#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 /*<<< orphan*/ printf(char *);
double rand_double();
int stdlib_base_is_finite(double);
double tic();
double benchmark() {
  double elapsed;
  double x;
  double t;
  bool b;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (rand_double() * 1.0e7) - 5.0e6;
    b = stdlib_base_is_finite(x);
    if (b != true && b != false) {
      printf("should return either true or false\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (b != true && b != false) {
    printf("should return either true or false\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,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xf4240,-0x20(%rbp)
jge    11d1 <benchmark+0x91>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe89(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <stdlib_base_is_finite@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     11be <benchmark+0x7e>
cmpl   $0x0,-0x1c(%rbp)
je     11be <benchmark+0x7e>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
jmp    11d1 <benchmark+0x91>
jmp    11c3 <benchmark+0x83>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1202 <benchmark+0xc2>
cmpl   $0x0,-0x1c(%rbp)
je     1202 <benchmark+0xc2>
lea    0xe13(%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   1050 <rand_double@plt>
mulsd  0xe91(%rip),%xmm0
addsd  0xe91(%rip),%xmm0
call   1060 <stdlib_base_is_finite@plt>
cmp    $0x2,%eax
jae    118f <benchmark+0x4f>
add    $0xffffffff,%ebx
jne    1160 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11b7 <benchmark+0x77>
lea    0xe7a(%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 either true or false\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %3
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 = call double @llvm.fmuladd.f64(double %11, double 1.000000e+07, double -5.000000e+06)
store double %12, double* %2
%13 = load double, double* %2
%14 = call i32 @stdlib_base_is_finite(double %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %26
22: ; preds = %17, %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* %3
%29 = fsub double %27, %28
store double %29, double* %1
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %32, %26
%38 = load double, double* %1
ret double %38
}

LLVM IR (-O2):
@str.1 = [35 x i8] c"should return either true or false\00"
define double @benchmark() {
%1 = tail call double (...) @tic()
br label %7
2: ; preds = %7
%3 = add nuw nsw i32 %8, 1
%4 = icmp eq i32 %3, 1000000
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call double (...) @tic()
br label %17
7: ; preds = %0, %2
%8 = phi i32 [ 0, %0 ], [ %3, %2 ]
%9 = tail call double (...) @rand_double()
%10 = tail call double @llvm.fmuladd.f64(double %9, double 1.000000e+07, double -5.000000e+06)
%11 = tail call i32 @stdlib_base_is_finite(double %10)
%12 = icmp ult i32 %11, 2
br i1 %12, label %2, label %13
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.1, i64 0, i64 0))
%15 = tail call double (...) @tic()
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.1, i64 0, i64 0))
br label %17
17: ; preds = %5, %13
%18 = phi double [ %6, %5 ], [ %15, %13 ]
%19 = fsub double %18, %1
ret double %19
}