title: How to view disassembly for optimized speed builds in Visual Studio
body: <p>I have a C program in Visual Studio where I would like to compare the disassembly between the standard debug build and a build where speed is optimized.</p>
  
  <p>For standard debug things work perfectly, I set a breakpoint and then right-click "Goto Dissassembly" to view the equivalent assembly code.</p>
  
  <p>However, when I try to do that when the optimized for speed switch is enabled, I only see part of the assembly.</p>
  
  <p>My procedure for creating an optimized speed build is (staying in the debug build configuration):</p>
  
  <ol>
  <li><p>From the project properties -> C/C++->Optimization change Optimization from disabled /Od to Optimize for maximize speed /O2 and changing favor Size or Speed to 'Favor Fast Code /Ot)  </p></li>
  <li><p>Under Code Generation ->Basic Runtime checks change to 'Default' </p></li>
  </ol>
  
  <p>Note: I decided to modify my debug configuration and not do a full optimization (which includes size) because I wanted to preserve my code symbols.</p>
  
  <p>As part of my investigation, I created a trivial program for testing. Here is the source:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int x = 0;
      int y = 0;
      printf("The value of x is %d\n", x);
      while (1)
      {
          ++x;
          if (x &gt; 1000000)
             break;
      }
      y = x;
      printf("The value of y is %d\n", y);
      return 0;
  }
  </code></pre>
  
  <p>In full debug mode here is my disassembly: Note: I can easily see what is happening in the WHILE LOOP</p>
  
  <pre><code>int x = 0;
  00CF1779  mov         dword ptr [x],0  
  int y = 0;
  00CF1780  mov         dword ptr [y],0  
  printf("The value of x is %d\n", x);
  00CF1787  mov         eax,dword ptr [x]  
  00CF178A  push        eax  
  00CF178B  push        offset string "The value of x is %d\n" (0CF6B30h)  
  00CF1790  call        _printf (0CF1320h)  
  00CF1795  add         esp,8  
  while (1)
  00CF1798  mov         eax,1  
  00CF179D  test        eax,eax  
  00CF179F  je          main+47h (0CF17B7h)  
  {
      ++x;
  00CF17A1  mov         eax,dword ptr [x]  
  00CF17A4  add         eax,1  
  00CF17A7  mov         dword ptr [x],eax  
      if (x &gt; 1000000)
  00CF17AA  cmp         dword ptr [x],0F4240h  
  00CF17B1  jle         main+45h (0CF17B5h)  
          break;
  00CF17B3  jmp         main+47h (0CF17B7h)  
  }
  00CF17B5  jmp         main+28h (0CF1798h)  
  y = x;
  00CF17B7  mov         eax,dword ptr [x]  
  00CF17BA  mov         dword ptr [y],eax  
  printf("The value of y is %d\n", y);
  00CF17BD  mov         eax,dword ptr [y]  
  00CF17C0  push        eax  
  00CF17C1  push        offset string "The value of y is %d\n" (0CF6BE8h)  
  00CF17C6  call        _printf (0CF1320h)  
  00CF17CB  add         esp,8  
  
  return 0;
  </code></pre>
  
  <p>Here is the disassembly from the optimized speed build - note there is no code shown for the while loop routine</p>
  
  <pre><code>int x = 0;
  int y = 0;
  printf("The value of x is %d\n", x);
  00EE16F0  push        0  
  00EE16F2  push        offset string "The value of x is %d\n" (0EE6B30h)  
  00EE16F7  call        _printf (0EE1320h)  
  while (1)
  {
      ++x;
      if (x &gt; 1000000)
          break;
  }
  y = x;
  printf("The value of y is %d\n", y);
  00EE16FC  push        0F4241h  
  00EE1701  push        offset string "The value of y is %d\n" (0EE6BE8h)   
  00EE1706  call        _printf (0EE1320h)  
  00EE170B  add         esp,10h  
  
  return 0;
  00EE170E  xor         eax,eax  
  }
  00EE1710  ret
  </code></pre>
  
  <p>Both builds output the same values for x and y in the printf statements.
  Does anyone know how to solve my problem?</p>