Enable 64 bit compilation

Buffers indices and sizes are frequently declared as 32 bit integers.
This is an initial attempt to clean up at least the most obvious
problems where 32 and 64 bit wide integers conflict (such as casting
pointers to integers with different widths).