#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 logit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rand_double();
double tic();
double benchmark() {
  double elapsed;
  double y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    y = logit(rand_double());
    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    $0x20,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11ba <benchmark+0x7a>
mov    $0x0,%al
call   1060 <rand_double@plt>
mov    %eax,%edi
call   1050 <logit@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1196 <benchmark+0x56>
jp     1196 <benchmark+0x56>
jmp    11a7 <benchmark+0x67>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
jmp    11ba <benchmark+0x7a>
jmp    11ac <benchmark+0x6c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11e6 <benchmark+0xa6>
jp     11e6 <benchmark+0xa6>
jmp    11f2 <benchmark+0xb2>
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   1060 <rand_double@plt>
mov    %eax,%edi
call   1050 <logit@plt>
ucomisd %xmm0,%xmm0
jp     1182 <benchmark+0x42>
add    $0xffffffff,%ebx
jne    1160 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11aa <benchmark+0x6a>
lea    0xe77(%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 i32
%5 = call double (...) @tic()
store double %5, double* %3
store i32 0, i32* %4
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = call i32 (...) @rand_double()
%11 = call double @logit(i32 %10)
store double %11, double* %2
%12 = load double, double* %2
%13 = load double, double* %2
%14 = fcmp une double %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %21
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %6
21: ; preds = %15, %6
%22 = call double (...) @tic()
%23 = load double, double* %3
%24 = fsub double %22, %23
store double %24, double* %1
%25 = load double, double* %2
%26 = load double, double* %2
%27 = fcmp une double %25, %26
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = load double, double* %1
ret double %31
}

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