#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 */
double binet(double);
double floor(double);
int /*<<< orphan*/ printf(char *);
double rand_double();
double tic();
double benchmark() {
  double elapsed;
  double t;
  double x;
  double y;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = floor(79.0 * rand_double());
    y = binet(x);
    if (y < 0) {
      printf("should return a nonnegative number\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y < 0) {
    printf("should return a nonnegative number\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    11d9 <benchmark+0x89>
mov    $0x0,%al
call   1050 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <binet@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11c6 <benchmark+0x76>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
jmp    11d9 <benchmark+0x89>
jmp    11cb <benchmark+0x7b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1204 <benchmark+0xb4>
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%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   1050 <rand_double@plt>
mulsd  0xe81(%rip),%xmm0
call   1070 <floor@plt>
call   1060 <binet@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11a1 <benchmark+0x51>
add    $0xffffffff,%ebx
jne    1170 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11c9 <benchmark+0x79>
lea    0xe68(%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 = [36 x i8] c"should return a nonnegative number\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %2
store i32 0, i32* %5
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = call double (...) @rand_double()
%12 = fmul double 7.900000e+01, %11
%13 = call double @llvm.floor.f64(double %12)
store double %13, double* %3
%14 = load double, double* %3
%15 = call double @binet(double %14)
store double %15, double* %4
%16 = load double, double* %4
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %24
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %18, %7
%25 = call double (...) @tic()
%26 = load double, double* %2
%27 = fsub double %25, %26
store double %27, double* %1
%28 = load double, double* %4
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load double, double* %1
ret double %33
}

LLVM IR (-O2):
@str.1 = [35 x i8] c"should return a nonnegative number\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 %12, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call double (...) @rand_double()
%8 = fmul double %7, 7.900000e+01
%9 = tail call double @llvm.floor.f64(double %8)
%10 = tail call double @binet(double %9)
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %14, label %2
12: ; preds = %2
%13 = tail call double (...) @tic()
br label %18
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.1, i64 0, i64 0))
%16 = tail call double (...) @tic()
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.1, i64 0, i64 0))
br label %18
18: ; preds = %12, %14
%19 = phi double [ %16, %14 ], [ %13, %12 ]
%20 = fsub double %19, %1
ret double %20
}