#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 */
typedef scalar_t__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
float rand_float();
double stdlib_strided_dsnannsumors(int, float *, int, scalar_t__ *);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len];
  int64_t n;
  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_dsnannsumors(len, x, 1, &n);
    if (v != v || n < 0) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (v != v || n < 0) {
    printf("should not return NaN\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%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    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  0xe59(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    11e9 <benchmark+0xa9>
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x48(%rbp),%rax
movss  0xe34(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe2c(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    11ee <benchmark+0xae>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117c <benchmark+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1282 <benchmark+0x142>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
lea    -0x28(%rbp),%rcx
call   1060 <stdlib_strided_dsnannsumors@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    125e <benchmark+0x11e>
jp     125e <benchmark+0x11e>
cmpq   $0x0,-0x28(%rbp)
jge    126f <benchmark+0x12f>
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
jmp    1282 <benchmark+0x142>
jmp    1274 <benchmark+0x134>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1217 <benchmark+0xd7>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    12b4 <benchmark+0x174>
jp     12b4 <benchmark+0x174>
cmpq   $0x0,-0x28(%rbp)
jge    12c0 <benchmark+0x180>
lea    0xd55(%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>
test   %r13d,%r13d
movsd  %xmm0,-0x40(%rbp)
jle    120d <benchmark+0xcd>
lea    -0x38(%rbp),%r12
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <stdlib_strided_dsnannsumors@plt>
movsd  %xmm0,-0x30(%rbp)
ucomisd %xmm0,%xmm0
jp     1217 <benchmark+0xd7>
cmpq   $0x0,-0x38(%rbp)
js     1217 <benchmark+0xd7>
add    $0xffffffff,%r13d
jne    11e0 <benchmark+0xa0>
jmp    1223 <benchmark+0xe3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1223 <benchmark+0xe3>
lea    0xdf2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
movapd %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm0,%xmm0
jp     1240 <benchmark+0x100>
cmpq   $0x0,-0x38(%rbp)
jns    1256 <benchmark+0x116>
lea    0xdc9(%rip),%rdi
movsd  %xmm1,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movapd %xmm1,%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 i64
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca float, i64 %13
store i64 %13, i64* %7
store i32 0, i32* %11
br label %16
16: ; preds = %34, %2
%17 = load i32, i32* %11
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %16
%21 = call float (...) @rand_float()
%22 = fcmp olt float %21, 0x3FC99999A0000000
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %15, i64 %25
store float 0x7FF8000000000000, float* %26
br label %33
27: ; preds = %20
%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* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %15, i64 %31
store float %29, float* %32
br label %33
33: ; preds = %27, %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %16
37: ; preds = %16
store double 0.000000e+00, double* %9
%38 = call double (...) @tic()
store double %38, double* %10
store i32 0, i32* %11
br label %39
39: ; preds = %55, %37
%40 = load i32, i32* %11
%41 = load i32, i32* %3
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %58
43: ; preds = %39
%44 = load i32, i32* %4
%45 = call double @stdlib_strided_dsnannsumors(i32 %44, float* %15, i32 1, i64* %8)
store double %45, double* %9
%46 = load double, double* %9
%47 = load double, double* %9
%48 = fcmp une double %46, %47
br i1 %48, label %52, label %49
49: ; preds = %43
%50 = load i64, i64* %8
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49, %43
%53 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %58
54: ; preds = %49
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %39
58: ; preds = %52, %39
%59 = call double (...) @tic()
%60 = load double, double* %10
%61 = fsub double %59, %60
store double %61, double* %5
%62 = load double, double* %9
%63 = load double, double* %9
%64 = fcmp une double %62, %63
br i1 %64, label %68, label %65
65: ; preds = %58
%66 = load i64, i64* %8
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65, %58
%69 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = load double, double* %5
%72 = load i8*, i8** %6
ret double %71
}

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