#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;
scalar_t__ _p3dKapurThresholding_entropy(double *, int, double);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ p3dGetElapsedTime_min();
int /*<<< orphan*/ p3dGetElapsedTime_sec();
int /*<<< orphan*/ p3dResetStartTime();
int p3dKapurThresholding_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;
  double *Pt, *F;
  double Hb, Hw;
  int i, j, ct, t;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Thresholding image according to Kapur's method...");
  }
  if (((Pt = (double *)malloc(sizeof(double) * (UCHAR_MAX + 1))) == NULL)) {
    goto MEM_ERROR;
  };
  if (((F = (double *)malloc(sizeof(double) * (UCHAR_MAX + 1))) == NULL)) {
    goto MEM_ERROR;
  };
  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);
  Pt[0] = prob[0];
  for (i = 1; i <= UCHAR_MAX; i++)
    Pt[i] = Pt[i - 1] + prob[i];
  t = 0;
  for (i = 0; i <= UCHAR_MAX; i++) {
    Hb = Hw = 0.0;
    for (j = 0; j <= UCHAR_MAX; j++)
      if (j <= i)
        Hb += _p3dKapurThresholding_entropy(prob, j, Pt[i]);
      else
        Hw += _p3dKapurThresholding_entropy(prob, j, 1.0 - Pt[i]);
    F[i] = Hb + Hw;
    if (i > 0 && F[i] > F[t])
      t = i;
  }
  *thresh = (unsigned char)t;
#pragma omp parallel for
  for (ct = 0; ct < (dimx * dimy * dimz); ct++)
    out_im[ct] = (in_im[ct] > (*thresh)) ? UCHAR_MAX : 0;
  if (prob != NULL)
    free(prob);
  if (Pt != NULL)
    free(Pt);
  if (F != NULL)
    free(F);
  if (wr_log != NULL) {
    wr_log("\tDetermined threshold: %d.", *thresh);
    wr_log("Pore3D - Image thresholded successfully in %dm%0.3fs.",
           p3dGetElapsedTime_min(), p3dGetElapsedTime_sec());
  }
  return 2;
MEM_ERROR:
  if (wr_log != NULL) {
    wr_log("Pore3D - Not enough (contiguous) memory. Program will exit.");
  }
  if (prob != NULL)
    free(prob);
  if (Pt != NULL)
    free(Pt);
  if (F != NULL)
    free(F);
  return 0;
}


