As others have mentioned, according to the C standard, the shift behavior is undefined.
Thus, the program prints 1. The low-level explanation of why it prints 1 is as follows:
When compiling without optimization, the compiler (GCC, clang) generates the SHL command:
... mov $32,%ecx shll %cl,0x1c(%esp) ...
Intel's documentation for the SHL instruction states:
SAL / SAR / SHL / SHR-Shift
The score is masked up to 5 bits (or 6 bits if used in 64-bit mode and REX.W is used). The sampling range is limited to 0 - 31 (or 63 if 64-bit mode and REX.W are used).
Masking the shift counter 32 (binary 00100000) to 5 bits gives 0 (binary 00000000). Therefore, the shll %cl,0x1c(%esp) does not perform any shifts and leaves the value of i unchanged.
user811773
source share