#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);
double kullback(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 += *s * log(*s / *z);
    } else {
      dist += *s;
    }
    s++;
    z++;
  }
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<kullback>:
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     1209 <kullback+0xe9>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movaps 0xe88(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11da <kullback+0xba>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11da <kullback+0xba>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
divsd  (%rax),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ec <kullback+0xcc>
mov    -0x8(%rbp),%rax
movsd  (%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    1145 <kullback+0x25>
movsd  -0x30(%rbp),%xmm0
lea    0xdfb(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kullback>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
add    $0xffffffff,%edx
je     11d0 <kullback+0xb0>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
movapd 0xeb9(%rip),%xmm5
xorpd  %xmm4,%xmm4
movsd  %xmm1,0x8(%rsp)
jmp    116d <kullback+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  %xmm6,%xmm4
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11d4 <kullback+0xb4>
movsd  (%r15,%rbx,8),%xmm6
movsd  (%r14,%rbx,8),%xmm3
movapd %xmm6,%xmm0
mulsd  %xmm3,%xmm0
movapd %xmm0,%xmm2
andpd  %xmm5,%xmm2
ucomisd %xmm1,%xmm2
jbe    1160 <kullback+0x40>
ucomisd 0xe79(%rip),%xmm0
jbe    1160 <kullback+0x40>
movapd %xmm6,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm4,(%rsp)
movsd  %xmm6,0x10(%rsp)
call   1040 <log@plt>
movapd 0xe47(%rip),%xmm5
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm4
jmp    1164 <kullback+0x44>
xorpd  %xmm4,%xmm4
movsd  %xmm4,(%rsp)
lea    0xe38(%rip),%rdi
movapd %xmm4,%xmm0
call   1030 <debug@plt>
movsd  (%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 @kullback(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 = %46, %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 %51
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 ogt double %24, %25
br i1 %26, label %27, label %41
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
%31 = load double*, double** %6
%32 = load double, double* %31
%33 = load double*, double** %6
%34 = load double, double* %33
%35 = load double*, double** %7
%36 = load double, double* %35
%37 = fdiv double %34, %36
%38 = call double @log(double %37)
%39 = load double, double* %11
%40 = call double @llvm.fmuladd.f64(double %32, double %38, double %39)
store double %40, double* %11
br label %46
41: ; preds = %27, %17
%42 = load double*, double** %6
%43 = load double, double* %42
%44 = load double, double* %11
%45 = fadd double %44, %43
store double %45, double* %11
br label %46
46: ; preds = %41, %30
%47 = load double*, double** %6
%48 = getelementptr inbounds double, double* %47, i32 1
store double* %48, double** %6
%49 = load double*, double** %7
%50 = getelementptr inbounds double, double* %49, i32 1
store double* %50, double** %7
br label %13
51: ; preds = %13
%52 = load double, double* %11
%53 = call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %52)
%54 = load double, double* %11
ret double %54
}

LLVM IR (-O2):
@.str = [7 x i8] c" %.6f\0A\00"
define double @kullback(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 %32, label %8
8: ; preds = %5, %26
%9 = phi i32 [ %30, %26 ], [ %6, %5 ]
%10 = phi double* [ %28, %26 ], [ %0, %5 ]
%11 = phi double [ %27, %26 ], [ 0.000000e+00, %5 ]
%12 = phi double* [ %29, %26 ], [ %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 ogt double %16, %4
%18 = fcmp ogt double %15, 0.000000e+00
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %20, label %24
20: ; preds = %8
%21 = fdiv double %13, %14
%22 = tail call double @log(double %21)
%23 = tail call double @llvm.fmuladd.f64(double %13, double %22, double %11)
br label %26
24: ; preds = %8
%25 = fadd double %11, %13
br label %26
26: ; preds = %24, %20
%27 = phi double [ %23, %20 ], [ %25, %24 ]
%28 = getelementptr inbounds double, double* %10, i64 1
%29 = getelementptr inbounds double, double* %12, i64 1
%30 = add nsw i32 %9, -1
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %8
32: ; preds = %26, %5
%33 = phi double [ 0.000000e+00, %5 ], [ %27, %26 ]
%34 = tail call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %33)
ret double %33
}