#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
uint32_t fab(uint32_t i) {
  uint32_t f, f1, f2;
  static uint32_t cache[100];
  if (i < 2)
    f = i;
  else {
    if (cache[i - 2] > 0)
      f2 = cache[i - 2];
    else
      f2 = fab(i - 2);
    if (cache[i - 1] > 0)
      f1 = cache[i - 1];
    else
      f1 = fab(i - 1);
    f = fab(i - 1) + f2;
  }
  cache[i] = f;
  printf("fab[%d]=%d\n", i, f);
  return f;
}


x86 assembly (clang, -O0):
<fab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1140 <fab+0x20>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11d7 <fab+0xb7>
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
movslq %eax,%rcx
lea    0x2ef0(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
jle    1175 <fab+0x55>
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
movslq %eax,%rcx
lea    0x2ed6(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <fab+0x63>
mov    -0x4(%rbp),%edi
sub    $0x2,%edi
call   1040 <fab@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ead(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
jle    11b8 <fab+0x98>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e93(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <fab+0xa6>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1040 <fab@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1040 <fab@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edx
movslq -0x4(%rbp),%rcx
lea    0x2e5b(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fab>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%ebp
cmp    $0x2,%edi
jl     1168 <fab+0x48>
lea    -0x2(%rbx),%edi
lea    0x2f06(%rip),%r15
mov    (%r15,%rdi,4),%r14d
test   %r14d,%r14d
jg     114b <fab+0x2b>
call   1040 <fab@plt>
mov    %eax,%r14d
lea    -0x1(%rbx),%ebp
cmpl   $0x0,(%r15,%rbp,4)
jg     115c <fab+0x3c>
mov    %ebp,%edi
call   1040 <fab@plt>
mov    %ebp,%edi
call   1040 <fab@plt>
mov    %eax,%ebp
add    %r14d,%ebp
movslq %ebx,%rax
lea    0x2ece(%rip),%rcx
mov    %ebp,(%rcx,%rax,4)
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@fab.cache = internal global [100 x i32] zeroinitializer
@.str = [12 x i8] c"fab[%d]=%d\0A\00"
define i32 @fab(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %2
store i32 %9, i32* %3
br label %50
10: ; preds = %1
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %20
%22 = load i32, i32* %21
store i32 %22, i32* %5
br label %27
23: ; preds = %10
%24 = load i32, i32* %2
%25 = sub nsw i32 %24, 2
%26 = call i32 @fab(i32 %25)
store i32 %26, i32* %5
br label %27
27: ; preds = %23, %17
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %2
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %37
%39 = load i32, i32* %38
store i32 %39, i32* %4
br label %44
40: ; preds = %27
%41 = load i32, i32* %2
%42 = sub nsw i32 %41, 1
%43 = call i32 @fab(i32 %42)
store i32 %43, i32* %4
br label %44
44: ; preds = %40, %34
%45 = load i32, i32* %2
%46 = sub nsw i32 %45, 1
%47 = call i32 @fab(i32 %46)
%48 = load i32, i32* %5
%49 = add nsw i32 %47, %48
store i32 %49, i32* %3
br label %50
50: ; preds = %44, %8
%51 = load i32, i32* %3
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %53
store i32 %51, i32* %54
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %55, i32 %56)
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@fab.cache = internal unnamed_addr global [100 x i32] zeroinitializer
@.str = [12 x i8] c"fab[%d]=%d\0A\00"
define i32 @fab(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = add nsw i32 %0, -2
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = icmp sgt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @fab(i32 %4)
br label %11
11: ; preds = %3, %9
%12 = phi i32 [ %10, %9 ], [ %7, %3 ]
%13 = add nsw i32 %0, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 @fab(i32 %13)
br label %20
20: ; preds = %11, %18
%21 = tail call i32 @fab(i32 %13)
%22 = add nsw i32 %21, %12
br label %23
23: ; preds = %1, %20
%24 = phi i32 [ %22, %20 ], [ %0, %1 ]
%25 = sext i32 %0 to i64
%26 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %25
store i32 %24, i32* %26
%27 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %24)
ret i32 %24
}