#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 */
int /*<<< orphan*/ debug(char *, double);
double fabs(double);
double log(double);
scalar_t__ sqrt(double);
double bhattacharyya(double *s, double *z, int len, double bsf,
                     double epsilon) {
  double dist = 0;
  double sz;
  while (--len) {
    sz = *s * *z;
    if (fabs(sz) < epsilon || sz > 0) {
      dist += sqrt(sz);
    }
    s++;
    z++;
  }
  if (fabs(dist) > epsilon && dist > 0) {
    dist = -log(dist);
  }
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<bhattacharyya>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11e3 <bhattacharyya+0xb3>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xe78(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11ad <bhattacharyya+0x7d>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <bhattacharyya+0x96>
movsd  -0x38(%rbp),%xmm0
call   1050 <sqrt@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1155 <bhattacharyya+0x25>
movsd  -0x30(%rbp),%xmm0
movaps 0xe11(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1236 <bhattacharyya+0x106>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1236 <bhattacharyya+0x106>
movsd  -0x30(%rbp),%xmm0
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdce(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bhattacharyya>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
add    $0xffffffff,%edx
je     11fb <bhattacharyya+0xcb>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
movapd 0xea9(%rip),%xmm4
xorpd  %xmm2,%xmm2
movsd  %xmm1,0x10(%rsp)
jmp    11a2 <bhattacharyya+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm2,(%rsp)
call   1050 <sqrt@plt>
movapd 0xe7e(%rip),%xmm4
movsd  0x10(%rsp),%xmm1
movapd (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11c8 <bhattacharyya+0x98>
movsd  (%r15,%rbx,8),%xmm0
mulsd  (%r14,%rbx,8),%xmm0
movapd %xmm0,%xmm3
andpd  %xmm4,%xmm3
ucomisd %xmm3,%xmm1
ja     1170 <bhattacharyya+0x40>
ucomisd 0xe5c(%rip),%xmm0
jbe    1199 <bhattacharyya+0x69>
jmp    1170 <bhattacharyya+0x40>
movapd 0xe30(%rip),%xmm0
andpd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ff <bhattacharyya+0xcf>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    11ff <bhattacharyya+0xcf>
movapd %xmm2,%xmm0
call   1040 <log@plt>
movapd %xmm0,%xmm2
xorpd  0xe17(%rip),%xmm2
jmp    11ff <bhattacharyya+0xcf>
xorpd  %xmm2,%xmm2
movapd %xmm2,(%rsp)
lea    0xe1d(%rip),%rdi
movapd %xmm2,%xmm0
call   1030 <debug@plt>
movaps (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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