#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;
  static uint32_t cache[100];
  if (i < 2)
    f = i;
  else if (cache[i] > 0)
    f = cache[i];
  else
    f = fab(i - 1) + fab(i - 2);
  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    1193 <fab+0x73>
movslq -0x4(%rbp),%rcx
lea    0x2ef5(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
jle    116b <fab+0x4b>
movslq -0x4(%rbp),%rcx
lea    0x2ee0(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x8(%rbp)
jmp    118e <fab+0x6e>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
call   1040 <fab@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sub    $0x2,%edi
call   1040 <fab@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1193 <fab+0x73>
mov    -0x8(%rbp),%edx
movslq -0x4(%rbp),%rcx
lea    0x2e9f(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fab>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%ebp
cmp    $0x2,%edi
jl     1155 <fab+0x35>
mov    %ebx,%eax
lea    0x2f0a(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
test   %ebp,%ebp
jg     1155 <fab+0x35>
lea    -0x1(%rbx),%edi
call   1040 <fab@plt>
mov    %eax,%r14d
lea    -0x2(%rbx),%edi
call   1040 <fab@plt>
mov    %eax,%ebp
add    %r14d,%ebp
movslq %ebx,%rax
lea    0x2ee1(%rip),%rcx
mov    %ebp,(%rcx,%rax,4)
lea    0xe97(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
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
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 2
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %2
store i32 %7, i32* %3
br label %28
8: ; preds = %1
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %3
br label %27
19: ; preds = %8
%20 = load i32, i32* %2
%21 = sub nsw i32 %20, 1
%22 = call i32 @fab(i32 %21)
%23 = load i32, i32* %2
%24 = sub nsw i32 %23, 2
%25 = call i32 @fab(i32 %24)
%26 = add nsw i32 %22, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %19, %14
br label %28
28: ; preds = %27, %6
%29 = load i32, i32* %3
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %31
store i32 %29, i32* %32
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* %3
ret i32 %36
}

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 %14, label %3
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %4
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = add nsw i32 %0, -1
%10 = tail call i32 @fab(i32 %9)
%11 = add nsw i32 %0, -2
%12 = tail call i32 @fab(i32 %11)
%13 = add nsw i32 %12, %10
br label %14
14: ; preds = %3, %1, %8
%15 = phi i32 [ %13, %8 ], [ %0, %1 ], [ %6, %3 ]
%16 = sext i32 %0 to i64
%17 = getelementptr inbounds [100 x i32], [100 x i32]* @fab.cache, i64 0, i64 %16
store i32 %15, i32* %17
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %15)
ret i32 %15
}