title: Can anyone help me interpret this MSVC debug-mode disassembly from a simple Hello World?
body: <p>I got the following simple C++ code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(void)
  {
      ::printf("\nHello,debugger!\n");
  }
  </code></pre>
  
  <p>And from WinDbg, I got the following disassembly code:</p>
  
  <pre><code>SimpleDemo!main:
  01111380 55              push    ebp
  01111381 8bec            mov     ebp,esp
  01111383 81ecc0000000    sub     esp,0C0h
  01111389 53              push    ebx
  0111138a 56              push    esi
  0111138b 57              push    edi
  0111138c 8dbd40ffffff    lea     edi,[ebp-0C0h]
  01111392 b930000000      mov     ecx,30h
  01111397 b8cccccccc      mov     eax,0CCCCCCCCh
  0111139c f3ab            rep stos dword ptr es:[edi]
  0111139e 8bf4            mov     esi,esp
  011113a0 683c571101      push    offset SimpleDemo!`string' (0111573c)
  011113a5 ff15b0821101    call    dword ptr [SimpleDemo!_imp__printf (011182b0)]
  011113ab 83c404          add     esp,4
  011113ae 3bf4            cmp     esi,esp
  011113b0 e877fdffff      call    SimpleDemo!ILT+295(__RTC_CheckEsp) (0111112c)
  011113b5 33c0            xor     eax,eax
  011113b7 5f              pop     edi
  011113b8 5e              pop     esi
  011113b9 5b              pop     ebx
  011113ba 81c4c0000000    add     esp,0C0h
  011113c0 3bec            cmp     ebp,esp
  011113c2 e865fdffff      call    SimpleDemo!ILT+295(__RTC_CheckEsp) (0111112c)
  011113c7 8be5            mov     esp,ebp
  011113c9 5d              pop     ebp
  011113ca c3              ret
  </code></pre>
  
  <p>I have some difficulties to fully understand it. What is the <strong><em>SimpleDemo!ILT</em></strong> things doing here?</p>
  
  <p>What's the point of the instruction comparing ebp and esp at <strong><em>011113c0</em></strong>?</p>
  
  <p>Since I don't have any local variables in main() function, why there's still a <strong><em>sub esp,0C0h</em></strong> at the loacation of <strong><em>01111383</em></strong>?</p>
  
  <p>Many thanks.</p>
  
  <h2>Update 1</h2>
  
  <p>Though I still don't know what <strong><em>ILT</em></strong> means, but the __RTC_CheckESP is for runtime checks. These code can be elimiated by placing the following pragma before the <em>main()</em> function.</p>
  
  <pre><code>#pragma runtime_checks( "su", off )
  </code></pre>
  
  <p>Reference: </p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx</a></p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/6kasb93x.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/6kasb93x.aspx</a></p>
  
  <h2>Update 2</h2>
  
  <p>The <strong><em>sub esp,0C0h</em></strong> instruction allocate another 0C0h bytes extra space on the stack. Then EAX is filled with 0xCCCCCCCC, this is 4 bytes, since ECX=30h, 4*30h=0C0h, so the instruction <strong><em>rep stos dword ptr es:[edi]</em></strong> fill exactly the extra spaces with 0xCC. But what is this extra space on stack for? Is this some kind of safe belt? <strong><em>Also I notice that if I turn off the runtime check as Update 1 shows, there's still such extra space on stack, though much smaller. And this space is not filled with 0xCC.</em></strong></p>
  
  <p>The assembly code without runtime check is like below:</p>
  
  <pre><code>SimpleDemo!main:
  00231250 55              push    ebp
  00231251 8bec            mov     ebp,esp
  00231253 83ec40          sub     esp,40h &lt;-- Still extra space allocated from stack, but smaller
  00231256 53              push    ebx
  00231257 56              push    esi
  00231258 57              push    edi
  00231259 683c472300      push    offset SimpleDemo!`string' (0023473c)
  0023125e ff1538722300    call    dword ptr [SimpleDemo!_imp__printf (00237238)]
  00231264 83c404          add     esp,4
  00231267 33c0            xor     eax,eax
  00231269 5f              pop     edi
  0023126a 5e              pop     esi
  0023126b 5b              pop     ebx
  0023126c 8be5            mov     esp,ebp
  0023126e 5d              pop     ebp
  0023126f c3              ret
  </code></pre>