On the Godbolt Compiler Explorer you can see what various compilers do with both versions, as well as KamilCuk's "option 3".
Guess what: with, for instance, the gcc compiler on x86-64 and optimization on, they all produce precisely the same code. So it makes no difference whatsoever.
(In particular, they all use a conditional set instruction that doesn't require a jump whether the condition is true or false.)
This is typical: modern compilers are smart enough to see that these are all equivalent, and to generate the best code no matter which way you wrote it. So it is a waste of time to think about such things. If one way seems to be clearer for someone reading the program, do it that way. If you don't think it makes any difference to a human, then just pick a way and move on.
If you have reason to believe that one case is more common than the other, you can use something like gcc's __builtin_expect
to hint this to the compiler. That way, if it is possible to optimize one branch to be faster than the other, the compiler will do so for the more common one. There can also be ways to use profiling to measure which branch is taken more often, and automatically inform the compiler of this. But the compiler normally won't try to draw such inferences just from your choice of which branch is the "then" and which is the "else".
However, in this case, using __builtin_expect
doesn't change anything, so both branches are already optimized as best the compiler knows how, and it doesn't know any way to make either one faster, even at the expense of making the other one slower.