#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int EXIT_SUCCESS;
long fib(int);
long fib2(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float, ...);
int main(int argc, char *argv[]) {
  int nval, rept;
  struct timeval time1;
  struct timeval time2;
  float intv1, intv2;
  for (nval = 1; nval <= 20; nval++) {
    long int fval;
    gettimeofday(&time1, NULL);
    for (rept = 0; rept < 100000; rept++) {
      fval = fib(nval);
    }
    gettimeofday(&time2, NULL);
    intv1 =
        (time2.tv_sec - time1.tv_sec) + 1e-6 * (time2.tv_usec - time1.tv_usec);
    printf("fib (%2d) = %ld, time = %f\n", nval, fval, intv1);
    gettimeofday(&time1, NULL);
    for (rept = 0; rept < 100000; rept++) {
      fval = fib2(nval);
    }
    gettimeofday(&time2, NULL);
    intv2 =
        (time2.tv_sec - time1.tv_sec) + 1e-6 * (time2.tv_usec - time1.tv_usec);
    printf("fib2(%2d) = %ld, time = %f\n", nval, fval, intv2);
    printf("ratio = %f\n", intv1 / intv2);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jg     12b7 <main+0x177>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x186a0,-0x18(%rbp)
jge    11a2 <main+0x62>
mov    -0x14(%rbp),%edi
call   1060 <fib@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117b <main+0x3b>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe35(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
cvtsi2ssl -0x14(%rbp),%xmm0
mov    -0x38(%rbp),%rsi
movss  -0x2c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe13(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x186a0,-0x18(%rbp)
jge    1237 <main+0xf7>
mov    -0x14(%rbp),%edi
call   1030 <fib2@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1210 <main+0xd0>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xda0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
cvtsi2ssl -0x14(%rbp),%xmm0
mov    -0x38(%rbp),%rsi
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd9a(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  -0x2c(%rbp),%xmm0
divss  -0x30(%rbp),%xmm0
lea    0xd9e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x1,%r13d
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
xchg   %ax,%ax
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x186a0,%ebp
nop
mov    %r13d,%edi
call   1060 <fib@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x30>
mov    %rax,%r12
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0x14(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0xe50(%rip),%xmm1
addsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %r13d,%xmm0
movss  %xmm1,0x24(%rsp)
cvtss2sd %xmm1,%xmm1
lea    0xe37(%rip),%rdi
movss  %xmm0,0x20(%rsp)
mov    %r12,%rsi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x186a0,%ebx
mov    %r13d,%edi
call   1030 <fib2@plt>
add    $0xffffffff,%ebx
jne    11f0 <main+0xb0>
mov    %rax,%rbp
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0x14(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0xdd0(%rip),%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x1c(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
lea    0xdd5(%rip),%rdi
movss  0x20(%rsp),%xmm0
mov    %rbp,%rsi
mov    $0x2,%al
call   1040 <printf@plt>
movss  0x24(%rsp),%xmm0
divss  0x1c(%rsp),%xmm0
lea    0xdce(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%r13d
cmp    $0x15,%r13d
jne    1160 <main+0x20>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [28 x i8] c"fib (%2d) = %ld, time = %f\0A\00"
@.str.1 = [28 x i8] c"fib2(%2d) = %ld, time = %f\0A\00"
@.str.2 = [12 x i8] c"ratio = %f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca float
%11 = alloca float
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %13
13: ; preds = %85, %2
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 20
br i1 %15, label %16, label %88
16: ; preds = %13
%17 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
store i32 0, i32* %7
br label %18
18: ; preds = %24, %16
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 100000
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %6
%23 = call i64 @fib(i32 %22)
store i64 %23, i64* %12
br label %24
24: ; preds = %21
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %18
27: ; preds = %18
%28 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%32 = load i32, i32* %31
%33 = sub nsw i32 %30, %32
%34 = sitofp i32 %33 to double
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%38 = load i32, i32* %37
%39 = sub nsw i32 %36, %38
%40 = sitofp i32 %39 to double
%41 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %40, double %34)
%42 = fptrunc double %41 to float
store float %42, float* %10
%43 = load i32, i32* %6
%44 = sitofp i32 %43 to float
%45 = load i64, i64* %12
%46 = load float, float* %10
%47 = fpext float %46 to double
%48 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), float %44, i64 %45, double %47)
%49 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
store i32 0, i32* %7
br label %50
50: ; preds = %56, %27
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 100000
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32, i32* %6
%55 = call i64 @fib2(i32 %54)
store i64 %55, i64* %12
br label %56
56: ; preds = %53
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %50
59: ; preds = %50
%60 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%64 = load i32, i32* %63
%65 = sub nsw i32 %62, %64
%66 = sitofp i32 %65 to double
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%70 = load i32, i32* %69
%71 = sub nsw i32 %68, %70
%72 = sitofp i32 %71 to double
%73 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %72, double %66)
%74 = fptrunc double %73 to float
store float %74, float* %11
%75 = load i32, i32* %6
%76 = sitofp i32 %75 to float
%77 = load i64, i64* %12
%78 = load float, float* %11
%79 = fpext float %78 to double
%80 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), float %76, i64 %77, double %79)
%81 = load float, float* %10
%82 = load float, float* %11
%83 = fdiv float %81, %82
%84 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float %83)
br label %85
85: ; preds = %59
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %13
88: ; preds = %13
%89 = load i32, i32* @EXIT_SUCCESS
ret i32 %89
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [28 x i8] c"fib (%2d) = %ld, time = %f\0A\00"
@.str.1 = [28 x i8] c"fib2(%2d) = %ld, time = %f\0A\00"
@.str.2 = [12 x i8] c"ratio = %f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %11
11: ; preds = %2, %40
%12 = phi i32 [ 1, %2 ], [ %56, %40 ]
%13 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %14
14: ; preds = %11, %14
%15 = phi i32 [ 0, %11 ], [ %17, %14 ]
%16 = tail call i64 @fib(i32 %12)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, 100000
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = sub nsw i32 %21, %22
%24 = sitofp i32 %23 to double
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = sub nsw i32 %25, %26
%28 = sitofp i32 %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %28, double 0x3EB0C6F7A0B5ED8D, double %24)
%30 = fptrunc double %29 to float
%31 = sitofp i32 %12 to float
%32 = fpext float %30 to double
%33 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), float %31, i64 %16, double %32)
%34 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %35
35: ; preds = %19, %35
%36 = phi i32 [ 0, %19 ], [ %38, %35 ]
%37 = tail call i64 @fib2(i32 %12)
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, 100000
br i1 %39, label %40, label %35
40: ; preds = %35
%41 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = sub nsw i32 %42, %43
%45 = sitofp i32 %44 to double
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = sub nsw i32 %46, %47
%49 = sitofp i32 %48 to double
%50 = tail call double @llvm.fmuladd.f64(double %49, double 0x3EB0C6F7A0B5ED8D, double %45)
%51 = fptrunc double %50 to float
%52 = fpext float %51 to double
%53 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), float %31, i64 %37, double %52)
%54 = fdiv float %30, %51
%55 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), float %54)
%56 = add nuw nsw i32 %12, 1
%57 = icmp eq i32 %56, 21
br i1 %57, label %58, label %11
58: ; preds = %40
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}