#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);
int sqrt(int);
double hellinger(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(*s * *z);
    }
    s++;
    z++;
  }
  if (fabs(dist - 1) < epsilon || dist < 1) {
    dist = 2 * sqrt(1 - dist);
  } else {
    dist = 0.0 / 0.0;
  }
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<hellinger>:
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     11e1 <hellinger+0xc1>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xe88(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     119d <hellinger+0x7d>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c4 <hellinger+0xa4>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
cvtsi2sd %eax,%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    1145 <hellinger+0x25>
movsd  -0x30(%rbp),%xmm1
movsd  0xe22(%rip),%xmm0
subsd  %xmm0,%xmm1
movaps 0xe07(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     121f <hellinger+0xff>
movsd  0xdfc(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1246 <hellinger+0x126>
movsd  0xde9(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1253 <hellinger+0x133>
movsd  0xdca(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdc1(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hellinger>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
add    $0xffffffff,%edx
je     11ef <hellinger+0xcf>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
movapd 0xeb9(%rip),%xmm4
xorpd  %xmm2,%xmm2
movsd  %xmm1,0x10(%rsp)
jmp    1197 <hellinger+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cvttsd2si %xmm0,%edi
movsd  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movapd 0xe89(%rip),%xmm4
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11bd <hellinger+0x9d>
movsd  (%r15,%rbx,8),%xmm0
mulsd  (%r14,%rbx,8),%xmm0
movapd %xmm0,%xmm3
andpd  %xmm4,%xmm3
ucomisd %xmm3,%xmm1
ja     1160 <hellinger+0x40>
ucomisd 0xe6f(%rip),%xmm0
jbe    118e <hellinger+0x6e>
jmp    1160 <hellinger+0x40>
movsd  0xe4b(%rip),%xmm0
addsd  %xmm2,%xmm0
andpd  0xe2f(%rip),%xmm0
ucomisd %xmm0,%xmm1
ja     11f3 <hellinger+0xd3>
movsd  0xe41(%rip),%xmm0
ucomisd %xmm2,%xmm0
ja     11f3 <hellinger+0xd3>
movsd  0xe2b(%rip),%xmm0
jmp    1211 <hellinger+0xf1>
xorpd  %xmm2,%xmm2
movsd  0xe25(%rip),%xmm0
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe18(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <debug@plt>
movsd  0x8(%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 @hellinger(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 = %41, %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 %46
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 %41
30: ; preds = %27, %17
%31 = load double*, double** %6
%32 = load double, double* %31
%33 = load double*, double** %7
%34 = load double, double* %33
%35 = fmul double %32, %34
%36 = fptosi double %35 to i32
%37 = call i32 @sqrt(i32 %36)
%38 = sitofp i32 %37 to double
%39 = load double, double* %11
%40 = fadd double %39, %38
store double %40, double* %11
br label %41
41: ; preds = %30, %27
%42 = load double*, double** %6
%43 = getelementptr inbounds double, double* %42, i32 1
store double* %43, double** %6
%44 = load double*, double** %7
%45 = getelementptr inbounds double, double* %44, i32 1
store double* %45, double** %7
br label %13
46: ; preds = %13
%47 = load double, double* %11
%48 = fsub double %47, 1.000000e+00
%49 = call double @llvm.fabs.f64(double %48)
%50 = load double, double* %10
%51 = fcmp olt double %49, %50
br i1 %51, label %55, label %52
52: ; preds = %46
%53 = load double, double* %11
%54 = fcmp olt double %53, 1.000000e+00
br i1 %54, label %55, label %62
55: ; preds = %52, %46
%56 = load double, double* %11
%57 = fsub double 1.000000e+00, %56
%58 = fptosi double %57 to i32
%59 = call i32 @sqrt(i32 %58)
%60 = mul nsw i32 2, %59
%61 = sitofp i32 %60 to double
store double %61, double* %11
br label %63
62: ; preds = %52
store double 0x7FF8000000000000, double* %11
br label %63
63: ; preds = %62, %55
%64 = load double, double* %11
%65 = call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %64)
%66 = load double, double* %11
ret double %66
}

LLVM IR (-O2):
@.str = [7 x i8] c" %.6f\0A\00"
define double @hellinger(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 %37, label %8
8: ; preds = %5, %25
%9 = phi i32 [ %29, %25 ], [ %6, %5 ]
%10 = phi double* [ %27, %25 ], [ %0, %5 ]
%11 = phi double [ %26, %25 ], [ 0.000000e+00, %5 ]
%12 = phi double* [ %28, %25 ], [ %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 %25
20: ; preds = %8
%21 = fptosi double %15 to i32
%22 = tail call i32 @sqrt(i32 %21)
%23 = sitofp i32 %22 to double
%24 = fadd double %11, %23
br label %25
25: ; preds = %8, %20
%26 = phi double [ %24, %20 ], [ %11, %8 ]
%27 = getelementptr inbounds double, double* %10, i64 1
%28 = getelementptr inbounds double, double* %12, i64 1
%29 = add nsw i32 %9, -1
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %8
31: ; preds = %25
%32 = fadd double %26, -1.000000e+00
%33 = tail call double @llvm.fabs.f64(double %32)
%34 = fcmp olt double %33, %4
%35 = fcmp olt double %26, 1.000000e+00
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %37, label %44
37: ; preds = %5, %31
%38 = phi double [ %26, %31 ], [ 0.000000e+00, %5 ]
%39 = fsub double 1.000000e+00, %38
%40 = fptosi double %39 to i32
%41 = tail call i32 @sqrt(i32 %40)
%42 = shl nsw i32 %41, 1
%43 = sitofp i32 %42 to double
br label %44
44: ; preds = %31, %37
%45 = phi double [ %43, %37 ], [ 0x7FF8000000000000, %31 ]
%46 = tail call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %45)
ret double %45
}