#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_snansumkbn2(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.2f) {
      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_snansumkbn2(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    11fc <benchmark+0xbc>
mov    $0x0,%al
call   1030 <rand_float@plt>
movaps %xmm0,%xmm1
movss  0xe66(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    11bd <benchmark+0x7d>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  0xe59(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    11e9 <benchmark+0xa9>
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x40(%rbp),%rax
movss  0xe34(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe2c(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    11ee <benchmark+0xae>
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    1277 <benchmark+0x137>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
call   1060 <stdlib_strided_snansumkbn2@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x24(%rbp),%xmm0
jne    1253 <benchmark+0x113>
jp     1253 <benchmark+0x113>
jmp    1264 <benchmark+0x124>
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
jmp    1277 <benchmark+0x137>
jmp    1269 <benchmark+0x129>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1217 <benchmark+0xd7>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movss  -0x24(%rbp),%xmm0
ucomiss -0x24(%rbp),%xmm0
jne    12a2 <benchmark+0x162>
jp     12a2 <benchmark+0x162>
jmp    12ae <benchmark+0x16e>
lea    0xd67(%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    11c4 <benchmark+0x84>
xor    %ebx,%ebx
jmp    118f <benchmark+0x4f>
nopw   0x0(%rax,%rax,1)
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c4 <benchmark+0x84>
xor    %eax,%eax
call   1040 <rand_float@plt>
movss  0xe66(%rip),%xmm1
ucomiss %xmm0,%xmm1
movss  0xe57(%rip),%xmm0
ja     1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe4e(%rip),%xmm0
addss  0xe4a(%rip),%xmm0
jmp    1180 <benchmark+0x40>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %r13d,%r13d
jle    11fd <benchmark+0xbd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <stdlib_strided_snansumkbn2@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    0xe03(%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    0xdbf(%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 = %33, %2
%16 = load i32, i32* %10
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = call float (...) @rand_float()
%21 = fcmp olt float %20, 0x3FC99999A0000000
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %14, i64 %24
store float 0x7FF8000000000000, float* %25
br label %32
26: ; preds = %19
%27 = call float (...) @rand_float()
%28 = call float @llvm.fmuladd.f32(float %27, float 2.000000e+04, float -1.000000e+04)
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds float, float* %14, i64 %30
store float %28, float* %31
br label %32
32: ; preds = %26, %22
br label %33
33: ; preds = %32
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %15
36: ; preds = %15
store float 0.000000e+00, float* %8
%37 = call double (...) @tic()
store double %37, double* %9
store i32 0, i32* %10
br label %38
38: ; preds = %51, %36
%39 = load i32, i32* %10
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = load i32, i32* %4
%44 = call float @stdlib_strided_snansumkbn2(i32 %43, float* %14, i32 1)
store float %44, float* %8
%45 = load float, float* %8
%46 = load float, float* %8
%47 = fcmp une float %45, %46
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %54
50: ; preds = %42
br label %51
51: ; preds = %50
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %38
54: ; preds = %48, %38
%55 = call double (...) @tic()
%56 = load double, double* %9
%57 = fsub double %55, %56
store double %57, double* %5
%58 = load float, float* %8
%59 = load float, float* %8
%60 = fcmp une float %58, %59
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %63
63: ; preds = %61, %54
%64 = load double, double* %5
%65 = load i8*, i8** %6
ret double %64
}

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 %18
6: ; preds = %2, %13
%7 = phi i64 [ %16, %13 ], [ 0, %2 ]
%8 = tail call float (...) @rand_float()
%9 = fcmp olt float %8, 0x3FC99999A0000000
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call float (...) @rand_float()
%12 = tail call float @llvm.fmuladd.f32(float %11, float 2.000000e+04, float -1.000000e+04)
br label %13
13: ; preds = %6, %10
%14 = phi float [ %12, %10 ], [ 0x7FF8000000000000, %6 ]
%15 = getelementptr inbounds float, float* %4, i64 %7
store float %14, float* %15
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %3
br i1 %17, label %18, label %6
18: ; preds = %13, %2
%19 = tail call double (...) @tic()
%20 = icmp sgt i32 %0, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = call double (...) @tic()
br label %37
23: ; preds = %25
%24 = icmp eq i32 %29, %0
br i1 %24, label %32, label %25
25: ; preds = %18, %23
%26 = phi i32 [ %29, %23 ], [ 0, %18 ]
%27 = call float @stdlib_strided_snansumkbn2(i32 %1, float* %4, i32 1)
%28 = fcmp uno float %27, 0.000000e+00
%29 = add nuw nsw i32 %26, 1
br i1 %28, label %30, label %23
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %32
32: ; preds = %23, %30
%33 = call double (...) @tic()
%34 = fcmp uno float %27, 0.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %37
37: ; preds = %21, %35, %32
%38 = phi double [ %22, %21 ], [ %33, %35 ], [ %33, %32 ]
%39 = fsub double %38, %19
ret double %39
}