#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__ FLT_GT(double, double, double);
int /*<<< orphan*/ debug(char *, double);
double fabs(double);
double canberra(double *s, double *z, int len, double bsf, double epsilon) {
  double dist = 0;
  double u, b;
  while (--len) {
    u = fabs(*s - *z);
    b = fabs(*s) + fabs(*z);
    if (b < epsilon) {
      dist += u;
    } else {
      dist += u / b;
    }
    s++;
    z++;
    if (FLT_GT(dist, bsf, epsilon)) {
      debug(" %.6f (early abandoned)\n", dist);
      return dist;
    }
  }
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<canberra>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     123d <canberra+0x11d>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movaps 0xe92(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xe7a(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movaps 0xe67(%rip),%xmm2
pand   %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ce <canberra+0xae>
movsd  -0x40(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11e2 <canberra+0xc2>
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1040 <FLT_GT@plt>
cmp    $0x0,%rax
je     1238 <canberra+0x118>
movsd  -0x38(%rbp),%xmm0
lea    0xdec(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <canberra+0x138>
jmp    1145 <canberra+0x25>
movsd  -0x38(%rbp),%xmm0
lea    0xde0(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canberra>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xffffffff,%r12d
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
nop
cmp    %ebx,%r12d
je     11df <canberra+0xbf>
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
movapd %xmm0,%xmm4
subsd  %xmm1,%xmm4
movapd 0xe8b(%rip),%xmm2
andpd  %xmm2,%xmm4
andpd  %xmm2,%xmm0
andpd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movsd  0x10(%rsp),%xmm2
cmpltsd %xmm2,%xmm0
movapd %xmm0,%xmm3
andnpd %xmm1,%xmm3
movsd  0xe6c(%rip),%xmm1
andpd  %xmm1,%xmm0
orpd   %xmm3,%xmm0
divsd  %xmm0,%xmm4
movsd  (%rsp),%xmm0
addsd  %xmm4,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm1
call   1040 <FLT_GT@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1150 <canberra+0x30>
lea    0xe3b(%rip),%rdi
jmp    11e6 <canberra+0xc6>
lea    0xe4b(%rip),%rdi
movsd  (%rsp),%xmm0
call   1030 <debug@plt>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c" %.6f (early abandoned)\0A\00"
@.str.1 = [7 x i8] c" %.6f\0A\00"
define double @canberra(double* %0, double* %1, i32 %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store double %3, double* %10
store double %4, double* %11
store double 0.000000e+00, double* %12
br label %15
15: ; preds = %60, %5
%16 = load i32, i32* %9
%17 = add nsw i32 %16, -1
store i32 %17, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %61
19: ; preds = %15
%20 = load double*, double** %7
%21 = load double, double* %20
%22 = load double*, double** %8
%23 = load double, double* %22
%24 = fsub double %21, %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %13
%26 = load double*, double** %7
%27 = load double, double* %26
%28 = call double @llvm.fabs.f64(double %27)
%29 = load double*, double** %8
%30 = load double, double* %29
%31 = call double @llvm.fabs.f64(double %30)
%32 = fadd double %28, %31
store double %32, double* %14
%33 = load double, double* %14
%34 = load double, double* %11
%35 = fcmp olt double %33, %34
br i1 %35, label %36, label %40
36: ; preds = %19
%37 = load double, double* %13
%38 = load double, double* %12
%39 = fadd double %38, %37
store double %39, double* %12
br label %46
40: ; preds = %19
%41 = load double, double* %13
%42 = load double, double* %14
%43 = fdiv double %41, %42
%44 = load double, double* %12
%45 = fadd double %44, %43
store double %45, double* %12
br label %46
46: ; preds = %40, %36
%47 = load double*, double** %7
%48 = getelementptr inbounds double, double* %47, i32 1
store double* %48, double** %7
%49 = load double*, double** %8
%50 = getelementptr inbounds double, double* %49, i32 1
store double* %50, double** %8
%51 = load double, double* %12
%52 = load double, double* %10
%53 = load double, double* %11
%54 = call i64 @FLT_GT(double %51, double %52, double %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %46
%57 = load double, double* %12
%58 = call i32 @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %57)
%59 = load double, double* %12
store double %59, double* %6
br label %65
60: ; preds = %46
br label %15
61: ; preds = %15
%62 = load double, double* %12
%63 = call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %62)
%64 = load double, double* %12
store double %64, double* %6
br label %65
65: ; preds = %61, %56
%66 = load double, double* %6
ret double %66
}

LLVM IR (-O2):
@.str = [25 x i8] c" %.6f (early abandoned)\0A\00"
@.str.1 = [7 x i8] c" %.6f\0A\00"
define double @canberra(double* nocapture %0, double* nocapture %1, i32 %2, double %3, double %4) {
br label %6
6: ; preds = %13, %5
%7 = phi i32 [ %2, %5 ], [ %11, %13 ]
%8 = phi double* [ %1, %5 ], [ %26, %13 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %24, %13 ]
%10 = phi double* [ %0, %5 ], [ %25, %13 ]
%11 = add nsw i32 %7, -1
%12 = icmp eq i32 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %6
%14 = load double, double* %10
%15 = load double, double* %8
%16 = fsub double %14, %15
%17 = tail call double @llvm.fabs.f64(double %16)
%18 = tail call double @llvm.fabs.f64(double %14)
%19 = tail call double @llvm.fabs.f64(double %15)
%20 = fadd double %18, %19
%21 = fcmp olt double %20, %4
%22 = select i1 %21, double 1.000000e+00, double %20
%23 = fdiv double %17, %22
%24 = fadd double %9, %23
%25 = getelementptr inbounds double, double* %10, i64 1
%26 = getelementptr inbounds double, double* %8, i64 1
%27 = tail call i64 @FLT_GT(double %24, double %3, double %4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %6, label %29
29: ; preds = %13
%30 = tail call i32 @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %24)
br label %33
31: ; preds = %6
%32 = tail call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %33
33: ; preds = %31, %29
%34 = phi double [ %24, %29 ], [ %9, %31 ]
ret double %34
}