title: function arguments loading to registers on x64
body: <p>I have this little C code</p>
  
  <pre><code>void decode(int *xp,int *yp,int *zp)
  {
        int a,b,c;
        a=*yp;
        b=*zp;
        c=*xp;
        *yp=c;
        *zp=a;
        *xp=b;
  }
  </code></pre>
  
  <p>Then I compiled it to object file using gcc -c -O1 decode.c, and then dumped the object with objdump -M intel -d decode.o and the equivalent assembly code for this is </p>
  
  <pre><code>mov ecx,DWORD PTR [rsi]
  mov eax,DWORD PTR [rdx]
  mov r8d,DWORD PTR [rdi]
  mov DWORD PTR [rsi],r8d
  mov DWORD PTR [rdx],ecx
  mov DWORD PTR [rdi],eax
  ret
  </code></pre>
  
  <p>And I noticed that it doesnt use stack at all.But firstly values still need to be loaded to the registers. So my question is <strong>how do the arguments get loaded into the registers? does the compiler automatically loads the arguments to the registers behind the scenes? or something else happens?</strong> because there is no instructions that would load the arguments into the registers.</p>
  
  <hr>
  
  <p>And a little off topic. When you increase optimization for compiling the relationship between original source code and machine code decreases,imposing dificulties to relate the machine code back to the source code. By default if you dont specify the optimization flag to the GCC it doesnt optimize the code. So I tried to compile without any optimizations to get expected results from the source, but what I got was 4-5 times bigger machine code that wasnt related to the source and understandable. But when I applied Level 1 optimization the code appeared understandable and related to the source. But why?</p>