This question is more out of curiosity than necessity:
Is it possible to rewrite the code with if ( !boolvar ) { ... so that it is compiled with 1 cpu instruction?
I tried to think about it on a theoretical level, and this is what I came up with:
if ( !boolvar ) { ...
it will be necessary to nullify the variable first, and then the branch, depending on this → 2 commands (negate + branch)
if ( boolvar == false ) { ...
it will be necessary to load the false value into the register, and then branch off depending on this → 2 instructions (load + branch)
if ( boolvar != true ) { ...
you will need to load the value true in the register, and then branch ("branch-if-not-equal") depending on this → 2 instructions (load + "branch-if-not-equal")
Am I really mistaken in my assumptions? Is there something I'm missing out on?
I know that I can release intermediate versions of asm programs, but I would not know how to use it in such a way that I could enable compiler optimization on the one hand and at the same time not have an empty if optimized (or if optimized with its contents, which gives some non-general answer)
PS: Of course, I also searched google and SO for this, but with such short search terms I could not find anything useful
PPS: I would be fine with a semantically equivalent version, which is not the syntactic equivalent, for example. not using if .
Edit: feel free to correct me if my assumptions about the issued asm instructions are incorrect.
Edit2: I really learned asm about 15 years ago and retrained about 5 years ago for alpha architecture, but hopefully my question is still clear enough to find out what I'm asking. In addition, you can assume that any processor extension is common in the consumer processor up to AVX2 (the current haswell cpu processor at the time of writing), if that helps to find a good answer.