#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 logbx(double, double);
int /*<<< orphan*/ printf(char *);
double rand_double();
double round(double);
double tic();
double benchmark() {
  double elapsed;
  double x;
  double b;
  double y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (1000.0 * rand_double()) - 0.0;
    b = round((10.0 * rand_double()) + 1.0);
    y = logbx(x, b);
    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,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jge    120c <benchmark+0xbc>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe89(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe61(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5d(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <round@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1060 <logbx@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    11e8 <benchmark+0x98>
jp     11e8 <benchmark+0x98>
jmp    11f9 <benchmark+0xa9>
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
jmp    120c <benchmark+0xbc>
jmp    11fe <benchmark+0xae>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1238 <benchmark+0xe8>
jp     1238 <benchmark+0xe8>
jmp    1244 <benchmark+0xf4>
lea    0xdd9(%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
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <rand_double@plt>
mulsd  0xe75(%rip),%xmm0
addsd  0xe75(%rip),%xmm0
call   1070 <round@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
call   1060 <logbx@plt>
ucomisd %xmm0,%xmm0
jp     11c2 <benchmark+0x72>
add    $0xffffffff,%ebx
jne    1170 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11ea <benchmark+0x9a>
lea    0xe4f(%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 double
%6 = alloca i32
%7 = call double (...) @tic()
store double %7, double* %5
store i32 0, i32* %6
br label %8
8: ; preds = %26, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1000000
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = call double (...) @rand_double()
%13 = call double @llvm.fmuladd.f64(double 1.000000e+03, double %12, double -0.000000e+00)
store double %13, double* %2
%14 = call double (...) @rand_double()
%15 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %14, double 1.000000e+00)
%16 = call double @llvm.round.f64(double %15)
store double %16, double* %3
%17 = load double, double* %2
%18 = load double, double* %3
%19 = call double @logbx(double %17, double %18)
store double %19, double* %4
%20 = load double, double* %4
%21 = load double, double* %4
%22 = fcmp une double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %11
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %8
29: ; preds = %23, %8
%30 = call double (...) @tic()
%31 = load double, double* %5
%32 = fsub double %30, %31
store double %32, double* %1
%33 = load double, double* %4
%34 = load double, double* %4
%35 = fcmp une double %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load double, double* %1
ret double %39
}

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 %14, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call double (...) @rand_double()
%8 = fmul double %7, 1.000000e+03
%9 = tail call double (...) @rand_double()
%10 = tail call double @llvm.fmuladd.f64(double %9, double 1.000000e+01, double 1.000000e+00)
%11 = tail call double @llvm.round.f64(double %10)
%12 = tail call double @logbx(double %8, double %11)
%13 = fcmp uno double %12, 0.000000e+00
br i1 %13, label %16, label %2
14: ; preds = %2
%15 = tail call double (...) @tic()
br label %20
16: ; preds = %5
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
%18 = tail call double (...) @tic()
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %20
20: ; preds = %14, %16
%21 = phi double [ %18, %16 ], [ %15, %14 ]
%22 = fsub double %21, %1
ret double %22
}