I'am trying to learn assembly. I disassembled a simple C program and debugged it with gdb. But one thing I've noticed is that values are moved very frequent.
0x0000555555555231 <+0>: push rbp
0x0000555555555232 <+1>: mov rbp,rsp
0x0000555555555235 <+4>: sub rsp,0x20
0x0000555555555239 <+8>: mov QWORD PTR [rbp-0x18],rdi
0x000055555555523d <+12>: mov QWORD PTR [rbp-0x20],rsi
0x0000555555555241 <+16>: mov rax,QWORD PTR [rbp-0x18]
0x0000555555555245 <+20>: mov rdi,rax
0x0000555555555248 <+23>: call 0x5555555551d9 <get_file_size>
rdi's value gets moved to the stack at rbp-0x18 (at <+8>), rsi's value to the stack at rbp-0x20 (+12). Then the value at rbp-0x18 gets moved to rax(+16) which will be moved to rdi again(+20). Why is this done? Why not just using rdi or at least moving rbp-0x18 to rdi directly instead via rax (at <+16>)? This could save the instruction at +20