#include <stdio.h>
int f(int x) {
return x * FACTOR;
}
int main() {
int x=1;
printf("%d\n", f(x));
return 0;
}
For the above program, if I compile it with clang -g -S -DFACTOR=2
. I got the following output.
It seems that the following two instructions are related to the multiplication x * 2
. But I don't understand how they can compute the multiplication. Could anybody help explain? Thanks.
leal (%rdi,%rdi), %eax
...
movl $2, %esi
...
Ltmp0:
##DEBUG_VALUE: f:x <- $edi
.loc 1 6 11 prologue_end ## main.c:6:11
leal (%rdi,%rdi), %eax
.loc 1 6 2 is_stmt 0 ## main.c:6:2
popq %rbp
retq
...
Ltmp2:
##DEBUG_VALUE: main:x <- 1
.loc 1 10 2 prologue_end ## main.c:10:2
leaq L_.str(%rip), %rdi
movl $2, %esi
xorl %eax, %eax
callq _printf
.loc 1 11 2 ## main.c:11:2
xorl %eax, %eax
popq %rbp
retq