x86 assembly (clang, -O0):
<p3dKapurThresholding_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 <p3dKapurThresholding_8+0x47>
mov    $0x0,%al
call   1070 <p3dResetStartTime@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11e3 <p3dKapurThresholding_8+0x73>
jmp    157d <p3dKapurThresholding_8+0x40d>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    120f <p3dKapurThresholding_8+0x9f>
jmp    157d <p3dKapurThresholding_8+0x40d>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1238 <p3dKapurThresholding_8+0xc8>
jmp    157d <p3dKapurThresholding_8+0x40d>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1295 <p3dKapurThresholding_8+0x125>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x64(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
movsd  0xd93(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x64(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    123f <p3dKapurThresholding_8+0xcf>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2d4a(%rip),%rcx
cmp    (%rcx),%eax
jg     12e9 <p3dKapurThresholding_8+0x179>
mov    -0x38(%rbp),%rax
movslq -0x64(%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 -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    129c <p3dKapurThresholding_8+0x12c>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%eax
jg     134c <p3dKapurThresholding_8+0x1dc>
mov    -0x40(%rbp),%rax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x5c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1300 <p3dKapurThresholding_8+0x190>
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2c8c(%rip),%rcx
cmp    (%rcx),%eax
jg     146b <p3dKapurThresholding_8+0x2fb>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    0x2c63(%rip),%rcx
cmp    (%rcx),%eax
jg     1411 <p3dKapurThresholding_8+0x2a1>
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     13ce <p3dKapurThresholding_8+0x25e>
mov    -0x38(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1080 <_p3dKapurThresholding_entropy@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    13fe <p3dKapurThresholding_8+0x28e>
mov    -0x38(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    -0x40(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  0xc1b(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
call   1080 <_p3dKapurThresholding_entropy@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1403 <p3dKapurThresholding_8+0x293>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1383 <p3dKapurThresholding_8+0x213>
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cmpl   $0x0,-0x5c(%rbp)
jle    1458 <p3dKapurThresholding_8+0x2e8>
mov    -0x48(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x68(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1458 <p3dKapurThresholding_8+0x2e8>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    145d <p3dKapurThresholding_8+0x2ed>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    135a <p3dKapurThresholding_8+0x1ea>
mov    -0x68(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    14e7 <p3dKapurThresholding_8+0x377>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x30(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jle    14bf <p3dKapurThresholding_8+0x34f>
mov    0x2b3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
jmp    14c9 <p3dKapurThresholding_8+0x359>
xor    %eax,%eax
mov    %eax,-0x6c(%rbp)
jmp    14c9 <p3dKapurThresholding_8+0x359>
mov    -0x6c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    147d <p3dKapurThresholding_8+0x30d>
cmpq   $0x0,-0x38(%rbp)
je     14fb <p3dKapurThresholding_8+0x38b>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     150f <p3dKapurThresholding_8+0x39f>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     1523 <p3dKapurThresholding_8+0x3b3>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x10(%rbp)
je     1571 <p3dKapurThresholding_8+0x401>
mov    0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
movzbl (%rax),%esi
lea    0xb03(%rip),%rdi
mov    $0x0,%al
call   *%rcx
mov    0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1060 <p3dGetElapsedTime_min@plt>
mov    %eax,-0x7c(%rbp)
mov    $0x0,%al
call   1040 <p3dGetElapsedTime_sec@plt>
mov    -0x7c(%rbp),%esi
mov    -0x78(%rbp),%rcx
mov    %eax,%edx
lea    0xaf1(%rip),%rdi
mov    $0x0,%al
call   *%rcx
movl   $0x2,-0x4(%rbp)
jmp    15d7 <p3dKapurThresholding_8+0x467>
cmpq   $0x0,0x10(%rbp)
je     1594 <p3dKapurThresholding_8+0x424>
lea    0xb05(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     15a8 <p3dKapurThresholding_8+0x438>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     15bc <p3dKapurThresholding_8+0x44c>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     15d0 <p3dKapurThresholding_8+0x460>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dKapurThresholding_8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x8(%rsp)
mov    %r8d,%ebx
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %rsi,0x28(%rsp)
mov    %rdi,0x18(%rsp)
mov    0x80(%rsp),%rbp
test   %rbp,%rbp
je     11b5 <p3dKapurThresholding_8+0x45>
xor    %eax,%eax
call   1070 <p3dResetStartTime@plt>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   *%rbp
mov    0x2e34(%rip),%r14
mov    (%r14),%eax
lea    0x8(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     123c <p3dKapurThresholding_8+0xcc>
mov    (%r14),%eax
lea    0x8(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     1271 <p3dKapurThresholding_8+0x101>
mov    (%r14),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     127a <p3dKapurThresholding_8+0x10a>
mov    %rax,%rbp
imul   %r12d,%r13d
imul   %ebx,%r13d
mov    %r13d,%ebx
mov    %r13d,0x14(%rsp)
test   %r13d,%r13d
mov    0x18(%rsp),%rdi
jle    132d <p3dKapurThresholding_8+0x1bd>
lea    -0x1(%rbx),%rcx
mov    %ebx,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    128e <p3dKapurThresholding_8+0x11e>
xor    %ecx,%ecx
jmp    12fc <p3dKapurThresholding_8+0x18c>
test   %rbp,%rbp
je     124c <p3dKapurThresholding_8+0xdc>
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   *%rbp
test   %r15,%r15
je     1259 <p3dKapurThresholding_8+0xe9>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     1776 <p3dKapurThresholding_8+0x606>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1776 <p3dKapurThresholding_8+0x606>
xor    %ebx,%ebx
test   %rbp,%rbp
jne    1241 <p3dKapurThresholding_8+0xd1>
jmp    124c <p3dKapurThresholding_8+0xdc>
mov    0x20(%rsp),%rbx
mov    0x80(%rsp),%rbp
test   %rbp,%rbp
jne    1241 <p3dKapurThresholding_8+0xd1>
jmp    124c <p3dKapurThresholding_8+0xdc>
mov    %ebx,%edx
and    $0xfffffffc,%edx
xor    %ecx,%ecx
movsd  0xd63(%rip),%xmm0
nopl   (%rax)
movzbl (%rdi,%rcx,1),%esi
movsd  0x0(%rbp,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rsi,8)
movzbl 0x1(%rdi,%rcx,1),%esi
movsd  0x0(%rbp,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rsi,8)
movzbl 0x2(%rdi,%rcx,1),%esi
movsd  0x0(%rbp,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rsi,8)
movzbl 0x3(%rdi,%rcx,1),%esi
movsd  0x0(%rbp,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    12a0 <p3dKapurThresholding_8+0x130>
test   %rax,%rax
je     132d <p3dKapurThresholding_8+0x1bd>
add    %rdi,%rcx
xor    %edx,%edx
movsd  0xcf2(%rip),%xmm0
xchg   %ax,%ax
movzbl (%rcx,%rdx,1),%esi
movsd  0x0(%rbp,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rsi,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1310 <p3dKapurThresholding_8+0x1a0>
mov    (%r14),%eax
test   %eax,%eax
mov    %rbx,0x30(%rsp)
js     13cb <p3dKapurThresholding_8+0x25b>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
lea    0x1(%rax),%rcx
test   %eax,%eax
je     13da <p3dKapurThresholding_8+0x26a>
mov    %ecx,%edx
and    $0xfffffffe,%edx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rdx),%rsi
mov    %rsi,%rbx
shr    %rbx
add    $0x1,%rbx
test   %rsi,%rsi
je     1787 <p3dKapurThresholding_8+0x617>
mov    %rbx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edi,%edi
nop
movupd 0x0(%rbp,%rdi,8),%xmm2
movupd 0x10(%rbp,%rdi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,0x0(%rbp,%rdi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbp,%rdi,8)
add    $0x4,%rdi
add    $0xfffffffffffffffe,%rsi
jne    1380 <p3dKapurThresholding_8+0x210>
test   $0x1,%bl
je     13bf <p3dKapurThresholding_8+0x24f>
movupd 0x0(%rbp,%rdi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,0x0(%rbp,%rdi,8)
cmp    %rcx,%rdx
mov    0x20(%rsp),%rbx
jne    13f0 <p3dKapurThresholding_8+0x280>
jmp    1409 <p3dKapurThresholding_8+0x299>
movsd  0x0(%rbp),%xmm0
movsd  %xmm0,(%r15)
jmp    15b0 <p3dKapurThresholding_8+0x440>
xor    %edx,%edx
mov    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rdx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    13f0 <p3dKapurThresholding_8+0x280>
movsd  0x0(%rbp),%xmm0
movsd  %xmm0,(%r15)
test   %eax,%eax
jle    14b3 <p3dKapurThresholding_8+0x343>
lea    -0x1(%rcx),%rdi
add    $0xfffffffffffffffe,%rcx
mov    %edi,%edx
and    $0x3,%edx
mov    $0x1,%esi
cmp    $0x3,%rcx
jb     1481 <p3dKapurThresholding_8+0x311>
and    $0xfffffffffffffffc,%rdi
xor    %esi,%esi
nopl   0x0(%rax)
addsd  0x8(%rbp,%rsi,8),%xmm0
movsd  %xmm0,0x8(%r15,%rsi,8)
addsd  0x10(%rbp,%rsi,8),%xmm0
movsd  %xmm0,0x10(%r15,%rsi,8)
addsd  0x18(%rbp,%rsi,8),%xmm0
movsd  %xmm0,0x18(%r15,%rsi,8)
addsd  0x20(%rbp,%rsi,8),%xmm0
movsd  %xmm0,0x20(%r15,%rsi,8)
add    $0x4,%rsi
cmp    %rsi,%rdi
jne    1440 <p3dKapurThresholding_8+0x2d0>
add    $0x1,%rsi
test   %rdx,%rdx
je     14b3 <p3dKapurThresholding_8+0x343>
lea    (%r15,%rsi,8),%rcx
lea    0x0(,%rsi,8),%rsi
add    %rbp,%rsi
xor    %edi,%edi
nopw   0x0(%rax,%rax,1)
addsd  (%rsi,%rdi,8),%xmm0
movsd  %xmm0,(%rcx,%rdi,8)
add    $0x1,%rdi
cmp    %rdi,%rdx
jne    14a0 <p3dKapurThresholding_8+0x330>
test   %eax,%eax
js     15b0 <p3dKapurThresholding_8+0x440>
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    14e3 <p3dKapurThresholding_8+0x373>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r13),%rcx
movslq %eax,%rdx
cmp    %rdx,%r13
mov    %rcx,%r13
jge    15b3 <p3dKapurThresholding_8+0x443>
xorpd  %xmm0,%xmm0
test   %eax,%eax
js     158b <p3dKapurThresholding_8+0x41b>
movsd  %xmm0,0x38(%rsp)
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
jmp    1546 <p3dKapurThresholding_8+0x3d6>
nopl   (%rax)
movsd  0xaf8(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    %rbp,%rdi
mov    %ebx,%esi
movapd %xmm1,%xmm0
call   1080 <_p3dKapurThresholding_entropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x38(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
movsd  0x40(%rsp),%xmm0
mov    (%r14),%eax
add    $0x1,%rbx
lea    -0x1(%rbx),%ecx
cmp    %eax,%ecx
jge    1580 <p3dKapurThresholding_8+0x410>
movsd  %xmm0,0x40(%rsp)
movsd  (%r15,%r13,8),%xmm0
cmp    %rbx,%r13
jb     1500 <p3dKapurThresholding_8+0x390>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1080 <_p3dKapurThresholding_entropy@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x40(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    1538 <p3dKapurThresholding_8+0x3c8>
nopl   0x0(%rax)
addsd  0x38(%rsp),%xmm0
mov    0x20(%rsp),%rbx
movsd  %xmm0,(%rbx,%r13,8)
test   %r13,%r13
je     14d0 <p3dKapurThresholding_8+0x360>
movslq %r12d,%rcx
ucomisd (%rbx,%rcx,8),%xmm0
jbe    14d0 <p3dKapurThresholding_8+0x360>
mov    %r13d,%r12d
jmp    14d0 <p3dKapurThresholding_8+0x360>
xor    %r12d,%r12d
mov    0x8(%rsp),%rax
mov    %r12b,(%rax)
cmpl   $0x0,0x14(%rsp)
mov    0x80(%rsp),%r13
mov    0x28(%rsp),%rbx
jle    171e <p3dKapurThresholding_8+0x5ae>
xor    %eax,%eax
mov    0x18(%rsp),%rcx
cmp    %r12b,(%rcx)
jbe    15e2 <p3dKapurThresholding_8+0x472>
mov    (%r14),%eax
mov    %al,(%rbx)
cmpl   $0x1,0x14(%rsp)
je     171e <p3dKapurThresholding_8+0x5ae>
mov    0x30(%rsp),%rsi
lea    -0x1(%rsi),%r8
mov    $0x1,%eax
cmp    $0x8,%r8
jb     16e6 <p3dKapurThresholding_8+0x576>
lea    0x1(%rbx),%r12
lea    (%rbx,%rsi,1),%rdi
mov    0x18(%rsp),%rcx
lea    0x1(%rcx),%r11
mov    0x8(%rsp),%rdx
cmp    %rdx,%rbx
setb   %r9b
cmp    %rdx,%rdi
seta   %r10b
lea    (%rcx,%rsi,1),%rdx
cmp    %rdx,%r12
setb   %dl
cmp    %rdi,%r11
setb   %cl
lea    0x4(%r14),%rbx
cmp    %rbx,%r12
setb   %bl
cmp    %r14,%rdi
seta   %sil
test   %r10b,%r9b
jne    16e6 <p3dKapurThresholding_8+0x576>
and    %cl,%dl
jne    16e6 <p3dKapurThresholding_8+0x576>
and    %sil,%bl
mov    0x28(%rsp),%rdi
jne    16e6 <p3dKapurThresholding_8+0x576>
mov    %r8,%rdx
and    $0xfffffffffffffff8,%rdx
lea    0x1(%rdx),%rax
mov    0x8(%rsp),%rcx
movzbl (%rcx),%ecx
movd   %ecx,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
movd   (%r14),%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %esi,%esi
mov    0x18(%rsp),%rcx
nopl   0x0(%rax)
movd   0x1(%rcx,%rsi,1),%xmm2
movd   0x5(%rcx,%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(%rdi,%rsi,1)
movd   %xmm2,0x5(%rdi,%rsi,1)
add    $0x8,%rsi
cmp    %rsi,%rdx
jne    16a0 <p3dKapurThresholding_8+0x530>
cmp    %rdx,%r8
je     171e <p3dKapurThresholding_8+0x5ae>
mov    %rax,%rcx
not    %rcx
mov    0x30(%rsp),%rdi
test   $0x1,%dil
jne    1719 <p3dKapurThresholding_8+0x5a9>
mov    0x18(%rsp),%rdx
mov    (%rdx,%rax,1),%bl
xor    %edx,%edx
mov    0x8(%rsp),%rsi
cmp    (%rsi),%bl
jbe    170d <p3dKapurThresholding_8+0x59d>
mov    (%r14),%edx
mov    0x28(%rsp),%rsi
mov    %dl,(%rsi,%rax,1)
add    $0x1,%rax
add    %rdi,%rcx
jne    1797 <p3dKapurThresholding_8+0x627>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    $0x2,%ebp
test   %r13,%r13
je     1776 <p3dKapurThresholding_8+0x606>
mov    0x8(%rsp),%rax
movzbl (%rax),%esi
lea    0x8f2(%rip),%rdi
xor    %eax,%eax
call   *%r13
xor    %eax,%eax
call   1060 <p3dGetElapsedTime_min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <p3dGetElapsedTime_sec@plt>
lea    0x8f1(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%r13
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
test   $0x1,%bl
jne    13af <p3dKapurThresholding_8+0x23f>
jmp    13bf <p3dKapurThresholding_8+0x24f>
mov    0x28(%rsp),%rdi
jmp    17b2 <p3dKapurThresholding_8+0x642>
xchg   %ax,%ax
mov    %r8b,0x1(%rdi,%rax,1)
add    $0x2,%rax
cmp    %rax,%rcx
je     171e <p3dKapurThresholding_8+0x5ae>
mov    0x18(%rsp),%rcx
movzbl (%rcx,%rax,1),%ebx
xor    %r8d,%r8d
mov    $0x0,%edx
mov    0x8(%rsp),%rsi
cmp    (%rsi),%bl
jbe    17cf <p3dKapurThresholding_8+0x65f>
mov    (%r14),%edx
mov    %dl,(%rdi,%rax,1)
movzbl 0x1(%rcx,%rax,1),%edx
mov    0x8(%rsp),%rsi
cmp    (%rsi),%dl
mov    0x30(%rsp),%rcx
jbe    17a0 <p3dKapurThresholding_8+0x630>
mov    (%r14),%r8d
jmp    17a0 <p3dKapurThresholding_8+0x630>

LLVM IR (-O0):
@.str = [59 x i8] c"Pore3D - Thresholding image according to Kapur'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 @p3dKapurThresholding_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 double*
%20 = alloca double*
%21 = alloca double
%22 = alloca double
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = 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
%27 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%28 = icmp ne i32 (i8*, ...)* %27, null
br i1 %28, label %29, label %33
29: ; preds = %8
%30 = call i32 (...) @p3dResetStartTime()
%31 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%32 = call i32 (i8*, ...) %31(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %29, %8
%34 = load i32, i32* @UCHAR_MAX
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 8, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to double*
store double* %40, double** %19
%41 = icmp eq double* %40, null
br i1 %41, label %42, label %43
42: ; preds = %33
br label %285
43: ; preds = %33
%44 = load i32, i32* @UCHAR_MAX
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = mul i64 8, %46
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to double*
store double* %50, double** %20
%51 = icmp eq double* %50, null
br i1 %51, label %52, label %53
52: ; preds = %43
br label %285
53: ; preds = %43
%54 = load i32, i32* @UCHAR_MAX
%55 = add nsw i32 %54, 1
%56 = call i64 @calloc(i32 %55, i32 8)
%57 = inttoptr i64 %56 to double*
store double* %57, double** %18
%58 = icmp eq double* %57, null
br i1 %58, label %59, label %60
59: ; preds = %53
br label %285
60: ; preds = %53
store i32 0, i32* %25
br label %61
61: ; preds = %88, %60
%62 = load i32, i32* %25
%63 = load i32, i32* %12
%64 = load i32, i32* %13
%65 = mul nsw i32 %63, %64
%66 = load i32, i32* %14
%67 = mul nsw i32 %65, %66
%68 = icmp slt i32 %62, %67
br i1 %68, label %69, label %91
69: ; preds = %61
%70 = load double*, double** %18
%71 = load i8*, i8** %10
%72 = load i32, i32* %25
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i64
%77 = getelementptr inbounds double, double* %70, i64 %76
%78 = load double, double* %77
%79 = fadd double %78, 1.000000e+00
%80 = load double*, double** %18
%81 = load i8*, i8** %10
%82 = load i32, i32* %25
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i8, i8* %84
%86 = zext i8 %85 to i64
%87 = getelementptr inbounds double, double* %80, i64 %86
store double %79, double* %87
br label %88
88: ; preds = %69
%89 = load i32, i32* %25
%90 = add nsw i32 %89, 1
store i32 %90, i32* %25
br label %61
91: ; preds = %61
store i32 0, i32* %25
br label %92
92: ; preds = %113, %91
%93 = load i32, i32* %25
%94 = load i32, i32* @UCHAR_MAX
%95 = icmp sle i32 %93, %94
br i1 %95, label %96, label %116
96: ; preds = %92
%97 = load double*, double** %18
%98 = load i32, i32* %25
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %97, i64 %99
%101 = load double, double* %100
%102 = load i32, i32* %12
%103 = load i32, i32* %13
%104 = mul nsw i32 %102, %103
%105 = load i32, i32* %14
%106 = mul nsw i32 %104, %105
%107 = sitofp i32 %106 to double
%108 = fdiv double %101, %107
%109 = load double*, double** %18
%110 = load i32, i32* %25
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
store double %108, double* %112
br label %113
113: ; preds = %96
%114 = load i32, i32* %25
%115 = add nsw i32 %114, 1
store i32 %115, i32* %25
br label %92
116: ; preds = %92
%117 = load double*, double** %18
%118 = getelementptr inbounds double, double* %117, i64 0
%119 = load double, double* %118
%120 = load double*, double** %19
%121 = getelementptr inbounds double, double* %120, i64 0
store double %119, double* %121
store i32 1, i32* %23
br label %122
122: ; preds = %143, %116
%123 = load i32, i32* %23
%124 = load i32, i32* @UCHAR_MAX
%125 = icmp sle i32 %123, %124
br i1 %125, label %126, label %146
126: ; preds = %122
%127 = load double*, double** %19
%128 = load i32, i32* %23
%129 = sub nsw i32 %128, 1
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds double, double* %127, i64 %130
%132 = load double, double* %131
%133 = load double*, double** %18
%134 = load i32, i32* %23
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds double, double* %133, i64 %135
%137 = load double, double* %136
%138 = fadd double %132, %137
%139 = load double*, double** %19
%140 = load i32, i32* %23
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %139, i64 %141
store double %138, double* %142
br label %143
143: ; preds = %126
%144 = load i32, i32* %23
%145 = add nsw i32 %144, 1
store i32 %145, i32* %23
br label %122
146: ; preds = %122
store i32 0, i32* %26
store i32 0, i32* %23
br label %147
147: ; preds = %214, %146
%148 = load i32, i32* %23
%149 = load i32, i32* @UCHAR_MAX
%150 = icmp sle i32 %148, %149
br i1 %150, label %151, label %217
151: ; preds = %147
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %21
store i32 0, i32* %24
br label %152
152: ; preds = %186, %151
%153 = load i32, i32* %24
%154 = load i32, i32* @UCHAR_MAX
%155 = icmp sle i32 %153, %154
br i1 %155, label %156, label %189
156: ; preds = %152
%157 = load i32, i32* %24
%158 = load i32, i32* %23
%159 = icmp sle i32 %157, %158
br i1 %159, label %160, label %172
160: ; preds = %156
%161 = load double*, double** %18
%162 = load i32, i32* %24
%163 = load double*, double** %19
%164 = load i32, i32* %23
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds double, double* %163, i64 %165
%167 = load double, double* %166
%168 = call i64 @_p3dKapurThresholding_entropy(double* %161, i32 %162, double %167)
%169 = sitofp i64 %168 to double
%170 = load double, double* %21
%171 = fadd double %170, %169
store double %171, double* %21
br label %185
172: ; preds = %156
%173 = load double*, double** %18
%174 = load i32, i32* %24
%175 = load double*, double** %19
%176 = load i32, i32* %23
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds double, double* %175, i64 %177
%179 = load double, double* %178
%180 = fsub double 1.000000e+00, %179
%181 = call i64 @_p3dKapurThresholding_entropy(double* %173, i32 %174, double %180)
%182 = sitofp i64 %181 to double
%183 = load double, double* %22
%184 = fadd double %183, %182
store double %184, double* %22
br label %185
185: ; preds = %172, %160
br label %186
186: ; preds = %185
%187 = load i32, i32* %24
%188 = add nsw i32 %187, 1
store i32 %188, i32* %24
br label %152
189: ; preds = %152
%190 = load double, double* %21
%191 = load double, double* %22
%192 = fadd double %190, %191
%193 = load double*, double** %20
%194 = load i32, i32* %23
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds double, double* %193, i64 %195
store double %192, double* %196
%197 = load i32, i32* %23
%198 = icmp sgt i32 %197, 0
br i1 %198, label %199, label %213
199: ; preds = %189
%200 = load double*, double** %20
%201 = load i32, i32* %23
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds double, double* %200, i64 %202
%204 = load double, double* %203
%205 = load double*, double** %20
%206 = load i32, i32* %26
%207 = sext i32 %206 to i64
%208 = getelementptr inbounds double, double* %205, i64 %207
%209 = load double, double* %208
%210 = fcmp ogt double %204, %209
br i1 %210, label %211, label %213
211: ; preds = %199
%212 = load i32, i32* %23
store i32 %212, i32* %26
br label %213
213: ; preds = %211, %199, %189
br label %214
214: ; preds = %213
%215 = load i32, i32* %23
%216 = add nsw i32 %215, 1
store i32 %216, i32* %23
br label %147
217: ; preds = %147
%218 = load i32, i32* %26
%219 = trunc i32 %218 to i8
%220 = load i8*, i8** %15
store i8 %219, i8* %220
store i32 0, i32* %25
br label %221
221: ; preds = %250, %217
%222 = load i32, i32* %25
%223 = load i32, i32* %12
%224 = load i32, i32* %13
%225 = mul nsw i32 %223, %224
%226 = load i32, i32* %14
%227 = mul nsw i32 %225, %226
%228 = icmp slt i32 %222, %227
br i1 %228, label %229, label %253
229: ; preds = %221
%230 = load i8*, i8** %10
%231 = load i32, i32* %25
%232 = sext i32 %231 to i64
%233 = getelementptr inbounds i8, i8* %230, i64 %232
%234 = load i8, i8* %233
%235 = zext i8 %234 to i32
%236 = load i8*, i8** %15
%237 = load i8, i8* %236
%238 = zext i8 %237 to i32
%239 = icmp sgt i32 %235, %238
br i1 %239, label %240, label %242
240: ; preds = %229
%241 = load i32, i32* @UCHAR_MAX
br label %243
242: ; preds = %229
br label %243
243: ; preds = %242, %240
%244 = phi i32 [ %241, %240 ], [ 0, %242 ]
%245 = trunc i32 %244 to i8
%246 = load i8*, i8** %11
%247 = load i32, i32* %25
%248 = sext i32 %247 to i64
%249 = getelementptr inbounds i8, i8* %246, i64 %248
store i8 %245, i8* %249
br label %250
250: ; preds = %243
%251 = load i32, i32* %25
%252 = add nsw i32 %251, 1
store i32 %252, i32* %25
br label %221
253: ; preds = %221
%254 = load double*, double** %18
%255 = icmp ne double* %254, null
br i1 %255, label %256, label %259
256: ; preds = %253
%257 = load double*, double** %18
%258 = call i32 @free(double* %257)
br label %259
259: ; preds = %256, %253
%260 = load double*, double** %19
%261 = icmp ne double* %260, null
br i1 %261, label %262, label %265
262: ; preds = %259
%263 = load double*, double** %19
%264 = call i32 @free(double* %263)
br label %265
265: ; preds = %262, %259
%266 = load double*, double** %20
%267 = icmp ne double* %266, null
br i1 %267, label %268, label %271
268: ; preds = %265
%269 = load double*, double** %20
%270 = call i32 @free(double* %269)
br label %271
271: ; preds = %268, %265
%272 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%273 = icmp ne i32 (i8*, ...)* %272, null
br i1 %273, label %274, label %284
274: ; preds = %271
%275 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%276 = load i8*, i8** %15
%277 = load i8, i8* %276
%278 = zext i8 %277 to i32
%279 = call i32 (i8*, ...) %275(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %278)
%280 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%281 = call i32 (...) @p3dGetElapsedTime_min()
%282 = call i32 (...) @p3dGetElapsedTime_sec()
%283 = call i32 (i8*, ...) %280(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %281, i32 %282)
br label %284
284: ; preds = %274, %271
store i32 2, i32* %9
br label %310
285: ; preds = %59, %52, %42
%286 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%287 = icmp ne i32 (i8*, ...)* %286, null
br i1 %287, label %288, label %291
288: ; preds = %285
%289 = load i32 (i8*, ...)*, i32 (i8*, ...)** %16
%290 = call i32 (i8*, ...) %289(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %291
291: ; preds = %288, %285
%292 = load double*, double** %18
%293 = icmp ne double* %292, null
br i1 %293, label %294, label %297
294: ; preds = %291
%295 = load double*, double** %18
%296 = call i32 @free(double* %295)
br label %297
297: ; preds = %294, %291
%298 = load double*, double** %19
%299 = icmp ne double* %298, null
br i1 %299, label %300, label %303
300: ; preds = %297
%301 = load double*, double** %19
%302 = call i32 @free(double* %301)
br label %303
303: ; preds = %300, %297
%304 = load double*, double** %20
%305 = icmp ne double* %304, null
br i1 %305, label %306, label %309
306: ; preds = %303
%307 = load double*, double** %20
%308 = call i32 @free(double* %307)
br label %309
309: ; preds = %306, %303
store i32 0, i32* %9
br label %310
310: ; preds = %309, %284
%311 = load i32, i32* %9
ret i32 %311
}

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