#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 c_canberra(double *x, double *y, long n) {
  double den;
  double d = 0.0;
  long i;
  for (i = 0; i < n; i++) {
    den = fabs(x[i]) + fabs(y[i]);
    if (den != 0)
      d += fabs(x[i] - y[i]) / den;
  }
  return d;
}


x86 assembly (clang, -O0):
<c_canberra>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11ce <c_canberra+0xce>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xebe(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xea6(%rip),%xmm2
pand   %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1184 <c_canberra+0x84>
jp     1184 <c_canberra+0x84>
jmp    11b8 <c_canberra+0xb8>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xe5b(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11bd <c_canberra+0xbd>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1120 <c_canberra+0x20>
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_canberra>:
test   %rdx,%rdx
jle    1172 <c_canberra+0x72>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
movapd 0xeed(%rip),%xmm2
movapd 0xee5(%rip),%xmm3
xorpd  %xmm0,%xmm0
jmp    1139 <c_canberra+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rax,%rdx
je     1171 <c_canberra+0x71>
movsd  (%rdi,%rax,8),%xmm4
movapd %xmm4,%xmm7
andpd  %xmm2,%xmm7
movsd  (%rsi,%rax,8),%xmm6
movapd %xmm6,%xmm5
andpd  %xmm2,%xmm5
addsd  %xmm7,%xmm5
ucomisd %xmm1,%xmm5
jne    115f <c_canberra+0x5f>
jnp    1130 <c_canberra+0x30>
subsd  %xmm6,%xmm4
andpd  %xmm3,%xmm4
divsd  %xmm5,%xmm4
addsd  %xmm4,%xmm0
jmp    1130 <c_canberra+0x30>
ret
xorps  %xmm0,%xmm0
ret

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

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