#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 d_canberra(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 += (fabs(f1[i] - f2[i]) / aux);
  }
  return (dist);
}


x86 assembly (clang, -O0):
<d_canberra>:
push   %rbp
mov    %rsp,%rbp
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    11ad <d_canberra+0xad>
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 0xeb5(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    119a <d_canberra+0x9a>
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
movaps 0xe79(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    119f <d_canberra+0x9f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    111e <d_canberra+0x1e>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_canberra>:
test   %edx,%edx
jle    1154 <d_canberra+0x54>
mov    %edx,%eax
xorpd  %xmm1,%xmm1
xor    %ecx,%ecx
movapd 0xeec(%rip),%xmm2
xorpd  %xmm0,%xmm0
jmp    1129 <d_canberra+0x29>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1153 <d_canberra+0x53>
movsd  (%rdi,%rcx,8),%xmm3
movsd  (%rsi,%rcx,8),%xmm5
movapd %xmm3,%xmm4
addsd  %xmm5,%xmm4
ucomisd %xmm1,%xmm4
je     1120 <d_canberra+0x20>
subsd  %xmm5,%xmm3
divsd  %xmm4,%xmm3
andpd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
jmp    1120 <d_canberra+0x20>
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @d_canberra(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 @llvm.fabs.f64(double %40)
%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_canberra(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %25
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %21
%8 = phi i64 [ 0, %5 ], [ %23, %21 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %22, %21 ]
%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 %21, label %16
16: ; preds = %7
%17 = fsub double %11, %13
%18 = fdiv double %17, %14
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fadd double %9, %19
br label %21
21: ; preds = %7, %16
%22 = phi double [ %20, %16 ], [ %9, %7 ]
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, %6
br i1 %24, label %25, label %7
25: ; preds = %21, %3
%26 = phi double [ 0.000000e+00, %3 ], [ %22, %21 ]
ret double %26
}