When plugged into the current version of clang at optimization level O3,
the initial code produces an assembly output that looks like the
following on an x86 target:
__ucmpdi2: mov rcx, rdi shr rcx, 32 mov rdx, rsi shr rdx, 32 xor eax, eax cmp ecx, edx jb .LBB0_4 mov eax, 2 ja .LBB0_4 mov eax, 0 cmp edi, esi jb .LBB0_4 cmp esi, edi mov eax, 1 adc eax, 0 .LBB0_4: ret
In constrast, the new version produces
__ucmpdi2: xor eax, eax cmp rdi, rsi seta al sbb eax, 0 add eax, 1 ret
We can safely use arithmetic on booleans here, since both the C++ and C
standard guarantee that a bool to int conversion will produce either
zero (for false) or one (for true).