#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 floor(double);
double lgamma(double);
int /*<<< orphan*/ printf(char *);
double rand_double();
double tic();
double benchmark() {
  double elapsed;
  double x;
  double y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = floor(171.0 * rand_double()) + 1.0;
    y = lgamma(x);
    if (y != y) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y != y) {
    printf("should not return NaN\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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    11f2 <benchmark+0xa2>
mov    $0x0,%al
call   1050 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  0xe7e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <floor@plt>
movsd  0xe65(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <lgamma@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    11ce <benchmark+0x7e>
jp     11ce <benchmark+0x7e>
jmp    11df <benchmark+0x8f>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    11f2 <benchmark+0xa2>
jmp    11e4 <benchmark+0x94>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    121e <benchmark+0xce>
jp     121e <benchmark+0xce>
jmp    122a <benchmark+0xda>
lea    0xdeb(%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>
addsd  0xe7c(%rip),%xmm0
call   1060 <lgamma@plt>
ucomisd %xmm0,%xmm0
jp     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 = [23 x i8] c"should not return NaN\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* %4
store i32 0, i32* %5
br label %7
7: ; preds = %23, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = call double (...) @rand_double()
%12 = fmul double 1.710000e+02, %11
%13 = call double @llvm.floor.f64(double %12)
%14 = fadd double %13, 1.000000e+00
store double %14, double* %2
%15 = load double, double* %2
%16 = call double @lgamma(double %15)
store double %16, double* %3
%17 = load double, double* %3
%18 = load double, double* %3
%19 = fcmp une double %17, %18
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %26
22: ; preds = %10
br label %23
23: ; preds = %22
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %7
26: ; preds = %20, %7
%27 = call double (...) @tic()
%28 = load double, double* %4
%29 = fsub double %27, %28
store double %29, double* %1
%30 = load double, double* %3
%31 = load double, double* %3
%32 = fcmp une double %30, %31
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = load double, double* %1
ret double %36
}

LLVM IR (-O2):
@str.1 = [22 x i8] c"should not return NaN\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 = fmul double %7, 1.710000e+02
%9 = tail call double @llvm.floor.f64(double %8)
%10 = fadd double %9, 1.000000e+00
%11 = tail call double @lgamma(double %10)
%12 = fcmp uno double %11, 0.000000e+00
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 ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
%17 = tail call double (...) @tic()
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 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
}