#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 */
double fabs(double);
double pow(double, int);
double d_squared_chi_square(double *f1, double *f2, int n) {
  int i;
  double dist = 0.0f, aux;
  for (i = 0; i < n; i++) {
    aux = fabs(f1[i] + f2[i]);
    if (aux > 0)
      dist += (pow(f1[i] - f2[i], 2) / aux);
  }
  return (dist);
}


x86 assembly (clang, -O0):
<d_squared_chi_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c0 <d_squared_chi_square+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movaps 0xea1(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ad <d_squared_chi_square+0x9d>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
divsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b2 <d_squared_chi_square+0xa2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <d_squared_chi_square+0x22>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_squared_chi_square>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edx,%edx
jle    118b <d_squared_chi_square+0x7b>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
jmp    1139 <d_squared_chi_square+0x29>
add    $0x1,%rbx
cmp    %rbx,%r12
je     118f <d_squared_chi_square+0x7f>
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
movapd %xmm0,%xmm3
addsd  %xmm1,%xmm3
ucomisd 0xebb(%rip),%xmm3
je     1130 <d_squared_chi_square+0x20>
andpd  0xea1(%rip),%xmm3
movapd %xmm3,0x10(%rsp)
subsd  %xmm1,%xmm0
mov    $0x2,%edi
movsd  %xmm2,0x8(%rsp)
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm2
divsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm2
jmp    1130 <d_squared_chi_square+0x20>
xorpd  %xmm2,%xmm2
movapd %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @d_squared_chi_square(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %8
store i32 0, i32* %7
br label %10
10: ; preds = %47, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %50
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fadd double %19, %24
%26 = call double @llvm.fabs.f64(double %25)
store double %26, double* %9
%27 = load double, double* %9
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %46
29: ; preds = %14
%30 = load double*, double** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fsub double %34, %39
%41 = call double @pow(double %40, i32 2)
%42 = load double, double* %9
%43 = fdiv double %41, %42
%44 = load double, double* %8
%45 = fadd double %44, %43
store double %45, double* %8
br label %46
46: ; preds = %29, %14
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %10
50: ; preds = %10
%51 = load double, double* %8
ret double %51
}

LLVM IR (-O2):
define double @d_squared_chi_square(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %26
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %22
%8 = phi i64 [ 0, %5 ], [ %24, %22 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %23, %22 ]
%10 = getelementptr inbounds double, double* %0, i64 %8
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %1, i64 %8
%13 = load double, double* %12
%14 = fadd double %11, %13
%15 = fcmp ueq double %14, 0.000000e+00
br i1 %15, label %22, label %16
16: ; preds = %7
%17 = tail call double @llvm.fabs.f64(double %14)
%18 = fsub double %11, %13
%19 = tail call double @pow(double %18, i32 2)
%20 = fdiv double %19, %17
%21 = fadd double %9, %20
br label %22
22: ; preds = %7, %16
%23 = phi double [ %21, %16 ], [ %9, %7 ]
%24 = add nuw nsw i64 %8, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %26, label %7
26: ; preds = %22, %3
%27 = phi double [ 0.000000e+00, %3 ], [ %23, %22 ]
ret double %27
}