On 2020-07-09 17:11 +0100, Jonny Grant wrote: > Due to the const' on the 'int i = 1;' gcc removes all the other branches > unfortunately. > (I'd rather not use any special build macro to remove the 'const' just to see > all the generated redundant assembler.) > > main: > push rbp > mov rbp, rsp > mov DWORD PTR [rbp-4], 1 > mov eax, 1 > pop rbp > ret Use -O0. It's nothing to do with that `const`. With something like -O2 it would be optimized away even if there is no `const`. `i` is a local variable and the compiler can determine that nobody can modify it. -- Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University