#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 UCHAR_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_8(unsigned char *in_im, unsigned char *out_im,
                          const int dimx, const int dimy, const int dimz,
                          unsigned char *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((UCHAR_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 <= UCHAR_MAX; ct++)
    prob[ct] = prob[ct] / (double)(dimx * dimy * dimz);
  ut = _p3dOtsuThresholding_u(prob, UCHAR_MAX);
  vt = 0.0;
  for (i = 0; i <= UCHAR_MAX; i++)
    vt += (i - ut) * (i - ut) * prob[i];
  j = -1;
  k = -1;
  for (i = 0; i <= UCHAR_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 char)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_8>:
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_8+0x47>
mov    $0x0,%al
call   1090 <p3dResetStartTime@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
mov    0x2e32(%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_8+0x70>
jmp    14f0 <p3dOtsuThresholding_8+0x380>
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_8+0xcd>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x6c(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
movsd  0xdf3(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x6c(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11e7 <p3dOtsuThresholding_8+0x77>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%eax
jg     1291 <p3dOtsuThresholding_8+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_8+0xd4>
mov    -0x38(%rbp),%rdi
mov    0x2d54(%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    0x2d2f(%rip),%rcx
cmp    (%rcx),%eax
jg     130e <p3dOtsuThresholding_8+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_8+0x147>
movl   $0xffffffff,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2cc3(%rip),%rcx
cmp    (%rcx),%eax
jg     1392 <p3dOtsuThresholding_8+0x222>
cmpl   $0x0,-0x40(%rbp)
jge    135f <p3dOtsuThresholding_8+0x1ef>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    135f <p3dOtsuThresholding_8+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_8+0x20f>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1384 <p3dOtsuThresholding_8+0x214>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1323 <p3dOtsuThresholding_8+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_8+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_8+0x283>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    13f8 <p3dOtsuThresholding_8+0x288>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13ac <p3dOtsuThresholding_8+0x23c>
mov    -0x48(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%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    1482 <p3dOtsuThresholding_8+0x312>
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jle    145a <p3dOtsuThresholding_8+0x2ea>
mov    0x2ba0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
jmp    1464 <p3dOtsuThresholding_8+0x2f4>
xor    %eax,%eax
mov    %eax,-0x70(%rbp)
jmp    1464 <p3dOtsuThresholding_8+0x2f4>
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    1418 <p3dOtsuThresholding_8+0x2a8>
cmpq   $0x0,0x10(%rbp)
je     14d0 <p3dOtsuThresholding_8+0x360>
mov    0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
movzbl (%rax),%esi
lea    0xbab(%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    0xb99(%rip),%rdi
mov    $0x0,%al
call   *%rcx
cmpq   $0x0,-0x38(%rbp)
je     14e4 <p3dOtsuThresholding_8+0x374>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1522 <p3dOtsuThresholding_8+0x3b2>
cmpq   $0x0,0x10(%rbp)
je     1507 <p3dOtsuThresholding_8+0x397>
lea    0xb99(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     151b <p3dOtsuThresholding_8+0x3ab>
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_8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x18(%rsp)
mov    %r8d,%ebp
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x90(%rsp),%rbx
test   %rbx,%rbx
je     11b1 <p3dOtsuThresholding_8+0x41>
xor    %eax,%eax
call   1090 <p3dResetStartTime@plt>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   *%rbx
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1206 <p3dOtsuThresholding_8+0x96>
mov    %rax,%rbx
mov    %r13d,%eax
imul   %r14d,%eax
imul   %ebp,%eax
mov    %eax,%r13d
mov    %eax,0xc(%rsp)
test   %eax,%eax
mov    0x2e07(%rip),%r14
jle    12cb <p3dOtsuThresholding_8+0x15b>
lea    -0x1(%r13),%rcx
mov    %r13d,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    122a <p3dOtsuThresholding_8+0xba>
xor    %ecx,%ecx
jmp    1298 <p3dOtsuThresholding_8+0x128>
mov    0x90(%rsp),%r15
test   %r15,%r15
je     169f <p3dOtsuThresholding_8+0x52f>
lea    0xe7d(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   *%r15
jmp    1747 <p3dOtsuThresholding_8+0x5d7>
mov    %r13d,%edx
and    $0xfffffffc,%edx
xor    %ecx,%ecx
movsd  0xdc6(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rcx,1),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzbl 0x1(%r12,%rcx,1),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzbl 0x2(%r12,%rcx,1),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
movzbl 0x3(%r12,%rcx,1),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1240 <p3dOtsuThresholding_8+0xd0>
test   %rax,%rax
je     12cb <p3dOtsuThresholding_8+0x15b>
add    %r12,%rcx
xor    %edx,%edx
movsd  0xd56(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movzbl (%rcx,%rdx,1),%esi
movsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rsi,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    12b0 <p3dOtsuThresholding_8+0x140>
mov    (%r14),%esi
test   %esi,%esi
js     1387 <p3dOtsuThresholding_8+0x217>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
lea    0x1(%rsi),%rax
test   %rsi,%rsi
je     1363 <p3dOtsuThresholding_8+0x1f3>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rdx
mov    %rdx,%rbp
shr    %rbp
add    $0x1,%rbp
test   %rdx,%rdx
je     16a6 <p3dOtsuThresholding_8+0x536>
mov    %rbp,%rdx
and    $0xfffffffffffffffe,%rdx
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nop
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_8+0x1b0>
test   $0x1,%bpl
je     135c <p3dOtsuThresholding_8+0x1ec>
movupd (%rbx,%rdi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rdi,8)
cmp    %rax,%rcx
jne    1370 <p3dOtsuThresholding_8+0x200>
jmp    1387 <p3dOtsuThresholding_8+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_8+0x200>
mov    %rbx,%rdi
call   1040 <_p3dOtsuThresholding_u@plt>
movapd %xmm0,%xmm2
mov    (%r14),%ecx
mov    $0xffffffff,%r14d
test   %ecx,%ecx
mov    %r13,0x10(%rsp)
js     14b6 <p3dOtsuThresholding_8+0x346>
lea    0x1(%rcx),%rax
test   %rcx,%rcx
je     168c <p3dOtsuThresholding_8+0x51c>
mov    %eax,%esi
and    $0xfffffffe,%esi
xorpd  %xmm1,%xmm1
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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_8+0x260>
test   $0x1,%al
je     1429 <p3dOtsuThresholding_8+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     14ba <p3dOtsuThresholding_8+0x34a>
test   %rcx,%rcx
je     16b7 <p3dOtsuThresholding_8+0x547>
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_8+0x2e0>
test   $0x1,%al
je     14aa <p3dOtsuThresholding_8+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    $0xff,%al
cmp    %r13d,%ebp
jle    14c5 <p3dOtsuThresholding_8+0x355>
jmp    154e <p3dOtsuThresholding_8+0x3de>
xorpd  %xmm1,%xmm1
mov    $0xffffffff,%r13d
mov    $0xffffffff,%ebp
add    $0x1,%r13d
movsd  0xb37(%rip),%xmm0
movapd %xmm0,%xmm4
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm0,0x30(%rsp)
movapd %xmm4,0x40(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
movapd %xmm2,%xmm0
call   1060 <_p3dOtsuThresholding_nu@plt>
movapd 0x40(%rsp),%xmm4
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
movapd 0x30(%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_8+0x380>
mov    %r14d,%eax
mov    0x18(%rsp),%rbp
mov    %al,0x0(%rbp)
cmpl   $0x0,0xc(%rsp)
mov    0x90(%rsp),%r14
mov    0x2a86(%rip),%r13
mov    0x10(%rsp),%rdi
jle    1705 <p3dOtsuThresholding_8+0x595>
xor    %ecx,%ecx
cmp    %al,(%r12)
jbe    1581 <p3dOtsuThresholding_8+0x411>
mov    0x0(%r13),%ecx
mov    %cl,(%r15)
cmpl   $0x1,0xc(%rsp)
je     1705 <p3dOtsuThresholding_8+0x595>
lea    -0x1(%rdi),%r11
mov    $0x1,%eax
cmp    $0x8,%r11
jb     16dd <p3dOtsuThresholding_8+0x56d>
lea    0x1(%r15),%rcx
lea    (%r15,%rdi,1),%rsi
lea    0x1(%r12),%r8
cmp    %rbp,%r15
setb   %r9b
cmp    %rbp,%rsi
seta   %r10b
lea    (%r12,%rdi,1),%rdx
cmp    %rdx,%rcx
setb   %dl
cmp    %rsi,%r8
mov    %r13,%r8
setb   %r13b
lea    0x4(%r8),%rdi
cmp    %rdi,%rcx
setb   %cl
cmp    %r8,%rsi
seta   %r8b
test   %r10b,%r9b
jne    16d1 <p3dOtsuThresholding_8+0x561>
and    %r13b,%dl
jne    16d1 <p3dOtsuThresholding_8+0x561>
and    %r8b,%cl
mov    0x29f2(%rip),%r13
mov    0x10(%rsp),%rdi
jne    16dd <p3dOtsuThresholding_8+0x56d>
mov    %r11,%rdx
and    $0xfffffffffffffff8,%rdx
lea    0x1(%rdx),%rax
movzbl 0x0(%rbp),%ecx
movd   %ecx,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
movd   0x0(%r13),%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movd   0x1(%r12,%rsi,1),%xmm2
movd   0x5(%r12,%rsi,1),%xmm3
movdqa %xmm2,%xmm4
pminub %xmm0,%xmm4
pcmpeqb %xmm2,%xmm4
movdqa %xmm3,%xmm2
pminub %xmm0,%xmm2
pcmpeqb %xmm3,%xmm2
pandn  %xmm1,%xmm4
pandn  %xmm1,%xmm2
movd   %xmm4,0x1(%r15,%rsi,1)
movd   %xmm2,0x5(%r15,%rsi,1)
add    $0x8,%rsi
cmp    %rsi,%rdx
jne    1640 <p3dOtsuThresholding_8+0x4d0>
cmp    %rdx,%r11
jne    16dd <p3dOtsuThresholding_8+0x56d>
jmp    1705 <p3dOtsuThresholding_8+0x595>
xorpd  %xmm1,%xmm1
xor    %edx,%edx
test   $0x1,%al
jne    1411 <p3dOtsuThresholding_8+0x2a1>
jmp    1429 <p3dOtsuThresholding_8+0x2b9>
xor    %ebx,%ebx
jmp    1747 <p3dOtsuThresholding_8+0x5d7>
xor    %edi,%edi
test   $0x1,%bpl
jne    134e <p3dOtsuThresholding_8+0x1de>
jmp    135c <p3dOtsuThresholding_8+0x1ec>
mov    $0xffffffff,%r13d
xor    %ecx,%ecx
mov    $0xffffffff,%ebp
test   $0x1,%al
jne    148f <p3dOtsuThresholding_8+0x31f>
jmp    14aa <p3dOtsuThresholding_8+0x33a>
mov    0x2918(%rip),%r13
mov    0x10(%rsp),%rdi
mov    %rax,%rcx
not    %rcx
test   $0x1,%dil
jne    1700 <p3dOtsuThresholding_8+0x590>
mov    (%r12,%rax,1),%dl
xor    %esi,%esi
cmp    0x0(%rbp),%dl
jbe    16f8 <p3dOtsuThresholding_8+0x588>
mov    0x0(%r13),%esi
mov    %sil,(%r15,%rax,1)
add    $0x1,%rax
add    %rdi,%rcx
jne    176e <p3dOtsuThresholding_8+0x5fe>
test   %r14,%r14
je     173a <p3dOtsuThresholding_8+0x5ca>
movzbl 0x0(%rbp),%esi
lea    0x935(%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    0x934(%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
nopl   0x0(%rax,%rax,1)
mov    %sil,0x1(%r15,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdi
je     1705 <p3dOtsuThresholding_8+0x595>
movzbl (%r12,%rax,1),%ecx
xor    %esi,%esi
mov    $0x0,%edx
cmp    0x0(%rbp),%cl
jbe    1783 <p3dOtsuThresholding_8+0x613>
mov    0x0(%r13),%edx
mov    %dl,(%r15,%rax,1)
movzbl 0x1(%r12,%rax,1),%ecx
cmp    0x0(%rbp),%cl
jbe    1760 <p3dOtsuThresholding_8+0x5f0>
mov    0x0(%r13),%esi
jmp    1760 <p3dOtsuThresholding_8+0x5f0>

LLVM IR (-O0):
@.str = [58 x i8] c"Pore3D - Thresholding image according to Otsu's method...\00"
@UCHAR_MAX = global i32 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_8(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i8* %5, i32 (i8*, ...)* %6, i32 (i32, ...)* %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%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 i8* %0, i8** %10
store i8* %1, i8** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i8* %5, i8** %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* @UCHAR_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 %233
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 i8*, i8** %10
%53 = load i32, i32* %27
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %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 i8*, i8** %10
%63 = load i32, i32* %27
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %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* @UCHAR_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* @UCHAR_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* @UCHAR_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* @UCHAR_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 i8
%180 = load i8*, i8** %15
store i8 %179, i8* %180
store i32 0, i32* %27
br label %181
181: ; preds = %210, %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 %213
189: ; preds = %181
%190 = load i8*, i8** %10
%191 = load i32, i32* %27
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds i8, i8* %190, i64 %192
%194 = load i8, i8* %193
%195 = zext i8 %194 to i32
%196 = load i8*, i8** %15
%197 = load i8, i8* %196
%198 = zext i8 %197 to i32
%199 = icmp sgt i32 %195, %198
br i1 %199, label %200, label %202
200: ; preds = %189
%201 = load i32, i32* @UCHAR_MAX
br label %203
202: ; preds = %189
br label %203
203: ; preds = %202, %200
%204 = phi i32 [ %201, %200 ], [ 0, %202 ]
%205 = trunc i32 %204 to i8
%206 = load i8*, i8** %11
%207 = load i32, i32* %27
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i8, i8* %206, i64 %208
store i8 %205, i8* %209
br label %210
210: ; preds = %203
%211 = load i32, i32* %27
%212 = add nsw i32 %211, 1
store i32 %212, i32* %27
br label %181
213: ; preds = %181
%214 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%215 = icmp ne i32 (i8*, ...)* %214, null
br i1 %215, label %216, label %226
216: ; preds = %213
%217 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%218 = load i8*, i8** %15
%219 = load i8, i8* %218
%220 = zext i8 %219 to i32
%221 = call i32 (i8*, ...) %217(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %220)
%222 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%223 = call i32 (...) @p3dGetElapsedTime_min()
%224 = call i32 (...) @p3dGetElapsedTime_sec()
%225 = call i32 (i8*, ...) %222(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %223, i32 %224)
br label %226
226: ; preds = %216, %213
%227 = load double*, double** %18
%228 = icmp ne double* %227, null
br i1 %228, label %229, label %232
229: ; preds = %226
%230 = load double*, double** %18
%231 = call i32 @free(double* %230)
br label %232
232: ; preds = %229, %226
store i32 2, i32* %9
br label %246
233: ; preds = %40
%234 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%235 = icmp ne i32 (i8*, ...)* %234, null
br i1 %235, label %236, label %239
236: ; preds = %233
%237 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%238 = call i32 (i8*, ...) %237(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %239
239: ; preds = %236, %233
%240 = load double*, double** %18
%241 = icmp ne double* %240, null
br i1 %241, label %242, label %245
242: ; preds = %239
%243 = load double*, double** %18
%244 = call i32 @free(double* %243)
br label %245
245: ; preds = %242, %239
store i32 0, i32* %9
br label %246
246: ; preds = %245, %232
%247 = load i32, i32* %9
ret i32 %247
}

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