#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 */
float CLOCKS_PER_SEC;
scalar_t__ clock();
float fibonacci(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int term = 0;
  clock_t start, stop;
  float diff;
  printf("This program prints the nth term of the Fibonacci sequence.\n");
  printf("Please enter the term to display.\n");
  scanf("%d", &term);
  start = clock();
  printf("Required term is %lu.\n", fibonacci(term));
  stop = clock();
  diff = ((float)stop - (float)start) / CLOCKS_PER_SEC;
  printf("Time taken is %f seconds.\n", diff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <fibonacci@plt>
cvtss2sd %xmm0,%xmm0
lea    0xec3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
cvtsi2ssq -0x18(%rbp),%xmm0
cvtsi2ssq -0x10(%rbp),%xmm1
subss  %xmm1,%xmm0
mov    0x2e1f(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe98(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
lea    0xe84(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   1060 <fibonacci@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe5f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
cvtsi2ss %rbx,%xmm1
subss  %xmm1,%xmm0
mov    0x2e1e(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe41(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [61 x i8] c"This program prints the nth term of the Fibonacci sequence.\0A\00"
@.str.1 = [35 x i8] c"Please enter the term to display.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Required term is %lu.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.4 = [27 x i8] c"Time taken is %f seconds.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = call i64 (...) @clock()
store i64 %9, i64* %3
%10 = load i32, i32* %2
%11 = call float @fibonacci(i32 %10)
%12 = fpext float %11 to double
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %12)
%14 = call i64 (...) @clock()
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = sitofp i64 %15 to float
%17 = load i64, i64* %3
%18 = sitofp i64 %17 to float
%19 = fsub float %16, %18
%20 = load float, float* @CLOCKS_PER_SEC
%21 = fdiv float %19, %20
store float %21, float* %5
%22 = load float, float* %5
%23 = fpext float %22 to double
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %23)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Required term is %lu.\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.4 = [27 x i8] c"Time taken is %f seconds.\0A\00"
@str = [60 x i8] c"This program prints the nth term of the Fibonacci sequence.\00"
@str.5 = [34 x i8] c"Please enter the term to display.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = call i64 (...) @clock()
%7 = load i32, i32* %1
%8 = call float @fibonacci(i32 %7)
%9 = fpext float %8 to double
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %9)
%11 = call i64 (...) @clock()
%12 = sitofp i64 %11 to float
%13 = sitofp i64 %6 to float
%14 = fsub float %12, %13
%15 = load float, float* @CLOCKS_PER_SEC
%16 = fdiv float %14, %15
%17 = fpext float %16 to double
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %17)
ret i32 0
}