#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 scalar_t__ clock_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
scalar_t__ clock();
float fibonacci(int, unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int term = 0, i = 0;
  clock_t start, stop;
  float diff;
  printf("This program prints the nth term of the Fibonacci sequence.\n");
  printf("Please enter the term to display.\n");
  scanf("%d", &term);
  unsigned long int memo[term + 1];
  for (i = 0; i < term + 1; i++)
    memo[i] = 0;
  start = clock();
  printf("Required term is %lu.\n", fibonacci(term, memo));
  stop = clock();
  diff = ((float)stop - (float)start) / CLOCKS_PER_SEC;
  printf("Time taken is %f seconds.\n", diff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x41(%rbp)
call   1040 <printf@plt>
mov    -0x41(%rbp),%al
lea    0xec5(%rip),%rdi
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11ed <main+0xad>
mov    -0x40(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11be <main+0x7e>
mov    $0x0,%al
call   1030 <clock@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <fibonacci@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe54(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
cvtsi2ssq -0x20(%rbp),%xmm0
cvtsi2ssq -0x18(%rbp),%xmm1
subss  %xmm1,%xmm0
mov    0x2db0(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,-0x1c(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
lea    0xe70(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <scanf@plt>
mov    %rsp,%r15
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x1c(%rbp),%eax
test   %eax,%eax
js     11d0 <main+0x70>
lea    0x8(,%rax,8),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    -0x1c(%rbp),%edi
mov    %rbx,%rsi
call   1070 <fibonacci@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe13(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
cvtsi2ss %r14,%xmm1
subss  %xmm1,%xmm0
mov    0x2dd2(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"This program prints the nth term of the Fibonacci sequence.\0A\00"
@.str.1 = [35 x i8] c"Please enter the term to display.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Required term is %lu.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.4 = [27 x i8] c"Time taken is %f seconds.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca float
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i64, i64 %14
store i64 %14, i64* %8
store i32 0, i32* %3
br label %17
17: ; preds = %26, %0
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i64, i64* %16, i64 %24
store i64 0, i64* %25
br label %26
26: ; preds = %22
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %17
29: ; preds = %17
%30 = call i64 (...) @clock()
store i64 %30, i64* %4
%31 = load i32, i32* %2
%32 = call float @fibonacci(i32 %31, i64* %16)
%33 = fpext float %32 to double
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %33)
%35 = call i64 (...) @clock()
store i64 %35, i64* %5
%36 = load i64, i64* %5
%37 = sitofp i64 %36 to float
%38 = load i64, i64* %4
%39 = sitofp i64 %38 to float
%40 = fsub float %37, %39
%41 = load float, float* @CLOCKS_PER_SEC
%42 = fdiv float %40, %41
store float %42, float* %6
%43 = load float, float* %6
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %44)
store i32 0, i32* %1
%46 = load i8*, i8** %7
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Required term is %lu.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.4 = [27 x i8] c"Time taken is %f seconds.\0A\00"
@str = [60 x i8] c"This program prints the nth term of the Fibonacci sequence.\00"
@str.5 = [34 x i8] c"Please enter the term to display.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i64, i64 %8
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %0
%14 = bitcast i64* %10 to i8*
%15 = zext i32 %11 to i64
%16 = shl nuw nsw i64 %15, 3
%17 = add nuw nsw i64 %16, 8
br label %18
18: ; preds = %13, %0
%19 = call i64 (...) @clock()
%20 = load i32, i32* %1
%21 = call float @fibonacci(i32 %20, i64* %10)
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %22)
%24 = call i64 (...) @clock()
%25 = sitofp i64 %24 to float
%26 = sitofp i64 %19 to float
%27 = fsub float %25, %26
%28 = load float, float* @CLOCKS_PER_SEC
%29 = fdiv float %27, %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %30)
ret i32 0
}