#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();
double stdlib_strided_dsnansum(int, float *, int);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len];
  double 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.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_dsnansum(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
movsd  %xmm0,-0x28(%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    1278 <benchmark+0x138>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
call   1060 <stdlib_strided_dsnansum@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1254 <benchmark+0x114>
jp     1254 <benchmark+0x114>
jmp    1265 <benchmark+0x125>
lea    0xdb5(%rip),%rdi
call   1040 <printf@plt>
jmp    1278 <benchmark+0x138>
jmp    126a <benchmark+0x12a>
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)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    12a4 <benchmark+0x164>
jp     12a4 <benchmark+0x164>
jmp    12b0 <benchmark+0x170>
lea    0xd65(%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    11fe <benchmark+0xbe>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <stdlib_strided_dsnansum@plt>
ucomisd %xmm0,%xmm0
jp     1207 <benchmark+0xc7>
add    $0xffffffff,%r13d
jne    11e0 <benchmark+0xa0>
jmp    121d <benchmark+0xdd>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    1234 <benchmark+0xf4>
lea    0xe02(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1050 <tic@plt>
movsd  -0x30(%rbp),%xmm1
ucomisd %xmm1,%xmm1
jp     124c <benchmark+0x10c>
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    0xdbd(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    1234 <benchmark+0xf4>

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 double
%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 double 0.000000e+00, double* %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 double @stdlib_strided_dsnansum(i32 %43, float* %14, i32 1)
store double %44, double* %8
%45 = load double, double* %8
%46 = load double, double* %8
%47 = fcmp une double %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 double, double* %8
%59 = load double, double* %8
%60 = fcmp une double %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 double @stdlib_strided_dsnansum(i32 %1, float* %4, i32 1)
%28 = fcmp uno double %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 double %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
}