title: Visual C++ optimization options - how to improve the code output?
body: <p>Are there any options (other than /O2) to improve the Visual C++ code output? The MSDN documentation is quite bad in this regard.
  Note that I'm not asking about project-wide settings (link-time optimization, etc...). I'm only interested in this particular example.</p>
  
  <p>The fairly simple C++11 code looks like this: </p>
  
  <pre><code>#include &lt;vector&gt;
  int main() {
      std::vector&lt;int&gt; v = {1, 2, 3, 4};
      int sum = 0;
      for(int i = 0; i &lt; v.size(); i++) {
          sum += v[i];
      }
      return sum;
  }
  </code></pre>
  
  <p>Clang's output with libc++ is quite compact:</p>
  
  <pre><code>main: # @main
    mov eax, 10
    ret
  </code></pre>
  
  <p>Visual C++ output, on the other hand, is a multi-page mess.
  Am I missing something here or is VS really this bad?</p>
  
  <p>Compiler explorer link:
  <a href="https://godbolt.org/g/GJYHjE" rel="noreferrer">https://godbolt.org/g/GJYHjE</a></p>