#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 int64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int64_t fib_memoization2(int n, int64_t *cache) {
  if (n < 2)
    return 1;
  if (!cache[n - 1]) {
    cache[n - 1] = fib_memoization2(n - 1, cache);
  }
  if (!cache[n - 2]) {
    cache[n - 2] = fib_memoization2(n - 2, cache);
  }
  int64_t ret = cache[n - 1] + cache[n - 2];
  assert(ret > 0);
  return ret;
}


x86 assembly (clang, -O0):
<fib_memoization2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1145 <fib_memoization2+0x25>
movl   $0x1,-0x4(%rbp)
jmp    11ef <fib_memoization2+0xcf>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    117d <fib_memoization2+0x5d>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fib_memoization2@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11b5 <fib_memoization2+0x95>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fib_memoization2@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%edx
sub    $0x2,%edx
movslq %edx,%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib_memoization2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
cmp    $0x2,%edi
jl     117d <fib_memoization2+0x5d>
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x1(%rbx),%r15d
mov    (%rsi,%r15,4),%eax
test   %eax,%eax
jne    1151 <fib_memoization2+0x31>
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <fib_memoization2@plt>
mov    %eax,(%r14,%r15,4)
add    $0xfffffffe,%ebx
mov    (%r14,%rbx,4),%ebp
test   %ebp,%ebp
jne    1170 <fib_memoization2+0x50>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <fib_memoization2@plt>
mov    %eax,%ebp
mov    %eax,(%r14,%rbx,4)
mov    (%r14,%r15,4),%eax
xor    %edi,%edi
add    %eax,%ebp
setg   %dil
call   1030 <assert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fib_memoization2(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %65
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %11, i64 %14
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %10
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = load i32*, i32** %5
%22 = call i32 @fib_memoization2(i32 %20, i32* %21)
%23 = load i32*, i32** %5
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %23, i64 %26
store i32 %22, i32* %27
br label %28
28: ; preds = %18, %10
%29 = load i32*, i32** %5
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %46, label %36
36: ; preds = %28
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 2
%39 = load i32*, i32** %5
%40 = call i32 @fib_memoization2(i32 %38, i32* %39)
%41 = load i32*, i32** %5
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %41, i64 %44
store i32 %40, i32* %45
br label %46
46: ; preds = %36, %28
%47 = load i32*, i32** %5
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %47, i64 %50
%52 = load i32, i32* %51
%53 = load i32*, i32** %5
%54 = load i32, i32* %4
%55 = sub nsw i32 %54, 2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %53, i64 %56
%58 = load i32, i32* %57
%59 = add nsw i32 %52, %58
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = icmp sgt i32 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = load i32, i32* %6
store i32 %64, i32* %3
br label %65
65: ; preds = %46, %9
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
define i32 @fib_memoization2(i32 %0, i32* %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = add nsw i32 %0, -1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @fib_memoization2(i32 %5, i32* %1)
store i32 %11, i32* %7
br label %12
12: ; preds = %10, %4
%13 = phi i32 [ %11, %10 ], [ %8, %4 ]
%14 = add nsw i32 %0, -2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = tail call i32 @fib_memoization2(i32 %14, i32* %1)
store i32 %20, i32* %16
%21 = load i32, i32* %7
br label %22
22: ; preds = %19, %12
%23 = phi i32 [ %20, %19 ], [ %17, %12 ]
%24 = phi i32 [ %21, %19 ], [ %13, %12 ]
%25 = add nsw i32 %23, %24
%26 = icmp sgt i32 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
br label %29
29: ; preds = %2, %22
%30 = phi i32 [ %25, %22 ], [ 1, %2 ]
ret i32 %30
}