#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 */
double log(double);
double _p3dKapurThresholding_entropy(double *h, int a, double p) {
  if (h[a] > 0.0 && p > 0.0)
    return -(h[a] / p * log((double)(h[a]) / p));
  return 0.0;
}


x86 assembly (clang, -O0):
<_p3dKapurThresholding_entropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ab <_p3dKapurThresholding_entropy+0x9b>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ab <_p3dKapurThresholding_entropy+0x9b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <_p3dKapurThresholding_entropy+0xa3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_p3dKapurThresholding_entropy>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    115b <_p3dKapurThresholding_entropy+0x4b>
movslq %esi,%rax
movsd  (%rdi,%rax,8),%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm3
jbe    115b <_p3dKapurThresholding_entropy+0x4b>
divsd  %xmm1,%xmm3
movapd %xmm3,(%rsp)
movapd %xmm3,%xmm0
call   1030 <log@plt>
movapd (%rsp),%xmm1
xorpd  0xead(%rip),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @_p3dKapurThresholding_entropy(double* %0, i32 %1, double %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
%8 = load double*, double** %5
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %8, i64 %10
%12 = load double, double* %11
%13 = fcmp ogt double %12, 0.000000e+00
br i1 %13, label %14, label %35
14: ; preds = %3
%15 = load double, double* %7
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = load double*, double** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double, double* %7
%24 = fdiv double %22, %23
%25 = load double*, double** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double, double* %7
%31 = fdiv double %29, %30
%32 = call double @log(double %31)
%33 = fmul double %24, %32
%34 = fneg double %33
store double %34, double* %4
br label %36
35: ; preds = %14, %3
store double 0.000000e+00, double* %4
br label %36
36: ; preds = %35, %17
%37 = load double, double* %4
ret double %37
}

LLVM IR (-O2):
define double @_p3dKapurThresholding_entropy(double* nocapture %0, i32 %1, double %2) {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds double, double* %0, i64 %4
%6 = load double, double* %5
%7 = fcmp ogt double %6, 0.000000e+00
%8 = fcmp ogt double %2, 0.000000e+00
%9 = and i1 %8, %7
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = fdiv double %6, %2
%12 = tail call double @log(double %11)
%13 = fneg double %11
%14 = fmul double %12, %13
br label %15
15: ; preds = %3, %10
%16 = phi double [ %14, %10 ], [ 0.000000e+00, %3 ]
ret double %16
}