title: How do nested scopes affect stack depth?
body: <p>I tried compiling the following c-code using MSVC into assembly both with (CL TestFile.c /Fa /Ot) and without optimizations (CL TestFile.c /Fa) and the result is they produce the same stack-depth.</p>
  <p>Why does the compiler use 8 bytes for each of the 3 varibles x, y, and z when it knows it will use a maximum of 16 bytes? Instead of <code>y$1 = 4</code> and <code>z$2 = 8</code> could it not use <code>y$1 = 4</code> and <code>z$2 = 4</code> so <code>y</code> and <code>z</code> use the same memory on the stack without any problems?</p>
  <pre class="lang-c prettyprint-override"><code>int main() {
    int x = 123;
    if (x == 123) {
      int y = 321;
    }
    else {
      int z = 234;
    }
  }
  </code></pre>
  <pre><code>; Parts of the assembly code
  x$ = 0
  y$1 = 4
  z$2 = 8
  main PROC
  $LN5:
    sub rsp, 24
  ; And so on...
  </code></pre>