#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 */
float c_sdot(int, float *, int, float *, int);
int /*<<< orphan*/ printf(char *);
float rand_float();
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len];
  float y[len];
  float z;
  double t;
  int i;
  for (i = 0; i < len; i++) {
    x[i] = (rand_float() * 20000.0f) - 10000.0f;
    y[i] = (rand_float() * 20000.0f) - 10000.0f;
  }
  z = 0.0f;
  t = tic();
  for (i = 0; i < iterations; i++) {
    z = c_sdot(len, x, 1, y, 1);
    if (z != z) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (z != z) {
    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,-0x50(%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,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120e <benchmark+0xce>
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x50(%rbp),%rax
movss  0xe45(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe3d(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x3c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x48(%rbp),%rax
movss  0xe19(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe11(%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    119c <benchmark+0x5c>
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    1291 <benchmark+0x151>
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <c_sdot@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
ucomiss -0x2c(%rbp),%xmm0
jne    126d <benchmark+0x12d>
jp     126d <benchmark+0x12d>
jmp    127e <benchmark+0x13e>
lea    0xd94(%rip),%rdi
call   1040 <printf@plt>
jmp    1291 <benchmark+0x151>
jmp    1283 <benchmark+0x143>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1229 <benchmark+0xe9>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movss  -0x2c(%rbp),%xmm0
ucomiss -0x2c(%rbp),%xmm0
jne    12bc <benchmark+0x17c>
jp     12bc <benchmark+0x17c>
jmp    12c8 <benchmark+0x188>
lea    0xd45(%rip),%rdi
call   1040 <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,%r15
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %esi,-0x3c(%rbp)
test   %esi,%esi
jle    11cb <benchmark+0x8b>
xor    %r14d,%r14d
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <rand_float@plt>
movss  0xe71(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe69(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,(%r15,%r14,4)
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe4c(%rip),%xmm0
addss  0xe48(%rip),%xmm0
movss  %xmm0,(%r12,%r14,4)
add    $0x1,%r14
cmp    %r14,%r13
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
jle    1205 <benchmark+0xc5>
mov    -0x3c(%rbp),%r14d
nop
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
mov    $0x1,%r8d
call   1060 <c_sdot@plt>
ucomiss %xmm0,%xmm0
jp     120e <benchmark+0xce>
add    $0xffffffff,%ebx
jne    11e0 <benchmark+0xa0>
jmp    1224 <benchmark+0xe4>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    123a <benchmark+0xfa>
lea    0xdf3(%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     1252 <benchmark+0x112>
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    0xdaf(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    123a <benchmark+0xfa>

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