The easiest way to answer this sort of question is to compile it with the -S
command line option, which outputs your C program as assembly code.
This is what your main()
function compiles to without any optimization (i.e., with the -O0
command line switch). I've removed some redundant marker statements and added a few comments:
main:
leal 4(%esp), %ecx # Create local storage on stack
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $20, %esp
movl $12345, -12(%ebp) # Initialize `a` to 12345
cmpl $12346, -12(%ebp) # Compare with 12346
jne .L4
subl $12, %esp # If equal, ...
pushl $.LC0
call puts # print "YES"
addl $16, %esp
.L4:
nop
nop
movl -4(%ebp), %ecx # Tidy up and exit
leave
leal -4(%ecx), %esp
ret
You can see that the numbers 12345 and 12346 are included in your code at the movl
and cmpl
instructions.
With optimization, the code becomes a lot simpler. The compiler can see that the if
statement never evaluates to true. It can also see that the variable a
is never used. This is what main()
looks like when compiled with hard optimization (-O3
):
main:
rep ret
(Note: I compiled this on 32-bit Ubuntu Xenial, but exactly the same optimizations would occur on a 64-bit machine.)