-fwrapv forces the compiler to handle signed overflow with 2's complement. UB essentially means the compiler is free to do anything, and with the option it chooses the wrapping behavior.
See https://stackoverflow.com/questions/47232954/what-does-fwrap...