#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 */
unsigned char UCHAR_MAX;
int USHRT_MAX;
double _p3dOtsuThresholding_nu(double *, int, double, double);
double _p3dOtsuThresholding_u(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ p3dGetElapsedTime_min();
int /*<<< orphan*/ p3dGetElapsedTime_sec();
int /*<<< orphan*/ p3dResetStartTime();
int p3dOtsuThresholding_16(unsigned short *in_im, unsigned char *out_im,
                           const int dimx, const int dimy, const int dimz,
                           unsigned short *thresh,
                           int (*wr_log)(const char *, ...),
                           int (*wr_progress)(const int, ...)) {
  double *prob;
  int i, j, k, m;
  double y, z;
  double ut, vt;
  int ct;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Thresholding image according to Otsu's method...");
  }
  if (((prob = (double *)calloc((USHRT_MAX + 1), sizeof(double))) == NULL)) {
    goto MEM_ERROR;
  };
  for (ct = 0; ct < (dimx * dimy * dimz); ct++)
    prob[in_im[ct]] = prob[in_im[ct]] + 1.0;
  for (ct = 0; ct <= USHRT_MAX; ct++)
    prob[ct] = prob[ct] / (double)(dimx * dimy * dimz);
  ut = _p3dOtsuThresholding_u(prob, USHRT_MAX);
  vt = 0.0;
  for (i = 0; i <= USHRT_MAX; i++)
    vt += (i - ut) * (i - ut) * prob[i];
  j = -1;
  k = -1;
  for (i = 0; i <= USHRT_MAX; i++) {
    if ((j < 0) && (prob[i] > 0.0))
      j = i;
    if (prob[i] > 0.0)
      k = i;
  }
  z = -1.0;
  m = -1;
  for (i = j; i <= k; i++) {
    y = _p3dOtsuThresholding_nu(prob, i, ut, vt);
    if (y >= z) {
      z = y;
      m = i;
    }
  }
  *thresh = (unsigned short)m;
#pragma omp parallel for
  for (ct = 0; ct < (dimx * dimy * dimz); ct++)
    out_im[ct] = (in_im[ct] > (*thresh)) ? UCHAR_MAX : 0;
  if (wr_log != NULL) {
    wr_log("\tDetermined threshold: %d.", *thresh);
    wr_log("Pore3D - Image thresholded successfully in %dm%0.3fs.",
           p3dGetElapsedTime_min(), p3dGetElapsedTime_sec());
  }
  if (prob != NULL)
    free(prob);
  return 2;
MEM_ERROR:
  if (wr_log != NULL) {
    wr_log("Pore3D - Not enough (contiguous) memory. Program will exit.");
  }
  if (prob != NULL)
    free(prob);
  return 0;
}


