#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 stdlib_base_pdifff(float, float);
double tic();
double benchmark() {
  double elapsed;
  double t;
  float x;
  float y;
  float z;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (1000.0f * rand_float()) - 500.0f;
    y = (1000.0f * rand_float()) - 500.0f;
    z = stdlib_base_pdifff(x, y);
    if (z != z) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (z != z) {
    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   1060 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xf4240,-0x20(%rbp)
jge    1202 <benchmark+0xc2>
mov    $0x0,%al
call   1030 <rand_float@plt>
movss  0xe89(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe81(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <rand_float@plt>
movss  0xe65(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe5d(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
call   1050 <stdlib_base_pdifff@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jne    11de <benchmark+0x9e>
jp     11de <benchmark+0x9e>
jmp    11ef <benchmark+0xaf>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
jmp    1202 <benchmark+0xc2>
jmp    11f4 <benchmark+0xb4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1060 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jne    122d <benchmark+0xed>
jp     122d <benchmark+0xed>
jmp    1239 <benchmark+0xf9>
lea    0xdd4(%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   1060 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_float@plt>
movaps %xmm0,%xmm1
movss  0xe8e(%rip),%xmm0
mulss  %xmm0,%xmm1
movss  0xe86(%rip),%xmm0
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <rand_float@plt>
movaps %xmm0,%xmm1
mulss  0xe67(%rip),%xmm1
addss  0xe63(%rip),%xmm1
movss  (%rsp),%xmm0
call   1050 <stdlib_base_pdifff@plt>
ucomiss %xmm0,%xmm0
jp     11be <benchmark+0x7e>
add    $0xffffffff,%ebx
jne    1160 <benchmark+0x20>
xor    %eax,%eax
call   1060 <tic@plt>
jmp    11e6 <benchmark+0xa6>
lea    0xe43(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <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 float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = call double (...) @tic()
store double %7, double* %2
store i32 0, i32* %6
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1000000
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = call float (...) @rand_float()
%13 = call float @llvm.fmuladd.f32(float 1.000000e+03, float %12, float -5.000000e+02)
store float %13, float* %3
%14 = call float (...) @rand_float()
%15 = call float @llvm.fmuladd.f32(float 1.000000e+03, float %14, float -5.000000e+02)
store float %15, float* %4
%16 = load float, float* %3
%17 = load float, float* %4
%18 = call float @stdlib_base_pdifff(float %16, float %17)
store float %18, float* %5
%19 = load float, float* %5
%20 = load float, float* %5
%21 = fcmp une float %19, %20
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %28
24: ; preds = %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %8
28: ; preds = %22, %8
%29 = call double (...) @tic()
%30 = load double, double* %2
%31 = fsub double %29, %30
store double %31, double* %1
%32 = load float, float* %5
%33 = load float, float* %5
%34 = fcmp une float %32, %33
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %28
%38 = load double, double* %1
ret double %38
}

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