I started to learn Assembly so I use the command gcc -S file.c
to get an Assembly version of my C code.
Everything is working fine but I noticed that when I put a simple code, for example:
void ft_return_strlen(char *str)
{
int a;
a = strlen(str);
return (a);
}
The gcc -S file.c
command gives me this:
_ft_return_strlen:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $16, %rsp
movq %rdi, -8(%rbp)
movq -8(%rbp), %rdi
callq _ft_strlen
movl %eax, -12(%rbp)
movl -12(%rbp), %eax
addq $16, %rsp
popq %rbp
retq
Even if this function is useless, why is gcc giving me these lines?
movq %rdi, -8(%rbp)
movq -8(%rbp), %rdi
Aren't they useless? If these lines were really useless, do they come from my code or from the gcc? Is there a way to improve this?