#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 _p3dKittlerTresholding_P1(int, double *);
double _p3dKittlerTresholding_P2(int, double *, int);
double _p3dKittlerTresholding_log(double);
double _p3dKittlerTresholding_s1(int, double *);
double _p3dKittlerTresholding_s2(int, double *, int);
double _p3dKittlerTresholding_J(int t, double *h, int hist_length) {
  double a, b, c, d, x1;
  a = _p3dKittlerTresholding_P1(t, h);
  b = _p3dKittlerTresholding_s1(t, h);
  c = _p3dKittlerTresholding_P2(t, h, hist_length);
  d = _p3dKittlerTresholding_s2(t, h, hist_length);
  x1 = 1.0 +
       2.0 * (a * _p3dKittlerTresholding_log(b) +
              c * _p3dKittlerTresholding_log(d)) -
       2.0 * (a * _p3dKittlerTresholding_log(a) +
              c * _p3dKittlerTresholding_log(c));
  return x1;
}


x86 assembly (clang, -O0):
<_p3dKittlerTresholding_J>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <_p3dKittlerTresholding_P1@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <_p3dKittlerTresholding_s1@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <_p3dKittlerTresholding_P2@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <_p3dKittlerTresholding_s2@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  -0x78(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
movsd  0xdfa(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
movaps %xmm0,%xmm4
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_p3dKittlerTresholding_J>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1060 <_p3dKittlerTresholding_P1@plt>
movsd  %xmm0,0x18(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <_p3dKittlerTresholding_s1@plt>
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <_p3dKittlerTresholding_P2@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <_p3dKittlerTresholding_s2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
movapd %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
addsd  0xe1d(%rip),%xmm1
movsd  %xmm1,(%rsp)
call   1040 <_p3dKittlerTresholding_log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <_p3dKittlerTresholding_log@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @_p3dKittlerTresholding_J(i32 %0, double* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store i32 %2, i32* %6
%12 = load i32, i32* %4
%13 = load double*, double** %5
%14 = call double @_p3dKittlerTresholding_P1(i32 %12, double* %13)
store double %14, double* %7
%15 = load i32, i32* %4
%16 = load double*, double** %5
%17 = call double @_p3dKittlerTresholding_s1(i32 %15, double* %16)
store double %17, double* %8
%18 = load i32, i32* %4
%19 = load double*, double** %5
%20 = load i32, i32* %6
%21 = call double @_p3dKittlerTresholding_P2(i32 %18, double* %19, i32 %20)
store double %21, double* %9
%22 = load i32, i32* %4
%23 = load double*, double** %5
%24 = load i32, i32* %6
%25 = call double @_p3dKittlerTresholding_s2(i32 %22, double* %23, i32 %24)
store double %25, double* %10
%26 = load double, double* %7
%27 = load double, double* %8
%28 = call double @_p3dKittlerTresholding_log(double %27)
%29 = load double, double* %9
%30 = load double, double* %10
%31 = call double @_p3dKittlerTresholding_log(double %30)
%32 = fmul double %29, %31
%33 = call double @llvm.fmuladd.f64(double %26, double %28, double %32)
%34 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %33, double 1.000000e+00)
%35 = load double, double* %7
%36 = load double, double* %7
%37 = call double @_p3dKittlerTresholding_log(double %36)
%38 = load double, double* %9
%39 = load double, double* %9
%40 = call double @_p3dKittlerTresholding_log(double %39)
%41 = fmul double %38, %40
%42 = call double @llvm.fmuladd.f64(double %35, double %37, double %41)
%43 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %42, double %34)
store double %43, double* %11
%44 = load double, double* %11
ret double %44
}

LLVM IR (-O2):
define double @_p3dKittlerTresholding_J(i32 %0, double* %1, i32 %2) {
%4 = tail call double @_p3dKittlerTresholding_P1(i32 %0, double* %1)
%5 = tail call double @_p3dKittlerTresholding_s1(i32 %0, double* %1)
%6 = tail call double @_p3dKittlerTresholding_P2(i32 %0, double* %1, i32 %2)
%7 = tail call double @_p3dKittlerTresholding_s2(i32 %0, double* %1, i32 %2)
%8 = tail call double @_p3dKittlerTresholding_log(double %5)
%9 = tail call double @_p3dKittlerTresholding_log(double %7)
%10 = fmul double %6, %9
%11 = tail call double @llvm.fmuladd.f64(double %4, double %8, double %10)
%12 = tail call double @llvm.fmuladd.f64(double %11, double 2.000000e+00, double 1.000000e+00)
%13 = tail call double @_p3dKittlerTresholding_log(double %4)
%14 = tail call double @_p3dKittlerTresholding_log(double %6)
%15 = fmul double %6, %14
%16 = tail call double @llvm.fmuladd.f64(double %4, double %13, double %15)
%17 = tail call double @llvm.fmuladd.f64(double %16, double -2.000000e+00, double %12)
ret double %17
}