#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();
double tic();
double benchmark() {
  double elapsed;
  double y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    y = 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    11a3 <benchmark+0x73>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    117f <benchmark+0x4f>
jp     117f <benchmark+0x4f>
jmp    1190 <benchmark+0x60>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
jmp    11a3 <benchmark+0x73>
jmp    1195 <benchmark+0x65>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <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    11cf <benchmark+0x9f>
jp     11cf <benchmark+0x9f>
jmp    11db <benchmark+0xab>
lea    0xe2a(%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>
ucomisd %xmm0,%xmm0
jp     116b <benchmark+0x3b>
add    $0xffffffff,%ebx
jne    1150 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    1193 <benchmark+0x63>
lea    0xe8e(%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 = %17, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = call double (...) @rand_double()
store double %10, double* %2
%11 = load double, double* %2
%12 = load double, double* %2
%13 = fcmp une double %11, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %20
16: ; preds = %9
br label %17
17: ; preds = %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %6
20: ; preds = %14, %6
%21 = call double (...) @tic()
%22 = load double, double* %3
%23 = fsub double %21, %22
store double %23, double* %1
%24 = load double, double* %2
%25 = load double, double* %2
%26 = fcmp une double %24, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
%30 = load double, double* %1
ret double %30
}

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