title: How to generate LLVM SSA Format
body: <p>I write the following C code where variable X is being assigned twice:</p>
  
  <pre><code>int main()
  {
          int x;
          x = 10;
          x = 20;
          return 0;
  }
  </code></pre>
  
  <p>Compile and generate IR representation using the following command</p>
  
  <pre><code>clang -emit-llvm -c ssa.c
  </code></pre>
  
  <p>IR generated</p>
  
  <pre><code>; Function Attrs: nounwind uwtable
  define i32 @main() #0 {
  entry:
    %retval = alloca i32, align 4
    %x = alloca i32, align 4
    store i32 0, i32* %retval
    store i32 10, i32* %x, align 4
    store i32 20, i32* %x, align 4
    ret i32 0
  }
  </code></pre>
  
  <p>If my understanding of SSA format is correct, we should in this example see x1 and x2 as two LLVM IR variables generated and assigned two values 10 and 20 respectively. Is there some specific option we should compile with to get SSA IR representation or my understanding of IR representation is incorrect? Please advise.</p>
  
  <p><strong>EDIT:</strong> as suggested in one answer, using -mem2reg optimization pass gives me the following output</p>
  
  <pre><code>clang -c -emit-llvm ssa.c -o ssa.bc
  opt -mem2reg ssa.bc -o ssa.opt.bc
  llvm-dis ssa.opt.bc
  cat ssa.opt.ll
  </code></pre>
  
  <p>Resultant IR generated</p>
  
  <pre><code>; Function Attrs: nounwind uwtable
  define i32 @main() #0 {
  entry:
    ret i32 0
  }
  </code></pre>
  
  <p>it looks like the entire x assignment got optimized using mem2reg optimization. Any other way to generate and retain different x values?</p>