#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdlib_base_float64_from_words(int, int, double *);
double tic();
double benchmark() {
  double elapsed;
  uint32_t h;
  double x;
  double t;
  int i;
  h = 1074339512;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    stdlib_base_float64_from_words(h, (uint32_t)i, &x);
    if (x != x) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (x != x) {
    printf("should not return NaN\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x40091eb8,-0xc(%rbp)
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    11ad <benchmark+0x7d>
mov    -0xc(%rbp),%edi
mov    -0x24(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1050 <stdlib_base_float64_from_words@plt>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1189 <benchmark+0x59>
jp     1189 <benchmark+0x59>
jmp    119a <benchmark+0x6a>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <benchmark+0x7d>
jmp    119f <benchmark+0x6f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1152 <benchmark+0x22>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    11d9 <benchmark+0xa9>
jp     11d9 <benchmark+0xa9>
jmp    11e5 <benchmark+0xb5>
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rsp,%r14
nopl   0x0(%rax)
mov    $0x40091eb8,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1050 <stdlib_base_float64_from_words@plt>
movsd  (%rsp),%xmm0
ucomisd %xmm0,%xmm0
jp     1177 <benchmark+0x47>
add    $0x1,%ebx
cmp    $0xf4240,%ebx
jne    1150 <benchmark+0x20>
jmp    1183 <benchmark+0x53>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm1
jp     11a3 <benchmark+0x73>
subsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe56(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
jmp    1195 <benchmark+0x65>

LLVM IR (-O0):
@.str = [23 x i8] c"should not return NaN\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 1074339512, i32* %2
%6 = call double (...) @tic()
store double %6, double* %4
store i32 0, i32* %5
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %2
%12 = load i32, i32* %5
%13 = call i32 @stdlib_base_float64_from_words(i32 %11, i32 %12, double* %3)
%14 = load double, double* %3
%15 = load double, double* %3
%16 = fcmp une double %14, %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %23
19: ; preds = %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %17, %7
%24 = call double (...) @tic()
%25 = load double, double* %4
%26 = fsub double %24, %25
store double %26, double* %1
%27 = load double, double* %3
%28 = load double, double* %3
%29 = fcmp une double %27, %28
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %23
%33 = load double, double* %1
ret double %33
}

LLVM IR (-O2):
@str.1 = [22 x i8] c"should not return NaN\00"
define double @benchmark() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call double (...) @tic()
br label %7
4: ; preds = %7
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 1000000
br i1 %6, label %14, label %7
7: ; preds = %0, %4
%8 = phi i32 [ 0, %0 ], [ %5, %4 ]
%9 = call i32 @stdlib_base_float64_from_words(i32 1074339512, i32 %8, double* %1)
%10 = load double, double* %1
%11 = fcmp uno double %10, 0.000000e+00
br i1 %11, label %12, label %4
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %14
14: ; preds = %4, %12
%15 = call double (...) @tic()
%16 = load double, double* %1
%17 = fcmp uno double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = 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 = %18, %14
%21 = fsub double %15, %3
ret double %21
}