#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 */

/* Variables and functions */
int fibonacci_index(int);
scalar_t__ floor(double);
int /*<<< orphan*/ printf(char *);
double rand_double();
double tic();
double benchmark() {
  double elapsed;
  double t;
  int x;
  int y;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (int)floor((100000.0 * rand_double()) + 2.0);
    y = fibonacci_index(x);
    if (y < 0) {
      printf("should return a nonnegative integer\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y < 0) {
    printf("should return a nonnegative integer\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11d8 <benchmark+0x88>
mov    $0x0,%al
call   1060 <rand_double@plt>
movsd  0xe79(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe75(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <fibonacci_index@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c5 <benchmark+0x75>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    11d8 <benchmark+0x88>
jmp    11ca <benchmark+0x7a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ff <benchmark+0xaf>
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand_double@plt>
mulsd  0xe81(%rip),%xmm0
addsd  0xe81(%rip),%xmm0
call   1070 <floor@plt>
mov    %eax,%edi
call   1050 <fibonacci_index@plt>
test   %eax,%eax
js     11a5 <benchmark+0x55>
add    $0xffffffff,%ebx
jne    1170 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11cd <benchmark+0x7d>
lea    0xe64(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"should return a nonnegative integer\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %2
store i32 0, i32* %5
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = call double (...) @rand_double()
%12 = call double @llvm.fmuladd.f64(double 1.000000e+05, double %11, double 2.000000e+00)
%13 = call i64 @floor(double %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 @fibonacci_index(i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %25
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %19, %7
%26 = call double (...) @tic()
%27 = load double, double* %2
%28 = fsub double %26, %27
store double %28, double* %1
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = load double, double* %1
ret double %34
}

LLVM IR (-O2):
@str.1 = [36 x i8] c"should return a nonnegative integer\00"
define double @benchmark() {
%1 = tail call double (...) @tic()
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 1000000
br i1 %4, label %13, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call double (...) @rand_double()
%8 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e+05, double 2.000000e+00)
%9 = tail call i64 @floor(double %8)
%10 = trunc i64 %9 to i32
%11 = tail call i32 @fibonacci_index(i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %15, label %2
13: ; preds = %2
%14 = tail call double (...) @tic()
br label %19
15: ; preds = %5
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.1, i64 0, i64 0))
%17 = tail call double (...) @tic()
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.1, i64 0, i64 0))
br label %19
19: ; preds = %13, %15
%20 = phi double [ %17, %15 ], [ %14, %13 ]
%21 = fsub double %20, %1
ret double %21
}