Using this site, I generated assembly code for a simple program.
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 5
mov eax, DWORD PTR [rbp-4]
mov edi, eax
mov eax, 0
call ifunc
mov eax, 0
leave
ret
Here value of a is loaded from memory into eax and then it is moved to edi to pass to function. But I wrote a similar assembly code and directly loaded value of a into edi. Both works fine. Does GCC follows this for some kind of optimization? What is the benefit of loading eax first?