#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 stdlib_strided_dmaxsorted(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] = i;
  }
  v = 0.0;
  t = tic();
  for (i = 0; i < iterations; i++) {
    v = stdlib_strided_dmaxsorted(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    1198 <benchmark+0x68>
mov    -0x40(%rbp),%rax
cvtsi2sdl -0x34(%rbp),%xmm0
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116c <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    1214 <benchmark+0xe4>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
call   1050 <stdlib_strided_dmaxsorted@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    11f0 <benchmark+0xc0>
jp     11f0 <benchmark+0xc0>
jmp    1201 <benchmark+0xd1>
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
jmp    1214 <benchmark+0xe4>
jmp    1206 <benchmark+0xd6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b3 <benchmark+0x83>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1240 <benchmark+0x110>
jp     1240 <benchmark+0x110>
jmp    124c <benchmark+0x11c>
lea    0xdb9(%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   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
mov    %esi,%eax
mov    %rsp,%r15
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r15
mov    %r15,%rsp
test   %esi,%esi
jle    1256 <benchmark+0x126>
cmp    $0x4,%r14d
jae    116e <benchmark+0x3e>
xor    %ecx,%ecx
jmp    1240 <benchmark+0x110>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     12d7 <benchmark+0x1a7>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
movdqa 0xe66(%rip),%xmm0
xor    %esi,%esi
movdqa 0xe6c(%rip),%xmm1
movdqa 0xe74(%rip),%xmm2
movdqa 0xe7c(%rip),%xmm3
movdqa 0xe84(%rip),%xmm4
nopl   0x0(%rax)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movaps %xmm6,(%r15,%rsi,8)
movaps %xmm5,0x10(%r15,%rsi,8)
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm0,%xmm6
cvtdq2pd %xmm5,%xmm5
paddd  %xmm3,%xmm6
cvtdq2pd %xmm6,%xmm6
movaps %xmm5,0x20(%r15,%rsi,8)
movaps %xmm6,0x30(%r15,%rsi,8)
add    $0x8,%rsi
paddd  %xmm4,%xmm0
add    $0xfffffffffffffffe,%rdi
jne    11c0 <benchmark+0x90>
test   $0x1,%dl
je     122f <benchmark+0xff>
cvtdq2pd %xmm0,%xmm1
paddd  0xdf2(%rip),%xmm0
cvtdq2pd %xmm0,%xmm0
movdqa %xmm1,(%r15,%rsi,8)
movdqa %xmm0,0x10(%r15,%rsi,8)
cmp    %rax,%rcx
je     1256 <benchmark+0x126>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,(%r15,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1240 <benchmark+0x110>
xor    %eax,%eax
call   1040 <tic@plt>
movq   %xmm0,-0x28(%rbp)
test   %ebx,%ebx
jle    128d <benchmark+0x15d>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <stdlib_strided_dmaxsorted@plt>
ucomisd %xmm0,%xmm0
jp     1296 <benchmark+0x166>
add    $0xffffffff,%ebx
jne    1270 <benchmark+0x140>
jmp    12ac <benchmark+0x17c>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    12c3 <benchmark+0x193>
lea    0xdb3(%rip),%rdi
movsd  %xmm0,-0x20(%rbp)
call   1030 <puts@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %eax,%eax
call   1040 <tic@plt>
movsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm1
jp     12ef <benchmark+0x1bf>
movsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movdqa 0xd21(%rip),%xmm0
xor    %esi,%esi
test   $0x1,%dl
jne    1212 <benchmark+0xe2>
jmp    122f <benchmark+0xff>
lea    0xd5a(%rip),%rdi
movsd  %xmm0,-0x20(%rbp)
call   1030 <puts@plt>
movsd  -0x20(%rbp),%xmm0
jmp    12c3 <benchmark+0x193>

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 = load i32, i32* %10
%21 = sitofp i32 %20 to double
%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_dmaxsorted(i32 %35, 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 %64
6: ; preds = %2
%7 = icmp ult i32 %1, 4
br i1 %7, label %55, label %8
8: ; preds = %6
%9 = and i64 %3, 4294967292
%10 = add nsw i64 %9, -4
%11 = lshr exact i64 %10, 2
%12 = add nuw nsw i64 %11, 1
%13 = and i64 %12, 1
%14 = icmp eq i64 %10, 0
br i1 %14, label %41, label %15
15: ; preds = %8
%16 = and i64 %12, 9223372036854775806
br label %17
17: ; preds = %17, %15
%18 = phi i64 [ 0, %15 ], [ %37, %17 ]
%19 = phi <2 x i32> [ <i32 0, i32 1>, %15 ], [ %38, %17 ]
%20 = phi i64 [ 0, %15 ], [ %39, %17 ]
%21 = add <2 x i32> %19, <i32 2, i32 2>
%22 = sitofp <2 x i32> %19 to <2 x double>
%23 = sitofp <2 x i32> %21 to <2 x double>
%24 = getelementptr inbounds double, double* %4, i64 %18
%25 = bitcast double* %24 to <2 x double>*
store <2 x double> %22, <2 x double>* %25
%26 = getelementptr inbounds double, double* %24, i64 2
%27 = bitcast double* %26 to <2 x double>*
store <2 x double> %23, <2 x double>* %27
%28 = or i64 %18, 4
%29 = add <2 x i32> %19, <i32 4, i32 4>
%30 = add <2 x i32> %19, <i32 6, i32 6>
%31 = sitofp <2 x i32> %29 to <2 x double>
%32 = sitofp <2 x i32> %30 to <2 x double>
%33 = getelementptr inbounds double, double* %4, i64 %28
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> %31, <2 x double>* %34
%35 = getelementptr inbounds double, double* %33, i64 2
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> %32, <2 x double>* %36
%37 = add nuw i64 %18, 8
%38 = add <2 x i32> %19, <i32 8, i32 8>
%39 = add i64 %20, 2
%40 = icmp eq i64 %39, %16
br i1 %40, label %41, label %17
41: ; preds = %17, %8
%42 = phi i64 [ 0, %8 ], [ %37, %17 ]
%43 = phi <2 x i32> [ <i32 0, i32 1>, %8 ], [ %38, %17 ]
%44 = icmp eq i64 %13, 0
br i1 %44, label %53, label %45
45: ; preds = %41
%46 = add <2 x i32> %43, <i32 2, i32 2>
%47 = sitofp <2 x i32> %43 to <2 x double>
%48 = sitofp <2 x i32> %46 to <2 x double>
%49 = getelementptr inbounds double, double* %4, i64 %42
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %47, <2 x double>* %50
%51 = getelementptr inbounds double, double* %49, i64 2
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %48, <2 x double>* %52
br label %53
53: ; preds = %41, %45
%54 = icmp eq i64 %9, %3
br i1 %54, label %64, label %55
55: ; preds = %6, %53
%56 = phi i64 [ 0, %6 ], [ %9, %53 ]
br label %57
57: ; preds = %55, %57
%58 = phi i64 [ %62, %57 ], [ %56, %55 ]
%59 = trunc i64 %58 to i32
%60 = sitofp i32 %59 to double
%61 = getelementptr inbounds double, double* %4, i64 %58
store double %60, double* %61
%62 = add nuw nsw i64 %58, 1
%63 = icmp eq i64 %62, %3
br i1 %63, label %64, label %57
64: ; preds = %57, %53, %2
%65 = tail call double (...) @tic()
%66 = icmp sgt i32 %0, 0
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = call double (...) @tic()
br label %83
69: ; preds = %71
%70 = icmp eq i32 %75, %0
br i1 %70, label %78, label %71
71: ; preds = %64, %69
%72 = phi i32 [ %75, %69 ], [ 0, %64 ]
%73 = call double @stdlib_strided_dmaxsorted(i32 %1, double* %4, i32 1)
%74 = fcmp uno double %73, 0.000000e+00
%75 = add nuw nsw i32 %72, 1
br i1 %74, label %76, label %69
76: ; preds = %71
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %78
78: ; preds = %69, %76
%79 = call double (...) @tic()
%80 = fcmp uno double %73, 0.000000e+00
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %83
83: ; preds = %67, %81, %78
%84 = phi double [ %68, %67 ], [ %79, %81 ], [ %79, %78 ]
%85 = fsub double %84, %65
ret double %85
}