title: Compile with no optimization in clang
body: <p><strong>Short question:</strong> how to compile with <code>clang</code> with no code optimization? <code>-O0</code> is not working.</p>
  
  <p><strong>Long question:</strong>
  I'm learning code optimization and LLVM in particular. I'm writing small examples, compiling them and then running just one optimization at a time, to analyze what it changes. For example, to test Dead Code Elimination, I tried this:</p>
  
  <pre><code>int main() {
      int a = 20 + 30;
      int b = 25; /* Assignment to dead variable */
      int c;
      c = a &lt;&lt; 2;
      return c;
      b = 24; /* Unreachable code */
      return 0;
  }
  </code></pre>
  
  <p>However, when I compile it with</p>
  
  <pre><code>clang -S -O0 -emit-llvm foo.c
  </code></pre>
  
  <p>The last two lines of my C code do not show up in the IR code (below). Also, the <code>20 + 30</code> is already being calculated to 50. So there's some optimization going on here, even though I'm using <code>-O0</code>.</p>
  
  <pre><code>; ModuleID = 'hello.c'
  target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  target triple = "x86_64-unknown-linux-gnu"
  
  ; Function Attrs: nounwind uwtable
  define i32 @main() #0 {
  entry:
    %retval = alloca i32, align 4
    %a = alloca i32, align 4
    %b = alloca i32, align 4
    %c = alloca i32, align 4
    store i32 0, i32* %retval
    store i32 50, i32* %a, align 4
    store i32 25, i32* %b, align 4
    %0 = load i32* %a, align 4
    %shl = shl i32 %0, 2
    store i32 %shl, i32* %c, align 4
    %1 = load i32* %c, align 4
    ret i32 %1
  }
  
  attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
  
  !llvm.ident = !{!0}
  
  !0 = metadata !{metadata !"clang version 3.4 (trunk 192936)"}
  </code></pre>