#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_uniformf(float, float);
int /*<<< orphan*/ stdlib_strided_srsqrt(int, float *, int, float *, int);
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len];
  float y[len];
  double t;
  int i;
  for (i = 0; i < len; i++) {
    x[i] = rand_uniformf(0.0f, 200.0f);
    y[i] = 0.0f;
  }
  t = tic();
  for (i = 0; i < iterations; i++) {
    stdlib_strided_srsqrt(len, x, 1, y, 1);
    if (y[0] != y[0]) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y[0] != y[0]) {
    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,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <benchmark+0xa3>
xorps  %xmm0,%xmm0
movss  0xe4d(%rip),%xmm1
call   1050 <rand_uniformf@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rdx
movss  %xmm0,(%rcx,%rdx,4)
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119c <benchmark+0x5c>
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    125b <benchmark+0x11b>
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <stdlib_strided_srsqrt@plt>
mov    -0x40(%rbp),%rax
movss  (%rax),%xmm0
ucomiss (%rax),%xmm0
jne    1237 <benchmark+0xf7>
jp     1237 <benchmark+0xf7>
jmp    1248 <benchmark+0x108>
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    125b <benchmark+0x11b>
jmp    124d <benchmark+0x10d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f6 <benchmark+0xb6>
mov    $0x0,%al
call   1040 <tic@plt>
mov    -0x40(%rbp),%rax
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movss  (%rax),%xmm0
ucomiss (%rax),%xmm0
jne    1288 <benchmark+0x148>
jp     1288 <benchmark+0x148>
jmp    1294 <benchmark+0x154>
lea    0xd75(%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    %edi,%ebx
mov    %esi,%r13d
mov    %rsp,%r12
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %esi,-0x30(%rbp)
test   %esi,%esi
jle    11a7 <benchmark+0x67>
xor    %r14d,%r14d
xchg   %ax,%ax
xorps  %xmm0,%xmm0
movss  0xe75(%rip),%xmm1
call   1050 <rand_uniformf@plt>
movss  %xmm0,(%r12,%r14,4)
movl   $0x0,(%r15,%r14,4)
add    $0x1,%r14
cmp    %r14,%r13
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
mov    -0x30(%rbp),%r14d
jle    11f6 <benchmark+0xb6>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1060 <stdlib_strided_srsqrt@plt>
movss  (%r15),%xmm0
ucomiss %xmm0,%xmm0
jp     11ea <benchmark+0xaa>
add    $0xffffffff,%ebx
jne    11c0 <benchmark+0x80>
jmp    11f6 <benchmark+0xb6>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movss  (%r15),%xmm1
ucomiss %xmm1,%xmm1
jp     121b <benchmark+0xdb>
subsd  -0x38(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde2(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    1207 <benchmark+0xc7>

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

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