title: LLVM 'ret' instructions
body: <p>I have followed the LLVM tutorial Kaleidoscope. Now I'm trying to extern this front-end compiler for language similar to Pascal. I have this code:</p>
  
  <pre><code>program main;
  
  function rett(): integer;
  begin
      rett := 1;
      exit;
      rett := 5;
  end;
  
  var a: integer;
  begin
      a := rett();    
      writeln(a);
  end.
  </code></pre>
  
  <p>An output of this program should be a single integer '1', because of the exit command (so the line <code>rett := 5;</code> should'n be execute). However the output is '5'. For this input I have generate this LLVM IR:</p>
  
  <pre><code>define i32 @rett() {
  entry:
    %rett = alloca i32
    store i32 0, i32* %rett
    store i32 1, i32* %rett
    %rett1 = load i32, i32* %rett
    ret i32 %rett1
    store i32 5, i32* %rett
    %rett2 = load i32, i32* %rett
    ret i32 %rett2
  }
  
  define i32 @main() {
  entry:
    %a = alloca i32
    %main = alloca i32
    store i32 0, i32* %main
    store i32 0, i32* %a
    %calltmp = call i32 @rett()
    store i32 %calltmp, i32* %a
    %a1 = load i32, i32* %a
    %calltmp2 = call i32 (i8*, ...) @printf([4 x i8]* @.str, i32 %a1)
    %main3 = load i32, i32* %main
    ret i32 %main3
  }
  </code></pre>
  
  <p>Why is not execute the first 'ret' command? Is there something what am I missing?</p>
  
  <hr>
  
  <p><strong>Update:</strong>
  In documentations is written:</p>
  
  <blockquote>
    <p>Each basic block may optionally start with a label (giving the basic block a symbol table entry), contains a list of instructions, and ends with a terminator instruction (such as a branch or function return).</p>
  </blockquote>
  
  <p>Is that mean that a "terminator" instruction can by only at the end of basic block? And if yes how should I implement return and break command for my language? </p>