#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 */
scalar_t__ fabs(double const);
double canberra_distance(const double *u, const double *v, int n) {
  int i;
  double snum = 0.0, sdenom_u = 0.0, sdenom_v = 0.0;
  for (i = 0; i < n; i++) {
    snum += fabs(u[i] - v[i]);
    sdenom_u += fabs(u[i]);
    sdenom_v += fabs(v[i]);
  }
  return snum / (sdenom_u + sdenom_v);
}


x86 assembly (clang, -O0):
<canberra_distance>:
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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cc <canberra_distance+0xbc>
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
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <canberra_distance+0x32>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canberra_distance>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    11db <canberra_distance+0xcb>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm1,0x10(%rsp)
movsd  (%r12,%rbx,8),%xmm0
subsd  (%r14,%rbx,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%r12,%rbx,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%r14,%rbx,8),%xmm0
call   1030 <fabs@plt>
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <canberra_distance+0x40>
movsd  (%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm0
divsd  %xmm2,%xmm0
jmp    11e3 <canberra_distance+0xd3>
movsd  0xe1d(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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