The BUG

I love Microsoft as much as I love wasting hours of my time trying to figure out something like ohh you add -s then it just works. The best part about using Visual Studio is that the STL has minor bugs. Like insert a million random integers into a list and sort now you have 100 thousand. Or run clear and size on a vector several times then push_back then clear and size a bunch of times and repeat then incomprehensible run time error "vector iterators incompatible". So I replaced vector with a struct "vectorThatWorks" with pointer to data, count, and total. Hey it works, but the best error ever VS 2010 Express compiled my code incorrectly. It's a new twist to compile error. I know for a fact it is not my fault this time. Since the assembly dump is long and boring I cut it off after "tmp << 17" because they were exactly the same from then on.

Broken code:
// Output
tmp = rows.data[a - 1].column;
binBuffOut.put((unsigned int) ((tmp << 17) / 50529455839), 17);

Address   Hex dump          Command
00E416E1    8B55 EC         MOV EDX,DWORD PTR SS:[EBP-14]
00E416E4    03D2            ADD EDX,EDX
*** load 64 bit int into ECX:EAX??? ***
00E416E6    8B44D1 F0       MOV EAX,DWORD PTR DS:[EDX*8+ECX-10]
00E416EA    8B4C0A F4       MOV ECX,DWORD PTR DS:[ECX+EDX-0C]    <<< WTF? shouldn't this be [EDX*8+ECX-0C]
*** load 64 bit int into ECX:EAX??? ***
00E416EE    0FA4C1 11       SHLD ECX,EAX,11
...

Working code:

// Output
tmp = rows.data[a - 1].column;
if (tmp >= 50529455839) // never will happen but I don't know what else it could be
{
	tmp = 0; // simplified for assembly dump
//	fprintf(stderr, "rows.data >= 50529455839\n");
//	exit(1);
}
binBuffOut.put((unsigned int) ((tmp << 17) / 50529455839), 17);

Address   Hex dump          Command
00B916E1    8B4D EC         MOV ECX,DWORD PTR SS:[EBP-14]
00B916E4    03C9            ADD ECX,ECX
*** load 64 bit int into ECX:EAX ***
00B916E6    8B44CA F0       MOV EAX,DWORD PTR DS:[ECX*8+EDX-10]
00B916EA    8B4CCA F4       MOV ECX,DWORD PTR DS:[ECX*8+EDX-0C]  <<< Weird who knew that a 64 bit int be stored as a 64 bit int
*** load 64 bit int into ECX:EAX ***
00B916EE    83F9 0B         CMP ECX,0B
00B916F1    72 0D           JB SHORT 00B91700
00B916F3    77 07           JA SHORT 00B916FC
00B916F5    3D DF4ECAC3     CMP EAX,C3CA4EDF
00B916FA    72 04           JB SHORT 00B91700
00B916FC    33C0            XOR EAX,EAX
00B916FE    33C9            XOR ECX,ECX
00B91700    0FA4C1 11       SHLD ECX,EAX,11
...