#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 *);
float rand_float();
float stdlib_strided_smskmax(int, float *, int, unsigned char *, int);
double tic();
double benchmark(int iterations, int len) {
  unsigned char mask[len];
  double elapsed;
  float x[len];
  float v;
  double t;
  int i;
  for (i = 0; i < len; i++) {
    if (rand_float() < 0.2f) {
      mask[i] = 1;
    } else {
      mask[i] = 0;
    }
    x[i] = (rand_float() * 20000.0f) - 10000.0f;
  }
  v = 0.0f;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_smskmax(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,4),%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    1219 <benchmark+0xd9>
mov    $0x0,%al
call   1030 <rand_float@plt>
movaps %xmm0,%xmm1
movss  0xe47(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    11d3 <benchmark+0x93>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
jmp    11df <benchmark+0x9f>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x48(%rbp),%rax
movss  0xe12(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe0a(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119b <benchmark+0x5b>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    129c <benchmark+0x15c>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <stdlib_strided_smskmax@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
ucomiss -0x2c(%rbp),%xmm0
jne    1278 <benchmark+0x138>
jp     1278 <benchmark+0x138>
jmp    1289 <benchmark+0x149>
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
jmp    129c <benchmark+0x15c>
jmp    128e <benchmark+0x14e>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1234 <benchmark+0xf4>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movss  -0x2c(%rbp),%xmm0
ucomiss -0x2c(%rbp),%xmm0
jne    12c7 <benchmark+0x187>
jp     12c7 <benchmark+0x187>
jmp    12d3 <benchmark+0x193>
lea    0xd3e(%rip),%rdi
call   1040 <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,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %esi,-0x3c(%rbp)
test   %esi,%esi
jle    11cd <benchmark+0x8d>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand_float@plt>
movss  0xe61(%rip),%xmm1
ucomiss %xmm0,%xmm1
seta   (%r15,%r14,1)
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe4e(%rip),%xmm0
addss  0xe4a(%rip),%xmm0
movss  %xmm0,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%r13
jne    1190 <benchmark+0x50>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
jle    1215 <benchmark+0xd5>
mov    -0x3c(%rbp),%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1060 <stdlib_strided_smskmax@plt>
ucomiss %xmm0,%xmm0
jp     121e <benchmark+0xde>
add    $0xffffffff,%ebx
jne    11f0 <benchmark+0xb0>
jmp    1234 <benchmark+0xf4>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    124a <benchmark+0x10a>
lea    0xde7(%rip),%rdi
movss  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1050 <tic@plt>
movss  -0x30(%rbp),%xmm1
ucomiss %xmm1,%xmm1
jp     1262 <benchmark+0x122>
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    0xda3(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    124a <benchmark+0x10a>

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 float
%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 float, 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 float (...) @rand_float()
%25 = fcmp olt float %24, 0x3FC99999A0000000
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 float (...) @rand_float()
%36 = call float @llvm.fmuladd.f32(float %35, float 2.000000e+04, float -1.000000e+04)
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %18, i64 %38
store float %36, float* %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 float 0.000000e+00, float* %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 float @stdlib_strided_smskmax(i32 %50, float* %18, i32 1, i8* %15, i32 1)
store float %51, float* %9
%52 = load float, float* %9
%53 = load float, float* %9
%54 = fcmp une float %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 float, float* %9
%66 = load float, float* %9
%67 = fcmp une float %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 float, 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 float (...) @rand_float()
%10 = fcmp olt float %9, 0x3FC99999A0000000
%11 = zext i1 %10 to i8
%12 = getelementptr inbounds i8, i8* %4, i64 %8
store i8 %11, i8* %12
%13 = tail call float (...) @rand_float()
%14 = tail call float @llvm.fmuladd.f32(float %13, float 2.000000e+04, float -1.000000e+04)
%15 = getelementptr inbounds float, float* %5, i64 %8
store float %14, float* %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 float @stdlib_strided_smskmax(i32 %1, float* %5, i32 1, i8* %4, i32 1)
%28 = fcmp uno float %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 float %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
}