#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();
int /*<<< orphan*/ stdlib_strided_dmeanstdev(int, double, double *, int,
                                             double *, int);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  double out[2];
  double x[len];
  double t;
  int i;
  for (i = 0; i < len; i++) {
    x[i] = (rand_double() * 20000.0) - 10000.0;
  }
  out[0] = 0.0;
  out[1] = 0.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    stdlib_strided_dmeanstdev(len, 1.0, x, 1, out, 1);
    if (out[i % 2] != out[i % 2]) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (out[i % 2] != out[i % 2]) {
    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,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c2 <benchmark+0x82>
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x48(%rbp),%rax
movsd  0xe6d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe69(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117c <benchmark+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%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    126f <benchmark+0x12f>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rcx
movsd  0xdfc(%rip),%xmm0
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <stdlib_strided_dmeanstdev@plt>
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movsd  -0x20(%rbp,%rax,8),%xmm0
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
ucomisd -0x20(%rbp,%rax,8),%xmm0
jne    124b <benchmark+0x10b>
jp     124b <benchmark+0x10b>
jmp    125c <benchmark+0x11c>
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    126f <benchmark+0x12f>
jmp    1261 <benchmark+0x121>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e5 <benchmark+0xa5>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movsd  -0x20(%rbp,%rax,8),%xmm0
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
ucomisd -0x20(%rbp,%rax,8),%xmm0
jne    12b9 <benchmark+0x179>
jp     12b9 <benchmark+0x179>
jmp    12c5 <benchmark+0x185>
lea    0xd58(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%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    $0x38,%rsp
mov    %esi,%r15d
mov    %edi,%r14d
mov    %rsp,-0x58(%rbp)
mov    %esi,%r13d
mov    %rsp,%r12
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %esi,%esi
jle    11a6 <benchmark+0x66>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand_double@plt>
mulsd  0xe71(%rip),%xmm0
addsd  0xe71(%rip),%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <benchmark+0x40>
xorpd  %xmm0,%xmm0
movapd %xmm0,-0x40(%rbp)
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,-0x50(%rbp)
test   %r14d,%r14d
jle    121d <benchmark+0xdd>
xor    %r13d,%r13d
lea    -0x40(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
movsd  0xe35(%rip),%xmm0
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
mov    $0x1,%r8d
call   1060 <stdlib_strided_dmeanstdev@plt>
mov    %r13d,%eax
and    $0x1,%eax
movsd  -0x40(%rbp,%rax,8),%xmm0
ucomisd %xmm0,%xmm0
jp     1211 <benchmark+0xd1>
add    $0x1,%r13d
cmp    %r13d,%r14d
jne    11d0 <benchmark+0x90>
mov    %r14d,%r13d
jmp    121d <benchmark+0xdd>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
and    $0x1,%r13d
movsd  -0x40(%rbp,%r13,8),%xmm1
ucomisd %xmm1,%xmm1
jp     124d <benchmark+0x10d>
subsd  -0x50(%rbp),%xmm0
mov    -0x58(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc4(%rip),%rdi
movsd  %xmm0,-0x48(%rbp)
call   1030 <puts@plt>
movsd  -0x48(%rbp),%xmm0
jmp    1235 <benchmark+0xf5>

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

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