#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 *);
double rand_double();
double stdlib_strided_dnansumors(int, double *, int);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  double x[len];
  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_dnansumors(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,8),%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    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    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  0xe64(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ea <benchmark+0xaa>
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x40(%rbp),%rax
movsd  0xe37(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe33(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11ef <benchmark+0xaf>
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   1040 <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_dnansumors@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1255 <benchmark+0x115>
jp     1255 <benchmark+0x115>
jmp    1266 <benchmark+0x126>
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
jmp    1279 <benchmark+0x139>
jmp    126b <benchmark+0x12b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1218 <benchmark+0xd8>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    12a5 <benchmark+0x165>
jp     12a5 <benchmark+0x165>
jmp    12b1 <benchmark+0x171>
lea    0xd74(%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>
movsd  %xmm0,-0x38(%rbp)
test   %r13d,%r13d
jle    11fe <benchmark+0xbe>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <stdlib_strided_dnansumors@plt>
ucomisd %xmm0,%xmm0
jp     1207 <benchmark+0xc7>
add    $0xffffffff,%r13d
jne    11e0 <benchmark+0xa0>
jmp    121d <benchmark+0xdd>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    1234 <benchmark+0xf4>
lea    0xe12(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1040 <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    0xdcd(%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 double, 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 double (...) @rand_double()
%21 = fcmp olt double %20, 2.000000e-01
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %14, i64 %24
store double 0x7FF8000000000000, double* %25
br label %32
26: ; preds = %19
%27 = call double (...) @rand_double()
%28 = call double @llvm.fmuladd.f64(double %27, double 2.000000e+04, double -1.000000e+04)
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %14, i64 %30
store double %28, double* %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_dnansumors(i32 %43, double* %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 double, 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 double (...) @rand_double()
%9 = fcmp olt double %8, 2.000000e-01
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call double (...) @rand_double()
%12 = tail call double @llvm.fmuladd.f64(double %11, double 2.000000e+04, double -1.000000e+04)
br label %13
13: ; preds = %6, %10
%14 = phi double [ %12, %10 ], [ 0x7FF8000000000000, %6 ]
%15 = getelementptr inbounds double, double* %4, i64 %7
store double %14, double* %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_dnansumors(i32 %1, double* %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
}