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

/* Variables and functions */
double CLOCKS_PER_SEC;
int Fibonacci_loop(int);
int Fibonacci_rec(int);
int clock();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int main() {
  int n;
  clock_t start, end, i;
  printf("Enter the number of terms ");
  if (scanf("%d", &n) > 0) {
    printf("\nFibonacci series (1):\n");
    start = clock();
    for (i = 0; i <= n; i++)
      printf("%d\n", Fibonacci_rec(i));
    end = clock();
    printf("it takes %f\n", ((double)(end - start)) / CLOCKS_PER_SEC);
    printf("\nFibonacci series (2):\n");
    start = clock();
    for (i = 0; i <= n; i++)
      printf("%d\n", Fibonacci_loop(i));
    end = clock();
    printf("it takes %f\n", ((double)(end - start)) / CLOCKS_PER_SEC);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x0,%rax
jle    1283 <main+0x133>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11d8 <main+0x88>
mov    -0x14(%rbp),%edi
call   1030 <Fibonacci_rec@plt>
mov    %eax,%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x56>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    0x2df5(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe3c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1256 <main+0x106>
mov    -0x14(%rbp),%edi
call   1070 <Fibonacci_loop@plt>
mov    %eax,%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1224 <main+0xd4>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    0x2d77(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdbe(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
test   %rax,%rax
jle    1270 <main+0x110>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %eax,%r14d
cmpl   $0x0,0x4(%rsp)
js     11dc <main+0x7c>
mov    $0xffffffff,%ebp
lea    0xe66(%rip),%rbx
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebp,%edi
call   1040 <Fibonacci_rec@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    0x4(%rsp),%ebp
jl     11c0 <main+0x60>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r14d,%eax
cvtsi2sd %eax,%xmm0
mov    0x2df7(%rip),%r15
divsd  (%r15),%xmm0
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %eax,%r14d
cmpl   $0x0,0x4(%rsp)
js     124c <main+0xec>
mov    $0xffffffff,%ebp
lea    0xdf1(%rip),%rbx
nopl   (%rax)
add    $0x1,%ebp
mov    %ebp,%edi
call   1080 <Fibonacci_loop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    0x4(%rsp),%ebp
jl     1230 <main+0xd0>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  (%r15),%xmm0
lea    0xdb9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter the number of terms \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [24 x i8] c"\0AFibonacci series (1):\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [13 x i8] c"it takes %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.5 = [24 x i8] c"\0AFibonacci series (2):\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %54
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @clock()
store i32 %11, i32* %3
store i32 0, i32* %5
br label %12
12: ; preds = %20, %9
%13 = load i32, i32* %5
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* %5
%18 = call i32 @Fibonacci_rec(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %12
23: ; preds = %12
%24 = call i32 (...) @clock()
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sub nsw i32 %25, %26
%28 = sitofp i32 %27 to double
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 (...) @clock()
store i32 %33, i32* %3
store i32 0, i32* %5
br label %34
34: ; preds = %42, %23
%35 = load i32, i32* %5
%36 = load i32, i32* %2
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32, i32* %5
%40 = call i32 @Fibonacci_loop(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %34
45: ; preds = %34
%46 = call i32 (...) @clock()
store i32 %46, i32* %4
%47 = load i32, i32* %4
%48 = load i32, i32* %3
%49 = sub nsw i32 %47, %48
%50 = sitofp i32 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %52)
br label %54
54: ; preds = %45, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter the number of terms \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [13 x i8] c"it takes %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [23 x i8] c"\0AFibonacci series (1):\00"
@str.6 = [23 x i8] c"\0AFibonacci series (2):\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %43
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%8 = call i32 (...) @clock()
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %6, %11
%12 = phi i32 [ %15, %11 ], [ 0, %6 ]
%13 = call i32 @Fibonacci_rec(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = add nuw nsw i32 %12, 1
%16 = load i32, i32* %1
%17 = icmp slt i32 %12, %16
br i1 %17, label %11, label %18
18: ; preds = %11, %6
%19 = call i32 (...) @clock()
%20 = sub nsw i32 %19, %8
%21 = sitofp i32 %20 to double
%22 = load double, double* @CLOCKS_PER_SEC
%23 = fdiv double %21, %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%26 = call i32 (...) @clock()
%27 = load i32, i32* %1
%28 = icmp slt i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %18, %29
%30 = phi i32 [ %33, %29 ], [ 0, %18 ]
%31 = call i32 @Fibonacci_loop(i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i32 %30, 1
%34 = load i32, i32* %1
%35 = icmp slt i32 %30, %34
br i1 %35, label %29, label %36
36: ; preds = %29, %18
%37 = call i32 (...) @clock()
%38 = sub nsw i32 %37, %26
%39 = sitofp i32 %38 to double
%40 = load double, double* @CLOCKS_PER_SEC
%41 = fdiv double %39, %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %41)
br label %43
43: ; preds = %36, %0
ret i32 0
}