Switch to custom byte swapping function.

GCC builtins like __bswap_32 are not portable between versions.
(cherry picked from commit da0c7b14a80baf63666c86254b47ea2b999db5e8)