#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*/ assert(int);
int fabs(float);
float sqrtf(float);
int shrCompareL2fe(const float *reference, const float *data,
                   const unsigned int len, const float epsilon) {
  assert(epsilon >= 0);
  float error = 0;
  float ref = 0;
  unsigned int i;
  for (i = 0; i < len; ++i) {
    float diff = reference[i] - data[i];
    error += diff * diff;
    ref += reference[i] * reference[i];
  }
  float normRef = sqrtf(ref);
  if (fabs(ref) < 1e-7) {
    return 0;
  }
  float normError = sqrtf(error);
  error = normError / normRef;
  int result = error < epsilon;
  return result;
}


x86 assembly (clang, -O0):
<shrCompareL2fe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11f4 <shrCompareL2fe+0xc4>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
subss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
movss  -0x30(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movss  (%rax,%rcx,4),%xmm2
movss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1177 <shrCompareL2fe+0x47>
movss  -0x28(%rbp),%xmm0
call   1050 <sqrtf@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xde7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    122f <shrCompareL2fe+0xff>
movl   $0x0,-0x4(%rbp)
jmp    126b <shrCompareL2fe+0x13b>
movss  -0x24(%rbp),%xmm0
call   1050 <sqrtf@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
divss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm1
movss  -0x20(%rbp),%xmm0
ucomiss %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shrCompareL2fe>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xorps  %xmm1,%xmm1
xor    %edi,%edi
movss  %xmm0,0xc(%rsp)
ucomiss %xmm1,%xmm0
setae  %dil
call   1040 <assert@plt>
test   %ebp,%ebp
je     116d <shrCompareL2fe+0x3d>
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    1172 <shrCompareL2fe+0x42>
xorps  %xmm0,%xmm0
xor    %ecx,%ecx
test   $0x1,%al
jne    11c3 <shrCompareL2fe+0x93>
jmp    11da <shrCompareL2fe+0xaa>
xorps  %xmm3,%xmm3
jmp    11da <shrCompareL2fe+0xaa>
mov    %eax,%edx
and    $0xfffffffe,%edx
xorps  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax)
movss  (%rbx,%rcx,4),%xmm1
movss  0x4(%rbx,%rcx,4),%xmm3
movaps %xmm1,%xmm2
subss  (%r14,%rcx,4),%xmm2
unpcklps %xmm2,%xmm1
mulps  %xmm1,%xmm1
addps  %xmm0,%xmm1
movaps %xmm3,%xmm0
subss  0x4(%r14,%rcx,4),%xmm0
unpcklps %xmm0,%xmm3
mulps  %xmm3,%xmm3
movaps %xmm3,%xmm0
addps  %xmm1,%xmm0
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1180 <shrCompareL2fe+0x50>
addps  %xmm1,%xmm3
test   $0x1,%al
je     11da <shrCompareL2fe+0xaa>
movss  (%rbx,%rcx,4),%xmm3
movaps %xmm3,%xmm1
subss  (%r14,%rcx,4),%xmm1
unpcklps %xmm1,%xmm3
mulps  %xmm3,%xmm3
addps  %xmm0,%xmm3
ucomiss 0xe1f(%rip),%xmm3
movaps %xmm3,0x10(%rsp)
jb     11f1 <shrCompareL2fe+0xc1>
xorps  %xmm0,%xmm0
sqrtss %xmm3,%xmm0
jmp    11fe <shrCompareL2fe+0xce>
movaps %xmm3,%xmm0
call   1050 <sqrtf@plt>
movaps 0x10(%rsp),%xmm3
movss  %xmm0,0x8(%rsp)
movaps %xmm3,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    122a <shrCompareL2fe+0xfa>
movaps 0x10(%rsp),%xmm1
shufps $0x55,%xmm1,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
movaps %xmm1,%xmm0
jb     122e <shrCompareL2fe+0xfe>
sqrtss %xmm0,%xmm0
jmp    1233 <shrCompareL2fe+0x103>
xor    %eax,%eax
jmp    1247 <shrCompareL2fe+0x117>
call   1050 <sqrtf@plt>
divss  0x8(%rsp),%xmm0
xor    %eax,%eax
movss  0xc(%rsp),%xmm1
ucomiss %xmm0,%xmm1
seta   %al
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @shrCompareL2fe(float* %0, float* %1, i32 %2, float %3) {
%5 = alloca i32
%6 = alloca float*
%7 = alloca float*
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca i32
store float* %0, float** %6
store float* %1, float** %7
store i32 %2, i32* %8
store float %3, float* %9
%17 = load float, float* %9
%18 = fcmp oge float %17, 0.000000e+00
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store float 0.000000e+00, float* %10
store float 0.000000e+00, float* %11
store i32 0, i32* %12
br label %21
21: ; preds = %53, %4
%22 = load i32, i32* %12
%23 = load i32, i32* %8
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %21
%26 = load float*, float** %6
%27 = load i32, i32* %12
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds float, float* %26, i64 %28
%30 = load float, float* %29
%31 = load float*, float** %7
%32 = load i32, i32* %12
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds float, float* %31, i64 %33
%35 = load float, float* %34
%36 = fsub float %30, %35
store float %36, float* %13
%37 = load float, float* %13
%38 = load float, float* %13
%39 = load float, float* %10
%40 = call float @llvm.fmuladd.f32(float %37, float %38, float %39)
store float %40, float* %10
%41 = load float*, float** %6
%42 = load i32, i32* %12
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds float, float* %41, i64 %43
%45 = load float, float* %44
%46 = load float*, float** %6
%47 = load i32, i32* %12
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = load float, float* %49
%51 = load float, float* %11
%52 = call float @llvm.fmuladd.f32(float %45, float %50, float %51)
store float %52, float* %11
br label %53
53: ; preds = %25
%54 = load i32, i32* %12
%55 = add i32 %54, 1
store i32 %55, i32* %12
br label %21
56: ; preds = %21
%57 = load float, float* %11
%58 = call float @sqrtf(float %57)
store float %58, float* %14
%59 = load float, float* %11
%60 = call i32 @fabs(float %59)
%61 = sitofp i32 %60 to double
%62 = fcmp olt double %61, 0x3E7AD7F29ABCAF48
br i1 %62, label %63, label %64
63: ; preds = %56
store i32 0, i32* %5
br label %75
64: ; preds = %56
%65 = load float, float* %10
%66 = call float @sqrtf(float %65)
store float %66, float* %15
%67 = load float, float* %15
%68 = load float, float* %14
%69 = fdiv float %67, %68
store float %69, float* %10
%70 = load float, float* %10
%71 = load float, float* %9
%72 = fcmp olt float %70, %71
%73 = zext i1 %72 to i32
store i32 %73, i32* %16
%74 = load i32, i32* %16
store i32 %74, i32* %5
br label %75
75: ; preds = %64, %63
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
define i32 @shrCompareL2fe(float* nocapture %0, float* nocapture %1, i32 %2, float %3) {
%5 = fcmp oge float %3, 0.000000e+00
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i32 %2, 0
br i1 %8, label %55, label %9
9: ; preds = %4
%10 = zext i32 %2 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %2, 1
br i1 %12, label %41, label %13
13: ; preds = %9
%14 = and i64 %10, 4294967294
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %36, %15 ]
%17 = phi <2 x float> [ zeroinitializer, %13 ], [ %35, %15 ]
%18 = phi i64 [ 0, %13 ], [ %37, %15 ]
%19 = getelementptr inbounds float, float* %0, i64 %16
%20 = load float, float* %19
%21 = getelementptr inbounds float, float* %1, i64 %16
%22 = load float, float* %21
%23 = fsub float %20, %22
%24 = insertelement <2 x float> poison, float %20, i64 0
%25 = insertelement <2 x float> %24, float %23, i64 1
%26 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %25, <2 x float> %25, <2 x float> %17)
%27 = or i64 %16, 1
%28 = getelementptr inbounds float, float* %0, i64 %27
%29 = load float, float* %28
%30 = getelementptr inbounds float, float* %1, i64 %27
%31 = load float, float* %30
%32 = fsub float %29, %31
%33 = insertelement <2 x float> poison, float %29, i64 0
%34 = insertelement <2 x float> %33, float %32, i64 1
%35 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %34, <2 x float> %34, <2 x float> %26)
%36 = add nuw nsw i64 %16, 2
%37 = add i64 %18, 2
%38 = icmp eq i64 %37, %14
br i1 %38, label %39, label %15
39: ; preds = %15
%40 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %34, <2 x float> %34, <2 x float> %26)
br label %41
41: ; preds = %39, %9
%42 = phi <2 x float> [ undef, %9 ], [ %40, %39 ]
%43 = phi i64 [ 0, %9 ], [ %36, %39 ]
%44 = phi <2 x float> [ zeroinitializer, %9 ], [ %35, %39 ]
%45 = icmp eq i64 %11, 0
br i1 %45, label %55, label %46
46: ; preds = %41
%47 = getelementptr inbounds float, float* %0, i64 %43
%48 = load float, float* %47
%49 = getelementptr inbounds float, float* %1, i64 %43
%50 = load float, float* %49
%51 = fsub float %48, %50
%52 = insertelement <2 x float> poison, float %48, i64 0
%53 = insertelement <2 x float> %52, float %51, i64 1
%54 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %53, <2 x float> %53, <2 x float> %44)
br label %55
55: ; preds = %46, %41, %4
%56 = phi <2 x float> [ zeroinitializer, %4 ], [ %42, %41 ], [ %54, %46 ]
%57 = extractelement <2 x float> %56, i64 0
%58 = tail call float @sqrtf(float %57)
%59 = tail call i32 @fabs(float %57)
%60 = icmp slt i32 %59, 1
br i1 %60, label %67, label %61
61: ; preds = %55
%62 = extractelement <2 x float> %56, i64 1
%63 = tail call float @sqrtf(float %62)
%64 = fdiv float %63, %58
%65 = fcmp olt float %64, %3
%66 = zext i1 %65 to i32
br label %67
67: ; preds = %55, %61
%68 = phi i32 [ %66, %61 ], [ 0, %55 ]
ret i32 %68
}