#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_dmskrange(int, double *, int, unsigned char *, int);
double tic();
double benchmark(int iterations, int len) {
  unsigned char mask[len];
  double elapsed;
  double x[len];
  double v;
  double t;
  int i;
  for (i = 0; i < len; i++) {
    if (rand_double() < 0.2) {
      mask[i] = 1;
    } else {
      mask[i] = 0;
    }
    x[i] = (rand_double() * 20000.0) - 10000.0;
  }
  v = 0.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_dmskrange(len, x, 1, mask, 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    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121a <benchmark+0xda>
mov    $0x0,%al
call   1060 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  0xe47(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d4 <benchmark+0x94>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
jmp    11e0 <benchmark+0xa0>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1060 <rand_double@plt>
mov    -0x48(%rbp),%rax
movsd  0xe15(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe11(%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    119b <benchmark+0x5b>
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    129e <benchmark+0x15e>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%r8d
mov    %r8d,%edx
call   1050 <stdlib_strided_dmskrange@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    127a <benchmark+0x13a>
jp     127a <benchmark+0x13a>
jmp    128b <benchmark+0x14b>
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
jmp    129e <benchmark+0x15e>
jmp    1290 <benchmark+0x150>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1235 <benchmark+0xf5>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    12ca <benchmark+0x18a>
jp     12ca <benchmark+0x18a>
jmp    12d6 <benchmark+0x196>
lea    0xd47(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%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    %edi,%ebx
mov    %esi,%r13d
mov    %rsp,%r15
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %esi,-0x3c(%rbp)
test   %esi,%esi
jle    11ce <benchmark+0x8e>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand_double@plt>
movsd  0xe61(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   (%r15,%r14,1)
xor    %eax,%eax
call   1060 <rand_double@plt>
mulsd  0xe51(%rip),%xmm0
addsd  0xe51(%rip),%xmm0
movsd  %xmm0,(%r12,%r14,8)
add    $0x1,%r14
cmp    %r14,%r13
jne    1190 <benchmark+0x50>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
jle    1216 <benchmark+0xd6>
mov    -0x3c(%rbp),%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1050 <stdlib_strided_dmskrange@plt>
ucomisd %xmm0,%xmm0
jp     121f <benchmark+0xdf>
add    $0xffffffff,%ebx
jne    11f0 <benchmark+0xb0>
jmp    1235 <benchmark+0xf5>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    124c <benchmark+0x10c>
lea    0xdf2(%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     1264 <benchmark+0x124>
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    0xdad(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    124c <benchmark+0x10c>

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