In addition to the undefined behaviors that other answers talk about, the difference in result comes from the GCC, which selects the second bit-shift.
If you parse the code using the -S flag, you may notice that only one shrl command is shrl :
subq $16, %rsp movl $32, -4(%rbp) movl -4(%rbp), %eax movl $-1, %edx movl %eax, %ecx shrl %cl, %edx movl %edx, %eax movl %eax, %esi movl $.LC0, %edi movl $0, %eax call printf movl $0, %esi movl $.LC0, %edi movl $0, %eax call printf movl $0, %eax
The compiler saw that he could calculate the second bitshift at compile time, since he would never change or replace the calculation based on its result, here 0 .
source share