#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 */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
void *atoi(char *);
scalar_t__ clock();
int compute_fibonacci(int volatile);
int /*<<< orphan*/ printf(char *, int volatile, ...);
int main(int argc, char *argv[]) {
  volatile int n = 20;
  if (argc > 1) {
    n = atoi(argv[1]);
  }
  int number_of_times = 100000;
  if (argc > 2) {
    number_of_times = atoi(argv[2]);
  }
  int fib_n = compute_fibonacci(n);
  clock_t begin = clock();
  compute_fibonacci(n);
  clock_t end = clock();
  double single_time = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("single execution time: %.2g s\n", single_time);
  double time_spent = 0;
  for (int i = 0; i < number_of_times; i++) {
    begin = clock();
    compute_fibonacci(n);
    end = clock();
    time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
  }
  double avg_time = time_spent / number_of_times;
  printf("fib(%d) = %d  [average execution time: %.2g s]\n", n, fib_n,
         avg_time);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x14,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1177 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x186a0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1198 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <compute_fibonacci@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <compute_fibonacci@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e13(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    125a <main+0x11a>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <compute_fibonacci@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2daa(%rip),%rax
divsd  (%rax),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1200 <main+0xc0>
movsd  -0x40(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
movsd  -0x50(%rbp),%xmm0
lea    0xda0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x14,0x4(%rsp)
mov    $0x186a0,%r14d
cmp    $0x2,%edi
jl     1182 <main+0x42>
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,0x4(%rsp)
cmp    $0x2,%ebx
je     1182 <main+0x42>
mov    0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
call   1030 <compute_fibonacci@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
call   1030 <compute_fibonacci@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e31(%rip),%r12
divsd  (%r12),%xmm0
cvttsd2si %xmm0,%esi
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xorpd  %xmm0,%xmm0
test   %r14d,%r14d
jle    1220 <main+0xe0>
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
call   1030 <compute_fibonacci@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0x8(%rsp),%xmm0
sub    %rbx,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%r12),%xmm1
addsd  %xmm1,%xmm0
add    $0xffffffff,%ebp
jne    11e0 <main+0xa0>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
mov    0x4(%rsp),%esi
lea    0xde8(%rip),%rdi
mov    %r15d,%edx
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [31 x i8] c"single execution time: %.2g s\0A\00"
@.str.1 = [48 x i8] c"fib(%d) = %d [average execution time: %.2g s]\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 i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store volatile i32 20, i32* %6
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @atoi(i8* %20)
%22 = ptrtoint i8* %21 to i32
store volatile i32 %22, i32* %6
br label %23
23: ; preds = %17, %2
store i32 100000, i32* %7
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i8* @atoi(i8* %29)
%31 = ptrtoint i8* %30 to i32
store i32 %31, i32* %7
br label %32
32: ; preds = %26, %23
%33 = load volatile i32, i32* %6
%34 = call i32 @compute_fibonacci(i32 %33)
store i32 %34, i32* %8
%35 = call i64 (...) @clock()
store i64 %35, i64* %9
%36 = load volatile i32, i32* %6
%37 = call i32 @compute_fibonacci(i32 %36)
%38 = call i64 (...) @clock()
store i64 %38, i64* %10
%39 = load i64, i64* %10
%40 = load i64, i64* %9
%41 = sub nsw i64 %39, %40
%42 = sitofp i64 %41 to double
%43 = load double, double* @CLOCKS_PER_SEC
%44 = fdiv double %42, %43
store double %44, double* %11
%45 = load double, double* %11
%46 = fptosi double %45 to i32
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %46)
store double 0.000000e+00, double* %12
store i32 0, i32* %13
br label %48
48: ; preds = %65, %32
%49 = load i32, i32* %13
%50 = load i32, i32* %7
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %68
52: ; preds = %48
%53 = call i64 (...) @clock()
store i64 %53, i64* %9
%54 = load volatile i32, i32* %6
%55 = call i32 @compute_fibonacci(i32 %54)
%56 = call i64 (...) @clock()
store i64 %56, i64* %10
%57 = load i64, i64* %10
%58 = load i64, i64* %9
%59 = sub nsw i64 %57, %58
%60 = sitofp i64 %59 to double
%61 = load double, double* @CLOCKS_PER_SEC
%62 = fdiv double %60, %61
%63 = load double, double* %12
%64 = fadd double %63, %62
store double %64, double* %12
br label %65
65: ; preds = %52
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 1
store i32 %67, i32* %13
br label %48
68: ; preds = %48
%69 = load double, double* %12
%70 = load i32, i32* %7
%71 = sitofp i32 %70 to double
%72 = fdiv double %69, %71
store double %72, double* %14
%73 = load volatile i32, i32* %6
%74 = load i32, i32* %8
%75 = load double, double* %14
%76 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %73, i32 %74, double %75)
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [31 x i8] c"single execution time: %.2g s\0A\00"
@.str.1 = [48 x i8] c"fib(%d) = %d [average execution time: %.2g s]\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store volatile i32 20, i32* %3
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8* @atoi(i8* %8)
%10 = ptrtoint i8* %9 to i64
%11 = trunc i64 %10 to i32
store volatile i32 %11, i32* %3
%12 = icmp eq i32 %0, 2
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i8* @atoi(i8* %15)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %2, %13, %6
%20 = phi i32 [ %18, %13 ], [ 100000, %6 ], [ 100000, %2 ]
%21 = load volatile i32, i32* %3
%22 = tail call i32 @compute_fibonacci(i32 %21)
%23 = tail call i64 (...) @clock()
%24 = load volatile i32, i32* %3
%25 = tail call i32 @compute_fibonacci(i32 %24)
%26 = tail call i64 (...) @clock()
%27 = sub nsw i64 %26, %23
%28 = sitofp i64 %27 to double
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
%31 = fptosi double %30 to i32
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = icmp sgt i32 %20, 0
br i1 %33, label %41, label %34
34: ; preds = %41, %19
%35 = phi double [ 0.000000e+00, %19 ], [ %52, %41 ]
%36 = sitofp i32 %20 to double
%37 = fdiv double %35, %36
%38 = load volatile i32, i32* %3
%39 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %22, double %37)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
41: ; preds = %19, %41
%42 = phi i32 [ %53, %41 ], [ 0, %19 ]
%43 = phi double [ %52, %41 ], [ 0.000000e+00, %19 ]
%44 = tail call i64 (...) @clock()
%45 = load volatile i32, i32* %3
%46 = tail call i32 @compute_fibonacci(i32 %45)
%47 = tail call i64 (...) @clock()
%48 = sub nsw i64 %47, %44
%49 = sitofp i64 %48 to double
%50 = load double, double* @CLOCKS_PER_SEC
%51 = fdiv double %49, %50
%52 = fadd double %43, %51
%53 = add nuw nsw i32 %42, 1
%54 = icmp eq i32 %53, %20
br i1 %54, label %34, label %41
}