int fibo_r() {
  static int a = 0, b = 1, count = 0;
  if (0 == count) {
    count++;
    return a;
  }
  if (1 == count) {
    count++;
    return b;
  }
  return (b > a) ? (a += b) : (b += a);
}


x86 assembly (clang, -O0):
<fibo_r>:
push   %rbp
mov    %rsp,%rbp
xor    %eax,%eax
cmp    0x2f20(%rip),%eax
jne    112f <fibo_r+0x2f>
mov    0x2f14(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f0b(%rip)
mov    0x2f01(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <fibo_r+0xa4>
mov    $0x1,%eax
cmp    0x2ef2(%rip),%eax
jne    115d <fibo_r+0x5d>
mov    0x2ee6(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2edd(%rip)
mov    0x2ecb(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <fibo_r+0xa4>
mov    0x2ebd(%rip),%eax
cmp    0x2ebf(%rip),%eax
jle    1189 <fibo_r+0x89>
mov    0x2eab(%rip),%eax
add    0x2ead(%rip),%eax
mov    %eax,0x2ea7(%rip)
mov    %eax,-0x8(%rbp)
jmp    119e <fibo_r+0x9e>
mov    0x2e99(%rip),%eax
add    0x2e8b(%rip),%eax
mov    %eax,0x2e85(%rip)
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibo_r>:
mov    0x2f26(%rip),%eax
cmp    $0x1,%eax
je     1120 <fibo_r+0x20>
test   %eax,%eax
jne    1131 <fibo_r+0x31>
movl   $0x1,0x2f13(%rip)
mov    0x2f09(%rip),%eax
ret
movl   $0x2,0x2f02(%rip)
mov    0x2ef0(%rip),%eax
ret
mov    0x2ee9(%rip),%ecx
mov    0x2eeb(%rip),%edx
lea    (%rdx,%rcx,1),%eax
cmp    %edx,%ecx
jle    114b <fibo_r+0x4b>
mov    %eax,0x2ede(%rip)
ret
mov    %eax,0x2ecf(%rip)
ret

LLVM IR (-O0):
@fibo_r.a = internal global i32 0
@fibo_r.b = internal global i32 1
@fibo_r.count = internal global i32 0
define i32 @fibo_r() {
%1 = alloca i32
%2 = load i32, i32* @fibo_r.count
%3 = icmp eq i32 0, %2
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @fibo_r.count
%6 = add nsw i32 %5, 1
store i32 %6, i32* @fibo_r.count
%7 = load i32, i32* @fibo_r.a
store i32 %7, i32* %1
br label %29
8: ; preds = %0
%9 = load i32, i32* @fibo_r.count
%10 = icmp eq i32 1, %9
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @fibo_r.count
%13 = add nsw i32 %12, 1
store i32 %13, i32* @fibo_r.count
%14 = load i32, i32* @fibo_r.b
store i32 %14, i32* %1
br label %29
15: ; preds = %8
%16 = load i32, i32* @fibo_r.b
%17 = load i32, i32* @fibo_r.a
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @fibo_r.b
%21 = load i32, i32* @fibo_r.a
%22 = add nsw i32 %21, %20
store i32 %22, i32* @fibo_r.a
br label %27
23: ; preds = %15
%24 = load i32, i32* @fibo_r.a
%25 = load i32, i32* @fibo_r.b
%26 = add nsw i32 %25, %24
store i32 %26, i32* @fibo_r.b
br label %27
27: ; preds = %23, %19
%28 = phi i32 [ %22, %19 ], [ %26, %23 ]
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %11, %4
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@fibo_r.a = internal unnamed_addr global i32 0
@fibo_r.b = internal unnamed_addr global i32 1
@fibo_r.count = internal unnamed_addr global i32 0
define i32 @fibo_r() {
%1 = load i32, i32* @fibo_r.count
switch i32 %1, label %6 [
i32 0, label %2
i32 1, label %4
]
2: ; preds = %0
store i32 1, i32* @fibo_r.count
%3 = load i32, i32* @fibo_r.a
br label %13
4: ; preds = %0
store i32 2, i32* @fibo_r.count
%5 = load i32, i32* @fibo_r.b
br label %13
6: ; preds = %0
%7 = load i32, i32* @fibo_r.b
%8 = load i32, i32* @fibo_r.a
%9 = icmp sgt i32 %7, %8
%10 = add nsw i32 %8, %7
br i1 %9, label %11, label %12
11: ; preds = %6
store i32 %10, i32* @fibo_r.a
br label %13
12: ; preds = %6
store i32 %10, i32* @fibo_r.b
br label %13
13: ; preds = %11, %12, %4, %2
%14 = phi i32 [ %3, %2 ], [ %5, %4 ], [ %10, %11 ], [ %10, %12 ]
ret i32 %14
}