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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdlib_base_float32_from_word(int /*<<< orphan*/, float *);
double tic();
double benchmark() {
  double elapsed;
  double t;
  float x;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    stdlib_base_float32_from_word((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    $0x20,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xf4240,-0x18(%rbp)
jge    11a2 <benchmark+0x72>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1050 <stdlib_base_float32_from_word@plt>
movss  -0x14(%rbp),%xmm0
ucomiss -0x14(%rbp),%xmm0
jne    117e <benchmark+0x4e>
jp     117e <benchmark+0x4e>
jmp    118f <benchmark+0x5f>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
jmp    11a2 <benchmark+0x72>
jmp    1194 <benchmark+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movss  -0x14(%rbp),%xmm0
ucomiss -0x14(%rbp),%xmm0
jne    11cd <benchmark+0x9d>
jp     11cd <benchmark+0x9d>
jmp    11d9 <benchmark+0xa9>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%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)
lea    0x4(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <stdlib_base_float32_from_word@plt>
movss  0x4(%rsp),%xmm0
ucomiss %xmm0,%xmm0
jp     1172 <benchmark+0x42>
add    $0x1,%ebx
cmp    $0xf4240,%ebx
jne    1150 <benchmark+0x20>
jmp    117e <benchmark+0x4e>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movss  0x4(%rsp),%xmm1
ucomiss %xmm1,%xmm1
jp     119e <benchmark+0x6e>
subsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
jmp    1190 <benchmark+0x60>

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 float
%4 = alloca i32
%5 = call double (...) @tic()
store double %5, double* %2
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 = load i32, i32* %4
%11 = call i32 @stdlib_base_float32_from_word(i32 %10, float* %3)
%12 = load float, float* %3
%13 = load float, float* %3
%14 = fcmp une float %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* %2
%24 = fsub double %22, %23
store double %24, double* %1
%25 = load float, float* %3
%26 = load float, float* %3
%27 = fcmp une float %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 = alloca float
%2 = bitcast float* %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_float32_from_word(i32 %8, float* %1)
%10 = load float, float* %1
%11 = fcmp uno float %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 float, float* %1
%17 = fcmp uno float %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
}