#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 _p3dOtsuThresholding_u(double *, int);
double _p3dOtsuThresholding_w(double *, int);
double _p3dOtsuThresholding_nu(double *p, int k, double ut, double vt) {
  double x, y;
  y = _p3dOtsuThresholding_w(p, k);
  x = ut * y - _p3dOtsuThresholding_u(p, k);
  x = x * x;
  y = y * (1.0 - y);
  if (y > 0)
    x = x / y;
  else
    x = 0.0;
  return x / vt;
}


x86 assembly (clang, -O0):
<_p3dOtsuThresholding_nu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <_p3dOtsuThresholding_w@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <_p3dOtsuThresholding_u@plt>
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11eb <_p3dOtsuThresholding_nu+0xcb>
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11f3 <_p3dOtsuThresholding_nu+0xd3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_p3dOtsuThresholding_nu>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <_p3dOtsuThresholding_w@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <_p3dOtsuThresholding_u@plt>
movsd  0x8(%rsp),%xmm3
movsd  0xea7(%rip),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jbe    1180 <_p3dOtsuThresholding_nu+0x60>
movsd  (%rsp),%xmm1
mulsd  %xmm3,%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm2,%xmm1
divsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define double @_p3dOtsuThresholding_nu(double* %0, i32 %1, double %2, double %3) {
%5 = tail call double @_p3dOtsuThresholding_w(double* %0, i32 %1)
%6 = tail call double @_p3dOtsuThresholding_u(double* %0, i32 %1)
%7 = fsub double 1.000000e+00, %5
%8 = fmul double %5, %7
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = fneg double %6
%12 = tail call double @llvm.fmuladd.f64(double %2, double %5, double %11)
%13 = fmul double %12, %12
%14 = fdiv double %13, %8
br label %15
15: ; preds = %4, %10
%16 = phi double [ %14, %10 ], [ 0.000000e+00, %4 ]
%17 = fdiv double %16, %3
ret double %17
}