I love this example. Even though you are aware how error-prone this is, you still get it wrong.
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)