; Handwritten teaching IR. The compiler selects the local target when building.

; textbook:begin straight
define i32 @twice_next(i32 %x) {
entry:
  %next = add i32 %x, 1
  %result = mul i32 %next, 2
  ret i32 %result
}
; textbook:end straight

; textbook:begin branch
define i32 @signed_step(i32 %x) {
entry:
  %positive_test = icmp sgt i32 %x, 0
  br i1 %positive_test, label %positive, label %other
positive:
  %plus = add i32 %x, 1
  br label %join
other:
  %minus = add i32 %x, -1
  br label %join
join:
  %result = phi i32 [ %plus, %positive ], [ %minus, %other ]
  ret i32 %result
}
; textbook:end branch

; textbook:begin memory
define i32 @read_twice(i32 %x) {
entry:
  %slot = alloca i32, align 4
  store i32 %x, ptr %slot, align 4
  %first = load i32, ptr %slot, align 4
  store i32 9, ptr %slot, align 4
  %second = load i32, ptr %slot, align 4
  %result = add i32 %first, %second
  ret i32 %result
}
; textbook:end memory
