#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 *);
float rand_float();
float sqrtf(float);
double tic();
double benchmark() {
  double elapsed;
  float x;
  float y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = rand_float() * 100000.0f;
    y = 1.0f / sqrtf(x);
    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   1050 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11dc <benchmark+0x9c>
mov    $0x0,%al
call   1030 <rand_float@plt>
movss  0xe8d(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1060 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  0xe6b(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jne    11b8 <benchmark+0x78>
jp     11b8 <benchmark+0x78>
jmp    11c9 <benchmark+0x89>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
jmp    11dc <benchmark+0x9c>
jmp    11ce <benchmark+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movss  -0x10(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jne    1207 <benchmark+0xc7>
jp     1207 <benchmark+0xc7>
jmp    1213 <benchmark+0xd3>
lea    0xdfa(%rip),%rdi
call   1040 <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   1050 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe91(%rip),%xmm0
ucomiss 0xe92(%rip),%xmm0
jb     1180 <benchmark+0x40>
sqrtss %xmm0,%xmm0
jmp    1185 <benchmark+0x45>
xchg   %ax,%ax
call   1060 <sqrtf@plt>
movss  0xe77(%rip),%xmm1
divss  %xmm0,%xmm1
ucomiss %xmm1,%xmm1
jp     11a4 <benchmark+0x64>
add    $0xffffffff,%ebx
jne    1160 <benchmark+0x20>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    11cc <benchmark+0x8c>
lea    0xe61(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <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 float
%3 = alloca float
%4 = alloca double
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = call float (...) @rand_float()
%12 = fmul float %11, 1.000000e+05
store float %12, float* %2
%13 = load float, float* %2
%14 = call float @sqrtf(float %13)
%15 = fdiv float 1.000000e+00, %14
store float %15, float* %3
%16 = load float, float* %3
%17 = load float, float* %3
%18 = fcmp une float %16, %17
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %25
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %19, %7
%26 = call double (...) @tic()
%27 = load double, double* %4
%28 = fsub double %26, %27
store double %28, double* %1
%29 = load float, float* %3
%30 = load float, float* %3
%31 = fcmp une float %29, %30
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %25
%35 = load double, double* %1
ret double %35
}

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