x86 assembly (clang, -O0):
<p3dOtsuThresholding_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,0x10(%rbp)
je     11b7 <p3dOtsuThresholding_16+0x47>
mov    $0x0,%al
call   1090 <p3dResetStartTime@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11e0 <p3dOtsuThresholding_16+0x70>
jmp    14f3 <p3dOtsuThresholding_16+0x383>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    123d <p3dOtsuThresholding_16+0xcd>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x6c(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  0xdf3(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x6c(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11e7 <p3dOtsuThresholding_16+0x77>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%eax
jg     1291 <p3dOtsuThresholding_16+0x121>
mov    -0x38(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1244 <p3dOtsuThresholding_16+0xd4>
mov    -0x38(%rbp),%rdi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
call   1040 <_p3dOtsuThresholding_u@plt>
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2d1f(%rip),%rcx
cmp    (%rcx),%eax
jg     130e <p3dOtsuThresholding_16+0x19e>
cvtsi2sdl -0x3c(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
subsd  -0x60(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12b7 <p3dOtsuThresholding_16+0x147>
movl   $0xffffffff,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2cb3(%rip),%rcx
cmp    (%rcx),%eax
jg     1392 <p3dOtsuThresholding_16+0x222>
cmpl   $0x0,-0x40(%rbp)
jge    135f <p3dOtsuThresholding_16+0x1ef>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    135f <p3dOtsuThresholding_16+0x1ef>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    137f <p3dOtsuThresholding_16+0x20f>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1384 <p3dOtsuThresholding_16+0x214>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1323 <p3dOtsuThresholding_16+0x1b3>
movsd  0xc66(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0xffffffff,-0x48(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     1406 <p3dOtsuThresholding_16+0x296>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
call   1060 <_p3dOtsuThresholding_nu@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
ucomisd -0x58(%rbp),%xmm0
jb     13f3 <p3dOtsuThresholding_16+0x283>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    13f8 <p3dOtsuThresholding_16+0x288>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13ac <p3dOtsuThresholding_16+0x23c>
mov    -0x48(%rbp),%eax
mov    %ax,%cx
mov    -0x30(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1485 <p3dOtsuThresholding_16+0x315>
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movzwl (%rax,%rcx,2),%eax
mov    -0x30(%rbp),%rcx
movzwl (%rcx),%ecx
cmp    %ecx,%eax
jle    145d <p3dOtsuThresholding_16+0x2ed>
mov    0x2b9e(%rip),%rax
movzbl (%rax),%eax
mov    %eax,-0x70(%rbp)
jmp    1467 <p3dOtsuThresholding_16+0x2f7>
xor    %eax,%eax
mov    %eax,-0x70(%rbp)
jmp    1467 <p3dOtsuThresholding_16+0x2f7>
mov    -0x70(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x6c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    141a <p3dOtsuThresholding_16+0x2aa>
cmpq   $0x0,0x10(%rbp)
je     14d3 <p3dOtsuThresholding_16+0x363>
mov    0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
movzwl (%rax),%esi
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   *%rcx
mov    0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1080 <p3dGetElapsedTime_min@plt>
mov    %eax,-0x7c(%rbp)
mov    $0x0,%al
call   1050 <p3dGetElapsedTime_sec@plt>
mov    -0x7c(%rbp),%esi
mov    -0x78(%rbp),%rcx
mov    %eax,%edx
lea    0xb96(%rip),%rdi
mov    $0x0,%al
call   *%rcx
cmpq   $0x0,-0x38(%rbp)
je     14e7 <p3dOtsuThresholding_16+0x377>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1525 <p3dOtsuThresholding_16+0x3b5>
cmpq   $0x0,0x10(%rbp)
je     150a <p3dOtsuThresholding_16+0x39a>
lea    0xb96(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     151e <p3dOtsuThresholding_16+0x3ae>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dOtsuThresholding_16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x28(%rsp)
mov    %r8d,0x10(%rsp)
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x90(%rsp),%rbp
test   %rbp,%rbp
je     11b3 <p3dOtsuThresholding_16+0x43>
xor    %eax,%eax
call   1090 <p3dResetStartTime@plt>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   *%rbp
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1206 <p3dOtsuThresholding_16+0x96>
mov    %rax,%rbx
mov    %r13d,%ebp
imul   %r14d,%ebp
imul   0x10(%rsp),%ebp
mov    %ebp,%r13d
test   %ebp,%ebp
mov    0x2df7(%rip),%r14
jle    12cb <p3dOtsuThresholding_16+0x15b>
lea    -0x1(%r13),%rcx
mov    %r13d,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    1221 <p3dOtsuThresholding_16+0xb1>
xor    %ecx,%ecx
jmp    1298 <p3dOtsuThresholding_16+0x128>
test   %rbp,%rbp
je     169c <p3dOtsuThresholding_16+0x52c>
lea    0xe95(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   *%rbp
jmp    173e <p3dOtsuThresholding_16+0x5ce>
mov    %r13d,%edx
and    $0xfffffffc,%edx
xor    %ecx,%ecx
movsd  0xdcf(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzwl (%r12,%rcx,2),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzwl 0x2(%r12,%rcx,2),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzwl 0x4(%r12,%rcx,2),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzwl 0x6(%r12,%rcx,2),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1240 <p3dOtsuThresholding_16+0xd0>
test   %rax,%rax
je     12cb <p3dOtsuThresholding_16+0x15b>
lea    (%r12,%rcx,2),%rcx
xor    %edx,%edx
movsd  0xd55(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movzwl (%rcx,%rdx,2),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    12b0 <p3dOtsuThresholding_16+0x140>
mov    (%r14),%esi
test   %esi,%esi
js     1387 <p3dOtsuThresholding_16+0x217>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0x1(%rsi),%rax
test   %rsi,%rsi
je     1363 <p3dOtsuThresholding_16+0x1f3>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rdx
mov    %rdx,%r8
shr    %r8
add    $0x1,%r8
test   %rdx,%rdx
je     16a3 <p3dOtsuThresholding_16+0x533>
mov    %r8,%rdx
and    $0xfffffffffffffffe,%rdx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movupd (%rbx,%rdi,8),%xmm2
movupd 0x10(%rbx,%rdi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rdi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx,%rdi,8)
add    $0x4,%rdi
add    $0xfffffffffffffffe,%rdx
jne    1320 <p3dOtsuThresholding_16+0x1b0>
test   $0x1,%r8b
je     135c <p3dOtsuThresholding_16+0x1ec>
movupd (%rbx,%rdi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rdi,8)
cmp    %rax,%rcx
jne    1370 <p3dOtsuThresholding_16+0x200>
jmp    1387 <p3dOtsuThresholding_16+0x217>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1370 <p3dOtsuThresholding_16+0x200>
mov    %ebp,0xc(%rsp)
mov    %rbx,%rdi
call   1040 <_p3dOtsuThresholding_u@plt>
movapd %xmm0,%xmm2
mov    (%r14),%ecx
mov    $0xffffffff,%r14d
test   %ecx,%ecx
mov    %r13,(%rsp)
js     14b8 <p3dOtsuThresholding_16+0x348>
lea    0x1(%rcx),%rax
test   %rcx,%rcx
je     1689 <p3dOtsuThresholding_16+0x519>
mov    %eax,%esi
and    $0xfffffffe,%esi
xorpd  %xmm1,%xmm1
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
subsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
mulsd  (%rbx,%rdx,8),%xmm0
addsd  %xmm1,%xmm0
lea    0x1(%rdx),%edi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm1
mulsd  0x8(%rbx,%rdx,8),%xmm1
addsd  %xmm0,%xmm1
add    $0x2,%rdx
cmp    %rsi,%rdx
jne    13d0 <p3dOtsuThresholding_16+0x260>
test   $0x1,%al
je     1429 <p3dOtsuThresholding_16+0x2b9>
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
subsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
mulsd  (%rbx,%rdx,8),%xmm0
addsd  %xmm0,%xmm1
test   %ecx,%ecx
js     14bc <p3dOtsuThresholding_16+0x34c>
test   %rcx,%rcx
je     16b4 <p3dOtsuThresholding_16+0x544>
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    $0xffffffff,%r13d
xor    %ecx,%ecx
xorpd  %xmm0,%xmm0
mov    $0xffffffff,%ebp
movsd  (%rbx,%rcx,8),%xmm3
ucomisd %xmm0,%xmm3
movsd  0x8(%rbx,%rcx,8),%xmm3
mov    %ebp,%esi
cmova  %ecx,%esi
cmova  %ecx,%r13d
test   %ebp,%ebp
cmovns %ebp,%esi
ucomisd %xmm0,%xmm3
lea    0x1(%rcx),%edi
mov    %esi,%ebp
cmova  %edi,%ebp
cmova  %edi,%r13d
test   %esi,%esi
cmovns %esi,%ebp
add    $0x2,%rcx
cmp    %rdx,%rcx
jne    1450 <p3dOtsuThresholding_16+0x2e0>
test   $0x1,%al
je     14aa <p3dOtsuThresholding_16+0x33a>
movsd  (%rbx,%rcx,8),%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
mov    %ebp,%eax
cmova  %ecx,%eax
cmova  %ecx,%r13d
test   %ebp,%ebp
cmovs  %eax,%ebp
mov    $0xffff,%ax
cmp    %r13d,%ebp
jle    14c7 <p3dOtsuThresholding_16+0x357>
jmp    154e <p3dOtsuThresholding_16+0x3de>
xorpd  %xmm1,%xmm1
mov    $0xffffffff,%r13d
mov    $0xffffffff,%ebp
add    $0x1,%r13d
movsd  0xb35(%rip),%xmm0
movapd %xmm0,%xmm4
movsd  %xmm2,0x38(%rsp)
movsd  %xmm1,0x30(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm0,0x40(%rsp)
movapd %xmm4,0x10(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
movapd %xmm2,%xmm0
call   1060 <_p3dOtsuThresholding_nu@plt>
movapd 0x10(%rsp),%xmm4
movsd  0x30(%rsp),%xmm1
movsd  0x38(%rsp),%xmm2
movapd 0x40(%rsp),%xmm5
ucomisd %xmm5,%xmm0
cmovae %ebp,%r14d
cmpnlesd %xmm0,%xmm4
movapd %xmm4,%xmm3
andnpd %xmm0,%xmm3
andpd  %xmm5,%xmm4
orpd   %xmm3,%xmm4
add    $0x1,%ebp
movapd %xmm4,%xmm0
cmp    %ebp,%r13d
jne    14f0 <p3dOtsuThresholding_16+0x380>
mov    %r14d,%eax
mov    0x28(%rsp),%rbp
mov    %ax,0x0(%rbp)
mov    0xc(%rsp),%esi
test   %esi,%esi
mov    0x90(%rsp),%r14
mov    (%rsp),%r13
jle    16fc <p3dOtsuThresholding_16+0x58c>
xor    %ecx,%ecx
cmp    %ax,(%r12)
mov    0x2a73(%rip),%rax
movzbl (%rax),%edx
cmovbe %ecx,%edx
mov    %dl,(%r15)
cmp    $0x1,%esi
je     16fc <p3dOtsuThresholding_16+0x58c>
lea    -0x1(%r13),%r9
mov    $0x1,%ecx
cmp    $0x10,%r9
jb     16d2 <p3dOtsuThresholding_16+0x562>
lea    0x1(%r15),%rdx
lea    (%r15,%r13,1),%rdi
lea    0x2(%rbp),%rsi
lea    0x2(%r12),%r8
cmp    %rsi,%rdx
setb   %r10b
cmp    %rbp,%rdi
seta   %r11b
lea    (%r12,%r13,2),%rsi
cmp    %rsi,%rdx
setb   %dl
cmp    %r8,%rdi
seta   %r13b
cmp    %rax,%r15
setb   %sil
cmp    %rax,%rdi
seta   %r8b
test   %r11b,%r10b
jne    16ce <p3dOtsuThresholding_16+0x55e>
and    %r13b,%dl
jne    16ce <p3dOtsuThresholding_16+0x55e>
and    %r8b,%sil
mov    (%rsp),%r13
jne    16d2 <p3dOtsuThresholding_16+0x562>
mov    %r9,%rsi
and    $0xfffffffffffffff0,%rsi
lea    0x1(%rsi),%rcx
movzwl 0x0(%rbp),%edx
movd   %edx,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm0
movzbl (%rax),%edx
movd   %edx,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %edi,%edi
movdqa 0x9da(%rip),%xmm2
pxor   %xmm2,%xmm0
nopw   0x0(%rax,%rax,1)
movdqu 0x2(%r12,%rdi,2),%xmm3
movdqu 0x12(%r12,%rdi,2),%xmm4
pxor   %xmm2,%xmm3
pcmpgtw %xmm0,%xmm3
packsswb %xmm3,%xmm3
pxor   %xmm2,%xmm4
pcmpgtw %xmm0,%xmm4
packsswb %xmm4,%xmm4
pand   %xmm1,%xmm3
pand   %xmm1,%xmm4
punpcklqdq %xmm4,%xmm3
movdqu %xmm3,0x1(%r15,%rdi,1)
add    $0x10,%rdi
cmp    %rdi,%rsi
jne    1640 <p3dOtsuThresholding_16+0x4d0>
cmp    %rsi,%r9
jne    16d2 <p3dOtsuThresholding_16+0x562>
jmp    16fc <p3dOtsuThresholding_16+0x58c>
xorpd  %xmm1,%xmm1
xor    %edx,%edx
test   $0x1,%al
jne    1411 <p3dOtsuThresholding_16+0x2a1>
jmp    1429 <p3dOtsuThresholding_16+0x2b9>
xor    %ebx,%ebx
jmp    173e <p3dOtsuThresholding_16+0x5ce>
xor    %edi,%edi
test   $0x1,%r8b
jne    134e <p3dOtsuThresholding_16+0x1de>
jmp    135c <p3dOtsuThresholding_16+0x1ec>
mov    $0xffffffff,%r13d
xor    %ecx,%ecx
mov    $0xffffffff,%ebp
test   $0x1,%al
jne    148f <p3dOtsuThresholding_16+0x31f>
jmp    14aa <p3dOtsuThresholding_16+0x33a>
mov    (%rsp),%r13
mov    %rcx,%rdx
not    %rdx
test   $0x1,%r13b
jne    16f7 <p3dOtsuThresholding_16+0x587>
movzwl (%r12,%rcx,2),%esi
xor    %edi,%edi
cmp    0x0(%rbp),%si
movzbl (%rax),%esi
cmovbe %edi,%esi
mov    %sil,(%r15,%rcx,1)
add    $0x1,%rcx
add    %r13,%rdx
jne    175e <p3dOtsuThresholding_16+0x5ee>
test   %r14,%r14
je     1731 <p3dOtsuThresholding_16+0x5c1>
movzwl 0x0(%rbp),%esi
lea    0x94e(%rip),%rdi
xor    %eax,%eax
call   *%r14
xor    %eax,%eax
call   1080 <p3dGetElapsedTime_min@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_sec@plt>
lea    0x94d(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
nop
mov    %dl,0x1(%r15,%rcx,1)
add    $0x2,%rcx
cmp    %rcx,%r13
je     16fc <p3dOtsuThresholding_16+0x58c>
movzwl (%r12,%rcx,2),%esi
xor    %edx,%edx
cmp    0x0(%rbp),%si
ja     1770 <p3dOtsuThresholding_16+0x600>
xor    %esi,%esi
jmp    1773 <p3dOtsuThresholding_16+0x603>
nop
movzbl (%rax),%esi
mov    %sil,(%r15,%rcx,1)
movzwl 0x2(%r12,%rcx,2),%esi
cmp    0x0(%rbp),%si
jbe    1750 <p3dOtsuThresholding_16+0x5e0>
movzbl (%rax),%edx
jmp    1750 <p3dOtsuThresholding_16+0x5e0>

LLVM IR (-O0):
@.str = [58 x i8] c"Pore3D - Thresholding image according to Otsu's method...\00"
@USHRT_MAX = global i32 0
@UCHAR_MAX = global i8 0
@.str.1 = [27 x i8] c"\09Determined threshold: %d.\00"
@.str.2 = [54 x i8] c"Pore3D - Image thresholded successfully in %dm%0.3fs.\00"
@.str.3 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dOtsuThresholding_16(i16* %0, i8* %1, i32 %2, i32 %3, i32 %4, i16* %5, i32 (i8*, ...)* %6, i32 (i32, ...)* %7) {
%9 = alloca i32
%10 = alloca i16*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i16*
%16 = alloca i32 (i8*, ...)*
%17 = alloca i32 (i32, ...)*
%18 = alloca double*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca i32
store i16* %0, i16** %10
store i8* %1, i8** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i16* %5, i16** %15
store i32 (i8*, ...)* %6, i32 (i8*, ...)** %16
store i32 (i32, ...)* %7, i32 (i32, ...)** %17
%28 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%29 = icmp ne i32 (i8*, ...)* %28, null
br i1 %29, label %30, label %34
30: ; preds = %8
%31 = call i32 (...) @p3dResetStartTime()
%32 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%33 = call i32 (i8*, ...) %32(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %30, %8
%35 = load i32, i32* @USHRT_MAX
%36 = add nsw i32 %35, 1
%37 = call i64 @calloc(i32 %36, i32 8)
%38 = inttoptr i64 %37 to double*
store double* %38, double** %18
%39 = icmp eq double* %38, null
br i1 %39, label %40, label %41
40: ; preds = %34
br label %234
41: ; preds = %34
store i32 0, i32* %27
br label %42
42: ; preds = %69, %41
%43 = load i32, i32* %27
%44 = load i32, i32* %12
%45 = load i32, i32* %13
%46 = mul nsw i32 %44, %45
%47 = load i32, i32* %14
%48 = mul nsw i32 %46, %47
%49 = icmp slt i32 %43, %48
br i1 %49, label %50, label %72
50: ; preds = %42
%51 = load double*, double** %18
%52 = load i16*, i16** %10
%53 = load i32, i32* %27
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i16, i16* %52, i64 %54
%56 = load i16, i16* %55
%57 = zext i16 %56 to i64
%58 = getelementptr inbounds double, double* %51, i64 %57
%59 = load double, double* %58
%60 = fadd double %59, 1.000000e+00
%61 = load double*, double** %18
%62 = load i16*, i16** %10
%63 = load i32, i32* %27
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i16, i16* %62, i64 %64
%66 = load i16, i16* %65
%67 = zext i16 %66 to i64
%68 = getelementptr inbounds double, double* %61, i64 %67
store double %60, double* %68
br label %69
69: ; preds = %50
%70 = load i32, i32* %27
%71 = add nsw i32 %70, 1
store i32 %71, i32* %27
br label %42
72: ; preds = %42
store i32 0, i32* %27
br label %73
73: ; preds = %94, %72
%74 = load i32, i32* %27
%75 = load i32, i32* @USHRT_MAX
%76 = icmp sle i32 %74, %75
br i1 %76, label %77, label %97
77: ; preds = %73
%78 = load double*, double** %18
%79 = load i32, i32* %27
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
%82 = load double, double* %81
%83 = load i32, i32* %12
%84 = load i32, i32* %13
%85 = mul nsw i32 %83, %84
%86 = load i32, i32* %14
%87 = mul nsw i32 %85, %86
%88 = sitofp i32 %87 to double
%89 = fdiv double %82, %88
%90 = load double*, double** %18
%91 = load i32, i32* %27
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
store double %89, double* %93
br label %94
94: ; preds = %77
%95 = load i32, i32* %27
%96 = add nsw i32 %95, 1
store i32 %96, i32* %27
br label %73
97: ; preds = %73
%98 = load double*, double** %18
%99 = load i32, i32* @USHRT_MAX
%100 = call double @_p3dOtsuThresholding_u(double* %98, i32 %99)
store double %100, double* %25
store double 0.000000e+00, double* %26
store i32 0, i32* %19
br label %101
101: ; preds = %122, %97
%102 = load i32, i32* %19
%103 = load i32, i32* @USHRT_MAX
%104 = icmp sle i32 %102, %103
br i1 %104, label %105, label %125
105: ; preds = %101
%106 = load i32, i32* %19
%107 = sitofp i32 %106 to double
%108 = load double, double* %25
%109 = fsub double %107, %108
%110 = load i32, i32* %19
%111 = sitofp i32 %110 to double
%112 = load double, double* %25
%113 = fsub double %111, %112
%114 = fmul double %109, %113
%115 = load double*, double** %18
%116 = load i32, i32* %19
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds double, double* %115, i64 %117
%119 = load double, double* %118
%120 = load double, double* %26
%121 = call double @llvm.fmuladd.f64(double %114, double %119, double %120)
store double %121, double* %26
br label %122
122: ; preds = %105
%123 = load i32, i32* %19
%124 = add nsw i32 %123, 1
store i32 %124, i32* %19
br label %101
125: ; preds = %101
store i32 -1, i32* %20
store i32 -1, i32* %21
store i32 0, i32* %19
br label %126
126: ; preds = %152, %125
%127 = load i32, i32* %19
%128 = load i32, i32* @USHRT_MAX
%129 = icmp sle i32 %127, %128
br i1 %129, label %130, label %155
130: ; preds = %126
%131 = load i32, i32* %20
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %142
133: ; preds = %130
%134 = load double*, double** %18
%135 = load i32, i32* %19
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds double, double* %134, i64 %136
%138 = load double, double* %137
%139 = fcmp ogt double %138, 0.000000e+00
br i1 %139, label %140, label %142
140: ; preds = %133
%141 = load i32, i32* %19
store i32 %141, i32* %20
br label %142
142: ; preds = %140, %133, %130
%143 = load double*, double** %18
%144 = load i32, i32* %19
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds double, double* %143, i64 %145
%147 = load double, double* %146
%148 = fcmp ogt double %147, 0.000000e+00
br i1 %148, label %149, label %151
149: ; preds = %142
%150 = load i32, i32* %19
store i32 %150, i32* %21
br label %151
151: ; preds = %149, %142
br label %152
152: ; preds = %151
%153 = load i32, i32* %19
%154 = add nsw i32 %153, 1
store i32 %154, i32* %19
br label %126
155: ; preds = %126
store double -1.000000e+00, double* %24
store i32 -1, i32* %22
%156 = load i32, i32* %20
store i32 %156, i32* %19
br label %157
157: ; preds = %174, %155
%158 = load i32, i32* %19
%159 = load i32, i32* %21
%160 = icmp sle i32 %158, %159
br i1 %160, label %161, label %177
161: ; preds = %157
%162 = load double*, double** %18
%163 = load i32, i32* %19
%164 = load double, double* %25
%165 = load double, double* %26
%166 = call double @_p3dOtsuThresholding_nu(double* %162, i32 %163, double %164, double %165)
store double %166, double* %23
%167 = load double, double* %23
%168 = load double, double* %24
%169 = fcmp oge double %167, %168
br i1 %169, label %170, label %173
170: ; preds = %161
%171 = load double, double* %23
store double %171, double* %24
%172 = load i32, i32* %19
store i32 %172, i32* %22
br label %173
173: ; preds = %170, %161
br label %174
174: ; preds = %173
%175 = load i32, i32* %19
%176 = add nsw i32 %175, 1
store i32 %176, i32* %19
br label %157
177: ; preds = %157
%178 = load i32, i32* %22
%179 = trunc i32 %178 to i16
%180 = load i16*, i16** %15
store i16 %179, i16* %180
store i32 0, i32* %27
br label %181
181: ; preds = %211, %177
%182 = load i32, i32* %27
%183 = load i32, i32* %12
%184 = load i32, i32* %13
%185 = mul nsw i32 %183, %184
%186 = load i32, i32* %14
%187 = mul nsw i32 %185, %186
%188 = icmp slt i32 %182, %187
br i1 %188, label %189, label %214
189: ; preds = %181
%190 = load i16*, i16** %10
%191 = load i32, i32* %27
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds i16, i16* %190, i64 %192
%194 = load i16, i16* %193
%195 = zext i16 %194 to i32
%196 = load i16*, i16** %15
%197 = load i16, i16* %196
%198 = zext i16 %197 to i32
%199 = icmp sgt i32 %195, %198
br i1 %199, label %200, label %203
200: ; preds = %189
%201 = load i8, i8* @UCHAR_MAX
%202 = zext i8 %201 to i32
br label %204
203: ; preds = %189
br label %204
204: ; preds = %203, %200
%205 = phi i32 [ %202, %200 ], [ 0, %203 ]
%206 = trunc i32 %205 to i8
%207 = load i8*, i8** %11
%208 = load i32, i32* %27
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds i8, i8* %207, i64 %209
store i8 %206, i8* %210
br label %211
211: ; preds = %204
%212 = load i32, i32* %27
%213 = add nsw i32 %212, 1
store i32 %213, i32* %27
br label %181
214: ; preds = %181
%215 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%216 = icmp ne i32 (i8*, ...)* %215, null
br i1 %216, label %217, label %227
217: ; preds = %214
%218 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%219 = load i16*, i16** %15
%220 = load i16, i16* %219
%221 = zext i16 %220 to i32
%222 = call i32 (i8*, ...) %218(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %221)
%223 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%224 = call i32 (...) @p3dGetElapsedTime_min()
%225 = call i32 (...) @p3dGetElapsedTime_sec()
%226 = call i32 (i8*, ...) %223(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %224, i32 %225)
br label %227
227: ; preds = %217, %214
%228 = load double*, double** %18
%229 = icmp ne double* %228, null
br i1 %229, label %230, label %233
230: ; preds = %227
%231 = load double*, double** %18
%232 = call i32 @free(double* %231)
br label %233
233: ; preds = %230, %227
store i32 2, i32* %9
br label %247
234: ; preds = %40
%235 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%236 = icmp ne i32 (i8*, ...)* %235, null
br i1 %236, label %237, label %240
237: ; preds = %234
%238 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%239 = call i32 (i8*, ...) %238(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %240
240: ; preds = %237, %234
%241 = load double*, double** %18
%242 = icmp ne double* %241, null
br i1 %242, label %243, label %246
243: ; preds = %240
%244 = load double*, double** %18
%245 = call i32 @free(double* %244)
br label %246
246: ; preds = %243, %240
store i32 0, i32* %9
br label %247
247: ; preds = %246, %233
%248 = load i32, i32* %9
ret i32 %248
}

LLVM IR (-O2):
@.str = [58 x i8] c"Pore3D - Thresholding image according to Otsu's method...\00"
@USHRT_MAX = global i32 0
@UCHAR_MAX = global i8 0
@.str.1 = [27 x i8] c"\09Determined threshold: %d.\00"
@.str.2 = [54 x i8] c"Pore3D - Image thresholded successfully in %dm%0.3fs.\00"
@.str.3 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dOtsuThresholding_16(i16* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3, i32 %4, i16* nocapture %5, i32 (i8*, ...)* %6, i32 (i32, ...)* nocapture readnone %7) {
%9 = bitcast i16* %5 to i8*
%10 = icmp eq i32 (i8*, ...)* %6, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 (...) @p3dResetStartTime()
%13 = tail call i32 (i8*, ...) %6(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %8
%15 = load i32, i32* @USHRT_MAX
%16 = add nsw i32 %15, 1
%17 = tail call i64 @calloc(i32 %16, i32 8)
%18 = inttoptr i64 %17 to double*
%19 = icmp eq i64 %17, 0
br i1 %19, label %369, label %20
20: ; preds = %14
%21 = mul nsw i32 %3, %2
%22 = mul i32 %21, %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %46
24: ; preds = %20
%25 = zext i32 %22 to i64
%26 = add nsw i64 %25, -1
%27 = and i64 %25, 3
%28 = icmp ult i64 %26, 3
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = and i64 %25, 4294967292
br label %95
31: ; preds = %95, %24
%32 = phi i64 [ 0, %24 ], [ %125, %95 ]
%33 = icmp eq i64 %27, 0
br i1 %33, label %46, label %34
34: ; preds = %31, %34
%35 = phi i64 [ %43, %34 ], [ %32, %31 ]
%36 = phi i64 [ %44, %34 ], [ 0, %31 ]
%37 = getelementptr inbounds i16, i16* %0, i64 %35
%38 = load i16, i16* %37
%39 = zext i16 %38 to i64
%40 = getelementptr inbounds double, double* %18, i64 %39
%41 = load double, double* %40
%42 = fadd double %41, 1.000000e+00
store double %42, double* %40
%43 = add nuw nsw i64 %35, 1
%44 = add i64 %36, 1
%45 = icmp eq i64 %44, %27
br i1 %45, label %46, label %34
46: ; preds = %31, %34, %20
%47 = load i32, i32* @USHRT_MAX
%48 = icmp slt i32 %47, 0
br i1 %48, label %135, label %49
49: ; preds = %46
%50 = sitofp i32 %22 to double
%51 = add nuw i32 %47, 1
%52 = zext i32 %51 to i64
%53 = icmp eq i32 %47, 0
br i1 %53, label %93, label %54
54: ; preds = %49
%55 = and i64 %52, 4294967294
%56 = insertelement <2 x double> poison, double %50, i64 0
%57 = shufflevector <2 x double> %56, <2 x double> poison, <2 x i32> zeroinitializer
%58 = add nsw i64 %55, -2
%59 = lshr exact i64 %58, 1
%60 = add nuw i64 %59, 1
%61 = and i64 %60, 1
%62 = icmp eq i64 %58, 0
br i1 %62, label %82, label %63
63: ; preds = %54
%64 = and i64 %60, -2
br label %65
65: ; preds = %65, %63
%66 = phi i64 [ 0, %63 ], [ %79, %65 ]
%67 = phi i64 [ 0, %63 ], [ %80, %65 ]
%68 = getelementptr inbounds double, double* %18, i64 %66
%69 = bitcast double* %68 to <2 x double>*
%70 = load <2 x double>, <2 x double>* %69
%71 = fdiv <2 x double> %70, %57
%72 = bitcast double* %68 to <2 x double>*
store <2 x double> %71, <2 x double>* %72
%73 = or i64 %66, 2
%74 = getelementptr inbounds double, double* %18, i64 %73
%75 = bitcast double* %74 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = fdiv <2 x double> %76, %57
%78 = bitcast double* %74 to <2 x double>*
store <2 x double> %77, <2 x double>* %78
%79 = add nuw i64 %66, 4
%80 = add nuw i64 %67, 2
%81 = icmp eq i64 %80, %64
br i1 %81, label %82, label %65
82: ; preds = %65, %54
%83 = phi i64 [ 0, %54 ], [ %79, %65 ]
%84 = icmp eq i64 %61, 0
br i1 %84, label %91, label %85
85: ; preds = %82
%86 = getelementptr inbounds double, double* %18, i64 %83
%87 = bitcast double* %86 to <2 x double>*
%88 = load <2 x double>, <2 x double>* %87
%89 = fdiv <2 x double> %88, %57
%90 = bitcast double* %86 to <2 x double>*
store <2 x double> %89, <2 x double>* %90
br label %91
91: ; preds = %82, %85
%92 = icmp eq i64 %55, %52
br i1 %92, label %135, label %93
93: ; preds = %49, %91
%94 = phi i64 [ 0, %49 ], [ %55, %91 ]
br label %128
95: ; preds = %95, %29
%96 = phi i64 [ 0, %29 ], [ %125, %95 ]
%97 = phi i64 [ 0, %29 ], [ %126, %95 ]
%98 = getelementptr inbounds i16, i16* %0, i64 %96
%99 = load i16, i16* %98
%100 = zext i16 %99 to i64
%101 = getelementptr inbounds double, double* %18, i64 %100
%102 = load double, double* %101
%103 = fadd double %102, 1.000000e+00
store double %103, double* %101
%104 = or i64 %96, 1
%105 = getelementptr inbounds i16, i16* %0, i64 %104
%106 = load i16, i16* %105
%107 = zext i16 %106 to i64
%108 = getelementptr inbounds double, double* %18, i64 %107
%109 = load double, double* %108
%110 = fadd double %109, 1.000000e+00
store double %110, double* %108
%111 = or i64 %96, 2
%112 = getelementptr inbounds i16, i16* %0, i64 %111
%113 = load i16, i16* %112
%114 = zext i16 %113 to i64
%115 = getelementptr inbounds double, double* %18, i64 %114
%116 = load double, double* %115
%117 = fadd double %116, 1.000000e+00
store double %117, double* %115
%118 = or i64 %96, 3
%119 = getelementptr inbounds i16, i16* %0, i64 %118
%120 = load i16, i16* %119
%121 = zext i16 %120 to i64
%122 = getelementptr inbounds double, double* %18, i64 %121
%123 = load double, double* %122
%124 = fadd double %123, 1.000000e+00
store double %124, double* %122
%125 = add nuw nsw i64 %96, 4
%126 = add i64 %97, 4
%127 = icmp eq i64 %126, %30
br i1 %127, label %31, label %95
128: ; preds = %93, %128
%129 = phi i64 [ %133, %128 ], [ %94, %93 ]
%130 = getelementptr inbounds double, double* %18, i64 %129
%131 = load double, double* %130
%132 = fdiv double %131, %50
store double %132, double* %130
%133 = add nuw nsw i64 %129, 1
%134 = icmp eq i64 %133, %52
br i1 %134, label %135, label %128
135: ; preds = %128, %91, %46
%136 = tail call double @_p3dOtsuThresholding_u(double* %18, i32 %47)
%137 = load i32, i32* @USHRT_MAX
%138 = icmp slt i32 %137, 0
br i1 %138, label %211, label %139
139: ; preds = %135
%140 = add nuw i32 %137, 1
%141 = zext i32 %140 to i64
%142 = add nsw i64 %141, -1
%143 = and i64 %141, 1
%144 = icmp eq i64 %142, 0
br i1 %144, label %147, label %145
145: ; preds = %139
%146 = and i64 %141, 4294967294
br label %167
147: ; preds = %167, %139
%148 = phi double [ undef, %139 ], [ %185, %167 ]
%149 = phi i64 [ 0, %139 ], [ %186, %167 ]
%150 = phi double [ 0.000000e+00, %139 ], [ %185, %167 ]
%151 = icmp eq i64 %143, 0
br i1 %151, label %160, label %152
152: ; preds = %147
%153 = trunc i64 %149 to i32
%154 = sitofp i32 %153 to double
%155 = fsub double %154, %136
%156 = fmul double %155, %155
%157 = getelementptr inbounds double, double* %18, i64 %149
%158 = load double, double* %157
%159 = tail call double @llvm.fmuladd.f64(double %156, double %158, double %150)
br label %160
160: ; preds = %147, %152
%161 = phi double [ %148, %147 ], [ %159, %152 ]
br i1 %138, label %211, label %162
162: ; preds = %160
%163 = and i64 %141, 1
%164 = icmp eq i64 %142, 0
br i1 %164, label %189, label %165
165: ; preds = %162
%166 = and i64 %141, 4294967294
br label %215
167: ; preds = %167, %145
%168 = phi i64 [ 0, %145 ], [ %186, %167 ]
%169 = phi double [ 0.000000e+00, %145 ], [ %185, %167 ]
%170 = phi i64 [ 0, %145 ], [ %187, %167 ]
%171 = trunc i64 %168 to i32
%172 = sitofp i32 %171 to double
%173 = fsub double %172, %136
%174 = fmul double %173, %173
%175 = getelementptr inbounds double, double* %18, i64 %168
%176 = load double, double* %175
%177 = tail call double @llvm.fmuladd.f64(double %174, double %176, double %169)
%178 = or i64 %168, 1
%179 = trunc i64 %178 to i32
%180 = sitofp i32 %179 to double
%181 = fsub double %180, %136
%182 = fmul double %181, %181
%183 = getelementptr inbounds double, double* %18, i64 %178
%184 = load double, double* %183
%185 = tail call double @llvm.fmuladd.f64(double %182, double %184, double %177)
%186 = add nuw nsw i64 %168, 2
%187 = add i64 %170, 2
%188 = icmp eq i64 %187, %146
br i1 %188, label %147, label %167
189: ; preds = %215, %162
%190 = phi i32 [ undef, %162 ], [ %237, %215 ]
%191 = phi i32 [ undef, %162 ], [ %240, %215 ]
%192 = phi i64 [ 0, %162 ], [ %241, %215 ]
%193 = phi i32 [ -1, %162 ], [ %240, %215 ]
%194 = phi i32 [ -1, %162 ], [ %237, %215 ]
%195 = icmp eq i64 %163, 0
br i1 %195, label %207, label %196
196: ; preds = %189
%197 = icmp slt i32 %194, 0
%198 = getelementptr inbounds double, double* %18, i64 %192
%199 = load double, double* %198
%200 = fcmp ogt double %199, 0.000000e+00
%201 = select i1 %197, i1 %200, i1 false
%202 = trunc i64 %192 to i32
%203 = select i1 %201, i32 %202, i32 %194
%204 = fcmp ogt double %199, 0.000000e+00
%205 = trunc i64 %192 to i32
%206 = select i1 %204, i32 %205, i32 %193
br label %207
207: ; preds = %189, %196
%208 = phi i32 [ %190, %189 ], [ %203, %196 ]
%209 = phi i32 [ %191, %189 ], [ %206, %196 ]
%210 = icmp sgt i32 %208, %209
br i1 %210, label %256, label %211
211: ; preds = %135, %160, %207
%212 = phi i32 [ %209, %207 ], [ -1, %160 ], [ -1, %135 ]
%213 = phi i32 [ %208, %207 ], [ -1, %160 ], [ -1, %135 ]
%214 = phi double [ %161, %207 ], [ %161, %160 ], [ 0.000000e+00, %135 ]
br label %244
215: ; preds = %215, %165
%216 = phi i64 [ 0, %165 ], [ %241, %215 ]
%217 = phi i32 [ -1, %165 ], [ %240, %215 ]
%218 = phi i32 [ -1, %165 ], [ %237, %215 ]
%219 = phi i64 [ 0, %165 ], [ %242, %215 ]
%220 = icmp slt i32 %218, 0
%221 = getelementptr inbounds double, double* %18, i64 %216
%222 = load double, double* %221
%223 = fcmp ogt double %222, 0.000000e+00
%224 = select i1 %220, i1 %223, i1 false
%225 = trunc i64 %216 to i32
%226 = select i1 %224, i32 %225, i32 %218
%227 = fcmp ogt double %222, 0.000000e+00
%228 = trunc i64 %216 to i32
%229 = select i1 %227, i32 %228, i32 %217
%230 = or i64 %216, 1
%231 = icmp slt i32 %226, 0
%232 = getelementptr inbounds double, double* %18, i64 %230
%233 = load double, double* %232
%234 = fcmp ogt double %233, 0.000000e+00
%235 = select i1 %231, i1 %234, i1 false
%236 = trunc i64 %230 to i32
%237 = select i1 %235, i32 %236, i32 %226
%238 = fcmp ogt double %233, 0.000000e+00
%239 = trunc i64 %230 to i32
%240 = select i1 %238, i32 %239, i32 %229
%241 = add nuw nsw i64 %216, 2
%242 = add i64 %219, 2
%243 = icmp eq i64 %242, %166
br i1 %243, label %189, label %215
244: ; preds = %211, %244
%245 = phi double [ %251, %244 ], [ -1.000000e+00, %211 ]
%246 = phi i32 [ %252, %244 ], [ %213, %211 ]
%247 = phi i32 [ %250, %244 ], [ -1, %211 ]
%248 = tail call double @_p3dOtsuThresholding_nu(double* %18, i32 %246, double %136, double %214)
%249 = fcmp ult double %248, %245
%250 = select i1 %249, i32 %247, i32 %246
%251 = select i1 %249, double %245, double %248
%252 = add i32 %246, 1
%253 = icmp eq i32 %246, %212
br i1 %253, label %254, label %244
254: ; preds = %244
%255 = trunc i32 %250 to i16
br label %256
256: ; preds = %254, %207
%257 = phi i16 [ -1, %207 ], [ %255, %254 ]
store i16 %257, i16* %5
br i1 %23, label %258, label %359
258: ; preds = %256
%259 = zext i32 %22 to i64
%260 = load i16, i16* %0
%261 = icmp ugt i16 %260, %257
%262 = load i8, i8* @UCHAR_MAX
%263 = select i1 %261, i8 %262, i8 0
store i8 %263, i8* %1
%264 = icmp eq i32 %22, 1
br i1 %264, label %359, label %265
265: ; preds = %258
%266 = add nsw i64 %259, -1
%267 = icmp ult i64 %266, 16
br i1 %267, label %322, label %268
268: ; preds = %265
%269 = getelementptr i8, i8* %1, i64 1
%270 = getelementptr i8, i8* %1, i64 %259
%271 = getelementptr i16, i16* %5, i64 1
%272 = bitcast i16* %271 to i8*
%273 = getelementptr i16, i16* %0, i64 1
%274 = bitcast i16* %273 to i8*
%275 = getelementptr i16, i16* %0, i64 %259
%276 = bitcast i16* %275 to i8*
%277 = icmp ult i8* %269, %272
%278 = icmp ugt i8* %270, %9
%279 = and i1 %277, %278
%280 = icmp ult i8* %269, %276
%281 = icmp ugt i8* %270, %274
%282 = and i1 %280, %281
%283 = or i1 %279, %282
%284 = icmp ult i8* %1, @UCHAR_MAX
%285 = icmp ugt i8* %270, @UCHAR_MAX
%286 = and i1 %284, %285
%287 = or i1 %283, %286
br i1 %287, label %322, label %288
288: ; preds = %268
%289 = and i64 %266, -16
%290 = or i64 %289, 1
%291 = load i16, i16* %5
%292 = insertelement <8 x i16> poison, i16 %291, i64 0
%293 = shufflevector <8 x i16> %292, <8 x i16> poison, <8 x i32> zeroinitializer
%294 = insertelement <8 x i16> poison, i16 %291, i64 0
%295 = shufflevector <8 x i16> %294, <8 x i16> poison, <8 x i32> zeroinitializer
%296 = load i8, i8* @UCHAR_MAX
%297 = insertelement <8 x i8> poison, i8 %296, i64 0
%298 = shufflevector <8 x i8> %297, <8 x i8> poison, <8 x i32> zeroinitializer
%299 = insertelement <8 x i8> poison, i8 %296, i64 0
%300 = shufflevector <8 x i8> %299, <8 x i8> poison, <8 x i32> zeroinitializer
br label %301
301: ; preds = %301, %288
%302 = phi i64 [ 0, %288 ], [ %318, %301 ]
%303 = or i64 %302, 1
%304 = getelementptr inbounds i16, i16* %0, i64 %303
%305 = bitcast i16* %304 to <8 x i16>*
%306 = load <8 x i16>, <8 x i16>* %305
%307 = getelementptr inbounds i16, i16* %304, i64 8
%308 = bitcast i16* %307 to <8 x i16>*
%309 = load <8 x i16>, <8 x i16>* %308
%310 = icmp ugt <8 x i16> %306, %293
%311 = icmp ugt <8 x i16> %309, %295
%312 = select <8 x i1> %310, <8 x i8> %298, <8 x i8> zeroinitializer
%313 = select <8 x i1> %311, <8 x i8> %300, <8 x i8> zeroinitializer
%314 = getelementptr inbounds i8, i8* %1, i64 %303
%315 = bitcast i8* %314 to <8 x i8>*
store <8 x i8> %312, <8 x i8>* %315
%316 = getelementptr inbounds i8, i8* %314, i64 8
%317 = bitcast i8* %316 to <8 x i8>*
store <8 x i8> %313, <8 x i8>* %317
%318 = add nuw i64 %302, 16
%319 = icmp eq i64 %318, %289
br i1 %319, label %320, label %301
320: ; preds = %301
%321 = icmp eq i64 %266, %289
br i1 %321, label %359, label %322
322: ; preds = %268, %265, %320
%323 = phi i64 [ 1, %268 ], [ 1, %265 ], [ %290, %320 ]
%324 = xor i64 %323, -1
%325 = and i64 %259, 1
%326 = icmp eq i64 %325, 0
br i1 %326, label %327, label %336
327: ; preds = %322
%328 = load i16, i16* %5
%329 = getelementptr inbounds i16, i16* %0, i64 %323
%330 = load i16, i16* %329
%331 = icmp ugt i16 %330, %328
%332 = load i8, i8* @UCHAR_MAX
%333 = select i1 %331, i8 %332, i8 0
%334 = getelementptr inbounds i8, i8* %1, i64 %323
store i8 %333, i8* %334
%335 = add nuw nsw i64 %323, 1
br label %336
336: ; preds = %327, %322
%337 = phi i64 [ %323, %322 ], [ %335, %327 ]
%338 = sub nsw i64 0, %259
%339 = icmp eq i64 %324, %338
br i1 %339, label %359, label %340
340: ; preds = %336, %340
%341 = phi i64 [ %357, %340 ], [ %337, %336 ]
%342 = load i16, i16* %5
%343 = getelementptr inbounds i16, i16* %0, i64 %341
%344 = load i16, i16* %343
%345 = icmp ugt i16 %344, %342
%346 = load i8, i8* @UCHAR_MAX
%347 = select i1 %345, i8 %346, i8 0
%348 = getelementptr inbounds i8, i8* %1, i64 %341
store i8 %347, i8* %348
%349 = add nuw nsw i64 %341, 1
%350 = load i16, i16* %5
%351 = getelementptr inbounds i16, i16* %0, i64 %349
%352 = load i16, i16* %351
%353 = icmp ugt i16 %352, %350
%354 = load i8, i8* @UCHAR_MAX
%355 = select i1 %353, i8 %354, i8 0
%356 = getelementptr inbounds i8, i8* %1, i64 %349
store i8 %355, i8* %356
%357 = add nuw nsw i64 %341, 2
%358 = icmp eq i64 %357, %259
br i1 %358, label %359, label %340
359: ; preds = %336, %340, %258, %320, %256
br i1 %10, label %367, label %360
360: ; preds = %359
%361 = load i16, i16* %5
%362 = zext i16 %361 to i32
%363 = tail call i32 (i8*, ...) %6(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %362)
%364 = tail call i32 (...) @p3dGetElapsedTime_min()
%365 = tail call i32 (...) @p3dGetElapsedTime_sec()
%366 = tail call i32 (i8*, ...) %6(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %364, i32 %365)
br label %367
367: ; preds = %359, %360
%368 = tail call i32 @free(double* %18)
br label %372
369: ; preds = %14
br i1 %10, label %372, label %370
370: ; preds = %369
%371 = tail call i32 (i8*, ...) %6(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %372
372: ; preds = %370, %369, %367
%373 = phi i32 [ 2, %367 ], [ 0, %369 ], [ 0, %370 ]
ret i32 %373
}