Following on from the last post we’re going to take a look at how optimisation flags, specifically -O3, alter the compiled output of the following snippet.
int main(int argc, char *argv[])
{
char input = getchar();
if (input == 'c')
{
puts("Always");
}
else
{
puts("Never");
}
return 0;
}
What can we discern from the above? When compiled with:
g++ Optional.cpp -O3 -o OptimisedOptional.exe
It must be non-deterministic. Since it’s control flow can be altered by external input it’s impossible to optimise out either case of the if statement. Meaning that even when optimised, both paths must be available.
Inspection reveals this:

It’s quite clear to see the two branches from the middle block which does the comparison.
Lets take a closer look at this OpCode:
cmp al, 63h
cmp will compare the two operands al (our general purpose register of 8 bits) and 63h. What’s the importance of 63h? Well 63 in hex is equal to a ‘c’ char!
Ok cool.. but can we change the functionality of the program without recompiling?… We sure can! Go download a hex editor and we’ll pick this up in the next post.