It may look ugly, but I could think of of a less ugly way :(.
Actually I think it looks pretty reasonable :-) I'm mildly surprised that the unallocated ones don't try to go back and fill in the gaps, but that does make our job easier.
The one thing I don't love is the name of var_has_buffer_offset_register_reservation(). I'd honestly be tempted to inline the condition. Or maybe replace the word "buffer" with "globals".
One other test that I'm tempted to add just to be safe:
``` float a : register(c2); float b;
float4 main() : sv_target { return a + b; } ```