#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_dvarmpn(int, double, 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++) {
    x[i] = (rand_double() * 20000.0) - 10000.0;
  }
  v = 0.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_dvarmpn(len, 0.0, 1, 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    11c2 <benchmark+0x82>
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x40(%rbp),%rax
movsd  0xe65(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe61(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
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    1243 <benchmark+0x103>
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%edi
xorps  %xmm0,%xmm0
mov    $0x1,%ecx
mov    %ecx,%esi
call   1060 <stdlib_strided_dvarmpn@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    121f <benchmark+0xdf>
jp     121f <benchmark+0xdf>
jmp    1230 <benchmark+0xf0>
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
jmp    1243 <benchmark+0x103>
jmp    1235 <benchmark+0xf5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11dd <benchmark+0x9d>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    126f <benchmark+0x12f>
jp     126f <benchmark+0x12f>
jmp    127b <benchmark+0x13b>
lea    0xd9a(%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    11a6 <benchmark+0x66>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <rand_double@plt>
mulsd  0xe71(%rip),%xmm0
addsd  0xe71(%rip),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %r13d,%r13d
jle    11e7 <benchmark+0xa7>
nopw   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
mov    %r14d,%edi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0x1,%ecx
call   1060 <stdlib_strided_dvarmpn@plt>
ucomisd %xmm0,%xmm0
jp     11f0 <benchmark+0xb0>
add    $0xffffffff,%r13d
jne    11c0 <benchmark+0x80>
jmp    1206 <benchmark+0xc6>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    121d <benchmark+0xdd>
lea    0xe19(%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     1235 <benchmark+0xf5>
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    0xdd4(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    121d <benchmark+0xdd>

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 = %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
store double 0.000000e+00, double* %8
%29 = call double (...) @tic()
store double %29, double* %9
store i32 0, i32* %10
br label %30
30: ; preds = %43, %28
%31 = load i32, i32* %10
%32 = load i32, i32* %3
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* %4
%36 = call double @stdlib_strided_dvarmpn(i32 %35, double 0.000000e+00, i32 1, double* %14, i32 1)
store double %36, double* %8
%37 = load double, double* %8
%38 = load double, double* %8
%39 = fcmp une double %37, %38
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %46
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %30
46: ; preds = %40, %30
%47 = call double (...) @tic()
%48 = load double, double* %9
%49 = fsub double %47, %48
store double %49, double* %5
%50 = load double, double* %8
%51 = load double, double* %8
%52 = fcmp une double %50, %51
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %53, %46
%56 = load double, double* %5
%57 = load i8*, i8** %6
ret double %56
}

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 %13
6: ; preds = %2, %6
%7 = phi i64 [ %11, %6 ], [ 0, %2 ]
%8 = tail call double (...) @rand_double()
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+04, double -1.000000e+04)
%10 = getelementptr inbounds double, double* %4, i64 %7
store double %9, double* %10
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, %3
br i1 %12, label %13, label %6
13: ; preds = %6, %2
%14 = tail call double (...) @tic()
%15 = icmp sgt i32 %0, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call double (...) @tic()
br label %32
18: ; preds = %20
%19 = icmp eq i32 %24, %0
br i1 %19, label %27, label %20
20: ; preds = %13, %18
%21 = phi i32 [ %24, %18 ], [ 0, %13 ]
%22 = call double @stdlib_strided_dvarmpn(i32 %1, double 0.000000e+00, i32 1, double* %4, i32 1)
%23 = fcmp uno double %22, 0.000000e+00
%24 = add nuw nsw i32 %21, 1
br i1 %23, label %25, label %18
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %27
27: ; preds = %18, %25
%28 = call double (...) @tic()
%29 = fcmp uno double %22, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %27
%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 = %16, %30, %27
%33 = phi double [ %17, %16 ], [ %28, %30 ], [ %28, %27 ]
%34 = fsub double %33, %14
ret double %34
}