Reduce ifdefs and fix for 64bit

Patch from FreeBSD