#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fibonacci(unsigned int);
int /*<<< orphan*/ fibonacci_optim(unsigned int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
int main(int argc, char *argv[]) {
  unsigned int i = 0;
  unsigned int nb_output = 0;
  struct timeval before_t;
  struct timeval after_t;
  struct timeval result_t;
  if (argc != 2) {
    printf("Usage: %s integer\n", argv[0]);
    return (1);
  }
  nb_output = atoi(argv[1]);
  printf("Fibonacci series\n");
  gettimeofday(&before_t, NULL);
  for (i = 0; i < nb_output; ++i) {
    printf("%lld ", fibonacci(i));
  }
  printf("\n");
  gettimeofday(&after_t, NULL);
  timersub(&after_t, &before_t, &result_t);
  printf("Time elapsed (recursivity)  : %ld.%06ld\n", (long int)result_t.tv_sec,
         (long int)result_t.tv_usec);
  gettimeofday(&before_t, NULL);
  fibonacci_optim(nb_output);
  gettimeofday(&after_t, NULL);
  timersub(&after_t, &before_t, &result_t);
  printf("Time elapsed (optimisation) : %ld.%06ld\n", (long int)result_t.tv_sec,
         (long int)result_t.tv_usec);
  return (0);
}


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   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <main+0x145>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1213 <main+0xb3>
mov    -0x14(%rbp),%edi
call   1050 <fibonacci@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <main+0x81>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1080 <timersub@plt>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
call   1060 <fibonacci_optim@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1080 <timersub@plt>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jne    127b <main+0xfb>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r13d
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %r13d,%r13d
je     11eb <main+0x6b>
lea    0xe4c(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
call   1070 <fibonacci@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    11d0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r14d,%r14d
lea    0x28(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x18(%rsp),%r12
lea    0x8(%rsp),%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <timersub@plt>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
lea    0xde9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r13d,%edi
call   1080 <fibonacci_optim@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <timersub@plt>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1292 <main+0x112>
mov    (%rsi),%rsi
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [19 x i8] c"Usage: %s integer\0A\00"
@.str.1 = [18 x i8] c"Fibonacci series\0A\00"
@.str.2 = [6 x i8] c"%lld \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [41 x i8] c"Time elapsed (recursivity) : %ld.%06ld\0A\00"
@.str.5 = [41 x i8] c"Time elapsed (optimisation) : %ld.%06ld\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 %struct.timeval
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
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %55
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
store i32 0, i32* %6
br label %25
25: ; preds = %33, %18
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32, i32* %6
%31 = call i32 @fibonacci(i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
br label %25
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%39 = call i32 @timersub(%struct.timeval* %9, %struct.timeval* %8, %struct.timeval* %10)
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%43 = load i64, i64* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %41, i64 %43)
%45 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%46 = load i32, i32* %7
%47 = call i32 @fibonacci_optim(i32 %46)
%48 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%49 = call i32 @timersub(%struct.timeval* %9, %struct.timeval* %8, %struct.timeval* %10)
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%51 = load i64, i64* %50
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%53 = load i64, i64* %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %51, i64 %53)
store i32 0, i32* %3
br label %55
55: ; preds = %36, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [19 x i8] c"Usage: %s integer\0A\00"
@.str.2 = [6 x i8] c"%lld \00"
@.str.4 = [41 x i8] c"Time elapsed (recursivity) : %ld.%06ld\0A\00"
@.str.5 = [41 x i8] c"Time elapsed (optimisation) : %ld.%06ld\0A\00"
@str = [17 x i8] c"Fibonacci series\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %42
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%18 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%19 = icmp eq i32 %16, 0
br i1 %19, label %26, label %20
20: ; preds = %13, %20
%21 = phi i32 [ %24, %20 ], [ 0, %13 ]
%22 = tail call i32 @fibonacci(i32 %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = add nuw i32 %21, 1
%25 = icmp eq i32 %24, %16
br i1 %25, label %26, label %20
26: ; preds = %20, %13
%27 = tail call i32 @putchar(i32 10)
%28 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%29 = call i32 @timersub(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %5)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%33 = load i64, i64* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %31, i64 %33)
%35 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%36 = call i32 @fibonacci_optim(i32 %16)
%37 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%38 = call i32 @timersub(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %5)
%39 = load i64, i64* %30
%40 = load i64, i64* %32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %39, i64 %40)
br label %42
42: ; preds = %26, %10
%43 = phi i32 [ 1, %10 ], [ 0, %26 ]
ret i32 %43
}