#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_strided_snanrange(int, float *, int);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len];
  float v;
  double t;
  int i;
  for (i = 0; i < len; i++) {
    if (rand_float() < 0.2) {
      x[i] = 0.0f / 0.0f;
    } else {
      x[i] = (rand_float() * 20000.0f) - 10000.0f;
    }
  }
  v = 0.0f;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_snanrange(len, x, 1);
    if (v != v) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (v != v) {
    printf("should not return NaN\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fe <benchmark+0xbe>
mov    $0x0,%al
call   1030 <rand_float@plt>
cvtss2sd %xmm0,%xmm1
movsd  0xe65(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <benchmark+0x7f>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  0xe5b(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    11eb <benchmark+0xab>
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x40(%rbp),%rax
movss  0xe36(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe2e(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    11f0 <benchmark+0xb0>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117c <benchmark+0x3c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1279 <benchmark+0x139>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
call   1060 <stdlib_strided_snanrange@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x24(%rbp),%xmm0
jne    1255 <benchmark+0x115>
jp     1255 <benchmark+0x115>
jmp    1266 <benchmark+0x126>
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
jmp    1279 <benchmark+0x139>
jmp    126b <benchmark+0x12b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1219 <benchmark+0xd9>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x24(%rbp),%xmm0
jne    12a4 <benchmark+0x164>
jp     12a4 <benchmark+0x164>
jmp    12b0 <benchmark+0x170>
lea    0xd69(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%r13d
mov    %esi,%r12d
mov    %rsp,%r15
lea    0xf(,%r12,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %esi,%esi
jle    11c9 <benchmark+0x89>
xor    %ebx,%ebx
jmp    118f <benchmark+0x4f>
nopw   0x0(%rax,%rax,1)
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c9 <benchmark+0x89>
xor    %eax,%eax
call   1040 <rand_float@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm0,%xmm1
movss  0xe52(%rip),%xmm0
ja     1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe45(%rip),%xmm0
addss  0xe41(%rip),%xmm0
jmp    1180 <benchmark+0x40>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %r13d,%r13d
jle    11fd <benchmark+0xbd>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <stdlib_strided_snanrange@plt>
ucomiss %xmm0,%xmm0
jp     1206 <benchmark+0xc6>
add    $0xffffffff,%r13d
jne    11e0 <benchmark+0xa0>
jmp    121c <benchmark+0xdc>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    1232 <benchmark+0xf2>
lea    0xe0b(%rip),%rdi
movss  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1050 <tic@plt>
movss  -0x30(%rbp),%xmm1
ucomiss %xmm1,%xmm1
jp     124a <benchmark+0x10a>
movsd  -0x38(%rbp),%xmm1
subsd  %xmm1,%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc7(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    1232 <benchmark+0xf2>

LLVM IR (-O0):
@.str = [23 x i8] c"should not return NaN\0A\00"
define double @benchmark(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i64
%8 = alloca float
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca float, i64 %12
store i64 %12, i64* %7
store i32 0, i32* %10
br label %15
15: ; preds = %34, %2
%16 = load i32, i32* %10
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = call float (...) @rand_float()
%21 = fpext float %20 to double
%22 = fcmp olt double %21, 2.000000e-01
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %14, i64 %25
store float 0x7FF8000000000000, float* %26
br label %33
27: ; preds = %19
%28 = call float (...) @rand_float()
%29 = call float @llvm.fmuladd.f32(float %28, float 2.000000e+04, float -1.000000e+04)
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %14, i64 %31
store float %29, float* %32
br label %33
33: ; preds = %27, %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %15
37: ; preds = %15
store float 0.000000e+00, float* %8
%38 = call double (...) @tic()
store double %38, double* %9
store i32 0, i32* %10
br label %39
39: ; preds = %52, %37
%40 = load i32, i32* %10
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i32, i32* %4
%45 = call float @stdlib_strided_snanrange(i32 %44, float* %14, i32 1)
store float %45, float* %8
%46 = load float, float* %8
%47 = load float, float* %8
%48 = fcmp une float %46, %47
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %55
51: ; preds = %43
br label %52
52: ; preds = %51
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %39
55: ; preds = %49, %39
%56 = call double (...) @tic()
%57 = load double, double* %9
%58 = fsub double %56, %57
store double %58, double* %5
%59 = load float, float* %8
%60 = load float, float* %8
%61 = fcmp une float %59, %60
br i1 %61, label %62, label %64
62: ; preds = %55
%63 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %64
64: ; preds = %62, %55
%65 = load double, double* %5
%66 = load i8*, i8** %6
ret double %65
}

LLVM IR (-O2):
@str.1 = [22 x i8] c"should not return NaN\00"
define double @benchmark(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca float, i64 %3
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %19
6: ; preds = %2, %14
%7 = phi i64 [ %17, %14 ], [ 0, %2 ]
%8 = tail call float (...) @rand_float()
%9 = fpext float %8 to double
%10 = fcmp olt double %9, 2.000000e-01
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call float (...) @rand_float()
%13 = tail call float @llvm.fmuladd.f32(float %12, float 2.000000e+04, float -1.000000e+04)
br label %14
14: ; preds = %6, %11
%15 = phi float [ %13, %11 ], [ 0x7FF8000000000000, %6 ]
%16 = getelementptr inbounds float, float* %4, i64 %7
store float %15, float* %16
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %3
br i1 %18, label %19, label %6
19: ; preds = %14, %2
%20 = tail call double (...) @tic()
%21 = icmp sgt i32 %0, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = call double (...) @tic()
br label %38
24: ; preds = %26
%25 = icmp eq i32 %30, %0
br i1 %25, label %33, label %26
26: ; preds = %19, %24
%27 = phi i32 [ %30, %24 ], [ 0, %19 ]
%28 = call float @stdlib_strided_snanrange(i32 %1, float* %4, i32 1)
%29 = fcmp uno float %28, 0.000000e+00
%30 = add nuw nsw i32 %27, 1
br i1 %29, label %31, label %24
31: ; preds = %26
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %33
33: ; preds = %24, %31
%34 = call double (...) @tic()
%35 = fcmp uno float %28, 0.000000e+00
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %38
38: ; preds = %22, %36, %33
%39 = phi double [ %23, %22 ], [ %34, %36 ], [ %34, %33 ]
%40 = fsub double %39, %20
ret double %40
}