#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ fibo_ite(unsigned long);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double, ...);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i = 0;
  int ret = 0;
  struct timeval start, end;
  double s, e;
  unsigned long int n;
  if (argc != 0 && argv[1])
    n = strtoul(argv[1], NULL, 0);
  else
    n = 40;
  ret = gettimeofday(&start, NULL);
  if (ret != 0) {
    perror("start gettime error\n");
    return 1;
  }
  printf("fibo_ite %lu: %lf\n", n, fibo_ite(n));
  ret = gettimeofday(&end, NULL);
  if (ret != 0) {
    perror("end gettime error\n");
    return 1;
  }
  s = (double)start.tv_sec + (double)start.tv_usec / 1000000.0;
  e = (double)end.tv_sec + (double)end.tv_usec / 1000000.0;
  printf("%lf elapsed\n", e - s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11a9 <main+0x59>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11a9 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x50(%rbp)
jmp    11b1 <main+0x61>
movq   $0x28,-0x50(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e3 <main+0x93>
lea    0xe56(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c0 <main+0x170>
movaps 0xe16(%rip),%xmm1
movq   -0x50(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe15(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <fibo_ite@plt>
movsd  -0x58(%rbp),%xmm0
mov    %eax,%esi
lea    0xe17(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     125f <main+0x10f>
lea    0xe02(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c0 <main+0x170>
cvtsi2sdq -0x20(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xdad(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
movsd  0xd8c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
lea    0xdb1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    $0x28,%ebx
test   %edi,%edi
je     1173 <main+0x23>
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1173 <main+0x23>
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %eax,%eax
jne    122f <main+0xdf>
movq   %rbx,%xmm0
punpckldq 0xe6c(%rip),%xmm0
subpd  0xe74(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
mov    %rbx,%rdi
call   1050 <fibo_ite@plt>
lea    0xe80(%rip),%rdi
movapd 0x20(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %eax,%eax
jne    1238 <main+0xe8>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x18(%rsp),%xmm1
cvtsi2sdq 0x10(%rsp),%xmm2
movsd  0xe2b(%rip),%xmm3
divsd  %xmm3,%xmm2
cvtsi2sdq 0x8(%rsp),%xmm4
xorps  %xmm0,%xmm0
cvtsi2sdq (%rsp),%xmm0
addsd  %xmm1,%xmm2
divsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
subsd  %xmm2,%xmm0
lea    0xe43(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xdf2(%rip),%rdi
jmp    123f <main+0xef>
lea    0xe11(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    1227 <main+0xd7>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [21 x i8] c"start gettime error\0A\00"
@.str.1 = [19 x i8] c"fibo_ite %lu: %lf\0A\00"
@.str.2 = [19 x i8] c"end gettime error\0A\00"
@.str.3 = [13 x i8] c"%lf elapsed\0A\00"
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 double
%11 = alloca double
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strtoul(i8* %23, i32* null, i32 0)
store i64 %24, i64* %12
br label %26
25: ; preds = %15, %2
store i64 40, i64* %12
br label %26
26: ; preds = %25, %20
%27 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %64
32: ; preds = %26
%33 = load i64, i64* %12
%34 = uitofp i64 %33 to double
%35 = load i64, i64* %12
%36 = call i32 @fibo_ite(i64 %35)
%37 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %34, i32 %36)
%38 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %64
43: ; preds = %32
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%45 = load i64, i64* %44
%46 = sitofp i64 %45 to double
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%48 = load i64, i64* %47
%49 = sitofp i64 %48 to double
%50 = fdiv double %49, 1.000000e+06
%51 = fadd double %46, %50
store double %51, double* %10
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%53 = load i64, i64* %52
%54 = sitofp i64 %53 to double
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%56 = load i64, i64* %55
%57 = sitofp i64 %56 to double
%58 = fdiv double %57, 1.000000e+06
%59 = fadd double %54, %58
store double %59, double* %11
%60 = load double, double* %11
%61 = load double, double* %10
%62 = fsub double %60, %61
%63 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %62)
store i32 0, i32* %3
br label %64
64: ; preds = %43, %41, %30
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [21 x i8] c"start gettime error\0A\00"
@.str.1 = [19 x i8] c"fibo_ite %lu: %lf\0A\00"
@.str.2 = [19 x i8] c"end gettime error\0A\00"
@.str.3 = [13 x i8] c"%lf elapsed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp eq i32 %0, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i64 @strtoul(i8* nocapture %10, i32* null, i32 0)
br label %14
14: ; preds = %2, %8, %12
%15 = phi i64 [ %13, %12 ], [ 40, %8 ], [ 40, %2 ]
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %47
20: ; preds = %14
%21 = uitofp i64 %15 to double
%22 = tail call i32 @fibo_ite(i64 %15)
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %21, i32 %22)
%24 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %47
28: ; preds = %20
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%30 = load i64, i64* %29
%31 = sitofp i64 %30 to double
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%33 = load i64, i64* %32
%34 = sitofp i64 %33 to double
%35 = fdiv double %34, 1.000000e+06
%36 = fadd double %35, %31
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%38 = load i64, i64* %37
%39 = sitofp i64 %38 to double
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%41 = load i64, i64* %40
%42 = sitofp i64 %41 to double
%43 = fdiv double %42, 1.000000e+06
%44 = fadd double %43, %39
%45 = fsub double %44, %36
%46 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %45)
br label %47
47: ; preds = %28, %26, %18
%48 = phi i32 [ 1, %18 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %48
}