#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ getNFib(int *, int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int *fib_list = malloc(2000000);
  fib_list[0] = 0;
  fib_list[1] = 1;
  int size = 2;
  if (argc < 2) {
    printf("Error\n Usage: ./fib n");
    return -1;
  }
  int n = atoi(argv[1]);
  if (n > 46) {
    printf("Error\nInput a value between 0 and 46 inclusive\n");
    return -1;
  }
  if ((fib_list + n) != NULL && n < size) {
    printf("The term you were looking for is: %d\n", *(fib_list + n));
    return 0;
  } else {
    getNFib(fib_list, &size, n);
  }
  printf("The term you were looking for is: %d\n", *(fib_list + n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1e8480,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x4(%rax)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a4 <main+0x64>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2e,-0x20(%rbp)
jle    11d8 <main+0x98>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1252 <main+0x112>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
cmp    $0x0,%rax
je     1222 <main+0xe2>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1222 <main+0xe2>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1252 <main+0x112>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    -0x1c(%rbp),%rsi
call   1050 <getNFib@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1e8480,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movabs $0x100000000,%rax
mov    %rax,(%rbx)
movl   $0x2,0xc(%rsp)
cmp    $0x1,%ebp
jg     1199 <main+0x49>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11e6 <main+0x96>
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
cmp    $0x2f,%eax
jl     11ba <main+0x6a>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11e6 <main+0x96>
movslq %eax,%r14
cmp    $0x1,%eax
jle    11d2 <main+0x82>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1060 <getNFib@plt>
mov    (%rbx,%r14,4),%esi
lea    0xe39(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Error\0A Usage: ./fib n\00"
@.str.1 = [48 x i8] c"Error\0AInput a value between 0 and 46 inclusive\0A\00"
@.str.2 = [38 x i8] c"The term you were looking for is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @malloc(i32 2000000)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 0, i32* %11
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 1
store i32 1, i32* %13
store i32 2, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 46
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
27: ; preds = %18
%28 = load i32*, i32** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %44
33: ; preds = %27
%34 = load i32, i32* %8
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i32*, i32** %6
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %42)
store i32 0, i32* %3
br label %55
44: ; preds = %33, %27
%45 = load i32*, i32** %6
%46 = load i32, i32* %8
%47 = call i32 @getNFib(i32* %45, i32* %7, i32 %46)
br label %48
48: ; preds = %44
%49 = load i32*, i32** %6
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %53)
store i32 0, i32* %3
br label %55
55: ; preds = %48, %37, %25, %16
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [22 x i8] c"Error\0A Usage: ./fib n\00"
@.str.2 = [38 x i8] c"The term you were looking for is: %d\0A\00"
@str = [47 x i8] c"Error\0AInput a value between 0 and 46 inclusive\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = tail call i32* @malloc(i32 2000000)
store i32 0, i32* %4
%5 = getelementptr inbounds i32, i32* %4, i64 1
store i32 1, i32* %5
%6 = bitcast i32* %3 to i8*
store i32 2, i32* %3
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %28
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp sgt i32 %13, 46
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %28
17: ; preds = %10
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds i32, i32* %4, i64 %18
%20 = icmp slt i32 %13, 2
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %28
24: ; preds = %17
%25 = call i32 @getNFib(i32* %4, i32* %3, i32 %13)
%26 = load i32, i32* %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %15, %21, %24, %8
%29 = phi i32 [ -1, %8 ], [ -1, %15 ], [ 0, %21 ], [ 0, %24 ]
ret i32 %29
}