#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 fib(int, int *);
int /*<<< orphan*/ free(int *);
int *generate_n(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int d;
  int *array;
  array = generate_n(1000000);
  scanf("%d", &d);
  while (d != -1) {
    printf("%d\n", fib(d, array));
    scanf("%d", &d);
  }
  free(array);
  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    $0xf4240,%edi
call   1050 <generate_n@plt>
mov    %rax,-0x20(%rbp)
lea    0xe85(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     11bd <main+0x6d>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fib@plt>
mov    %eax,%esi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
jmp    1184 <main+0x34>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xf4240,%edi
call   1050 <generate_n@plt>
mov    %rax,%rbx
lea    0xe94(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0xffffffff,%edi
je     11c6 <main+0x76>
lea    0xe7d(%rip),%r14
lea    0xe73(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rsi
call   1070 <fib@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0xffffffff,%edi
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @generate_n(i32 1000000)
store i32* %8, i32** %7
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %6
%15 = load i32*, i32** %7
%16 = call i32 @fib(i32 %14, i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %10
19: ; preds = %10
%20 = load i32*, i32** %7
%21 = call i32 @free(i32* %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32* @generate_n(i32 1000000)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %9
9: ; preds = %2, %9
%10 = phi i32 [ %14, %9 ], [ %7, %2 ]
%11 = call i32 @fib(i32 %10, i32* %5)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %9
16: ; preds = %9, %2
%17 = call i32 @free(i32* %5)
ret i32 0
}