#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;
  long tv_usec;
};

/* Variables and functions */
long fib(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, long);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
int main() {
  struct timeval tvBegin, tvEnd, tvDiff;
  int n = 39;
  long res;
  gettimeofday(&tvBegin, NULL);
  res = fib(n);
  gettimeofday(&tvEnd, NULL);
  timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
  printf("fib(%d) = %d\n", n, res);
  printf("elapsed time %ld.%06ld s\n", tvDiff.tv_sec, tvDiff.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x27,-0x3c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x3c(%rbp),%edi
call   1060 <fib@plt>
mov    %rax,-0x48(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <timeval_subtract@plt>
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x27,%edi
call   1060 <fib@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <timeval_subtract@plt>
lea    0xe77(%rip),%rdi
mov    $0x27,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    (%rsp),%esi
mov    0x8(%rsp),%rdx
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [14 x i8] c"fib(%d) = %d\0A\00"
@.str.1 = [26 x i8] c"elapsed time %ld.%06ld s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
store i32 39, i32* %5
%7 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%8 = load i32, i32* %5
%9 = call i64 @fib(i32 %8)
store i64 %9, i64* %6
%10 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%11 = call i32 @timeval_subtract(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %2)
%12 = load i32, i32* %5
%13 = load i64, i64* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %13)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%18 = load i64, i64* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %16, i64 %18)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [14 x i8] c"fib(%d) = %d\0A\00"
@.str.1 = [26 x i8] c"elapsed time %ld.%06ld s\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = tail call i64 @fib(i32 39)
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%10 = call i32 @timeval_subtract(%struct.timeval* %3, %struct.timeval* %2, %struct.timeval* %1)
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 39, i64 %8)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%15 = load i64, i64* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13, i64 %15)
ret i32 0
}