Firstly, the main function (unless you use ancient Turbo C) should return int
.
Secondly, a decent compiler (clang for me) complains about the dubious expression:
clang++ -S -mllvm --x86-asm-syntax=intel ls.cpp
ls.cpp:5:11: warning: '&&' within '||' [-Wlogical-op-parentheses]
m = ++i && ++j || ++k;
~~~~^~~~~~ ~~
ls.cpp:5:11: note: place parentheses around the '&&' expression to silence this warning
m = ++i && ++j || ++k;
^
( )
1 warning generated.
Thirdly, let's see the assembly output:
mov dword ptr [rbp - 8], -3 # this is i
mov dword ptr [rbp - 12], 2 # this is j
mov dword ptr [rbp - 16], 0 # this is k
mov eax, dword ptr [rbp - 8] # this is i++
add eax, 1
mov dword ptr [rbp - 8], eax
cmp eax, 0 # is i++ == 0?
je .LBB0_2
# BB#1: # no, i++ is NOT 0
mov al, 1
mov ecx, dword ptr [rbp - 12] # this is j++
add ecx, 1
mov dword ptr [rbp - 12], ecx
cmp ecx, 0
mov byte ptr [rbp - 21], al # store al as a flag somewhere else
# it will be the final result of the operation
jne .LBB0_3 # if j++ was NOT zero, go down to LBB0_3
.LBB0_2: # Yes, i++ is 0. Did you remark that
# it didn't increment j in this case?
# but it needs to increment k since the first
# part of the OR evaluated to false.
mov eax, dword ptr [rbp - 16] # This is k++
add eax, 1
mov dword ptr [rbp - 16], eax
cmp eax, 0 # is c++ 0?
setne cl # if yes, set cl as a flag to 1
mov byte ptr [rbp - 21], cl # 1-byte Spill
# and here we get if j++ was not zero,
# so did you remark that k was not incremented?
.LBB0_3:
mov al, byte ptr [rbp - 21] # 1-byte Reload
lea rdi, qword ptr [.L.str]
and al, 1
movzx ecx, al
mov dword ptr [rbp - 20], ecx
# there goes the printf
mov esi, dword ptr [rbp - 8]
mov edx, dword ptr [rbp - 12]
mov ecx, dword ptr [rbp - 16]
mov r8d, dword ptr [rbp - 20]
mov al, 0
call printf