title: Decoding equivalent assembly code of C code
body: <p>Wanting to see the output of the compiler (in assembly) for some C code, I wrote a simple program in C and generated its assembly file using gcc.</p>
  
  <p>The code is this:  </p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  
  int main()  
  {  
      int i = 0;
  
      if ( i == 0 )
      {
          printf("testing\n");
      }
  
      return 0;  
  }  
  </code></pre>
  
  <p>The generated assembly for it is here (only the main function):</p>
  
  <pre><code>_main:  
  pushl   %ebpz  
  movl    %esp, %ebp  
  subl    $24, %esp  
  andl    $-16, %esp  
  movl    $0, %eax  
  addl    $15, %eax  
  addl    $15, %eax  
  shrl    $4, %eax  
  sall    $4, %eax  
  movl    %eax, -8(%ebp)  
  movl    -8(%ebp), %eax  
  call    __alloca  
  call    ___main  
  movl    $0, -4(%ebp)  
  cmpl    $0, -4(%ebp)  
  jne L2  
  movl    $LC0, (%esp)  
  call    _printf  
  L2:  
  movl    $0, %eax  
  leave  
  ret  
  </code></pre>
  
  <p>I am at an absolute loss to correlate the C code and assembly code. All that the code has to do is store 0 in a register and compare it with a constant 0 and take suitable action. But what is going on in the assembly?  </p>