#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 *);
double rand_double();
double stdlib_strided_dnannsumkbn(int, double *, int, scalar_t__ *);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  double x[len];
  int64_t n;
  double v;
  double t;
  int i;
  for (i = 0; i < len; i++) {
    if (rand_double() < 0.2) {
      x[i] = 0.0 / 0.0;
    } else {
      x[i] = (rand_double() * 20000.0) - 10000.0;
    }
  }
  v = 0.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_dnannsumkbn(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,8),%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    11fd <benchmark+0xbd>
mov    $0x0,%al
call   1050 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  0xe66(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11be <benchmark+0x7e>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  0xe64(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ea <benchmark+0xaa>
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x48(%rbp),%rax
movsd  0xe37(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe33(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ef <benchmark+0xaf>
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   1040 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1283 <benchmark+0x143>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
lea    -0x28(%rbp),%rcx
call   1060 <stdlib_strided_dnannsumkbn@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    125f <benchmark+0x11f>
jp     125f <benchmark+0x11f>
cmpq   $0x0,-0x28(%rbp)
jge    1270 <benchmark+0x130>
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
jmp    1283 <benchmark+0x143>
jmp    1275 <benchmark+0x135>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1218 <benchmark+0xd8>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    12b5 <benchmark+0x175>
jp     12b5 <benchmark+0x175>
cmpq   $0x0,-0x28(%rbp)
jge    12c1 <benchmark+0x181>
lea    0xd64(%rip),%rdi
call   1030 <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,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %esi,%esi
jle    11c5 <benchmark+0x85>
xor    %ebx,%ebx
jmp    118f <benchmark+0x4f>
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c5 <benchmark+0x85>
xor    %eax,%eax
call   1050 <rand_double@plt>
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm0,%xmm1
movsd  0xe56(%rip),%xmm0
ja     1180 <benchmark+0x40>
xor    %eax,%eax
call   1050 <rand_double@plt>
mulsd  0xe55(%rip),%xmm0
addsd  0xe55(%rip),%xmm0
jmp    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
test   %r13d,%r13d
movsd  %xmm0,-0x40(%rbp)
jle    120d <benchmark+0xcd>
lea    -0x38(%rbp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <stdlib_strided_dnannsumkbn@plt>
movsd  %xmm0,-0x30(%rbp)
ucomisd %xmm0,%xmm0
jp     1218 <benchmark+0xd8>
cmpq   $0x0,-0x38(%rbp)
js     1218 <benchmark+0xd8>
add    $0xffffffff,%r13d
jne    11e0 <benchmark+0xa0>
jmp    1224 <benchmark+0xe4>
xorpd  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1224 <benchmark+0xe4>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movapd %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm0,%xmm0
jp     1241 <benchmark+0x101>
cmpq   $0x0,-0x38(%rbp)
jns    1257 <benchmark+0x117>
lea    0xdd8(%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 double, 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 double (...) @rand_double()
%22 = fcmp olt double %21, 2.000000e-01
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %15, i64 %25
store double 0x7FF8000000000000, double* %26
br label %33
27: ; preds = %20
%28 = call double (...) @rand_double()
%29 = call double @llvm.fmuladd.f64(double %28, double 2.000000e+04, double -1.000000e+04)
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %15, i64 %31
store double %29, double* %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_dnannsumkbn(i32 %44, double* %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 double, 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 double (...) @rand_double()
%11 = fcmp olt double %10, 2.000000e-01
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call double (...) @rand_double()
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+04, double -1.000000e+04)
br label %15
15: ; preds = %8, %12
%16 = phi double [ %14, %12 ], [ 0x7FF8000000000000, %8 ]
%17 = getelementptr inbounds double, double* %5, i64 %9
store double %16, double* %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_dnannsumkbn(i32 %1, double* %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
}