Make sure to use __builtin_popcountl to count bits in a uint64_t, or you may miss half of them (yes it happened to me).
long is 32-bits on GCC 32-bit. So it will still give the wrong result with `uint64_t`. You should be using __builtin_popcountll.
(don't get me wrong - you're not stupid, it happened to me too: https://github.com/orlp/libop/issues/1)