#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 _p3dJohannsenThresholding_dlog(double);
double _p3dJohannsenThresholding_entropy(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 p3dJohannsenThresholding_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 = NULL;
  double *Pt = NULL;
  double *F = NULL;
  double *Pq = NULL;
  int i, t, start, end;
  double Sb, Sw;
  int ct;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Thresholding image according to Johannsen's method...");
  }
  if (((prob = (double *)calloc((USHRT_MAX + 1), sizeof(double))) == NULL)) {
    goto MEM_ERROR;
  };
  if (((Pt = (double *)malloc(sizeof(double) * (USHRT_MAX + 1))) == NULL)) {
    goto MEM_ERROR;
  };
  if (((F = (double *)malloc(sizeof(double) * (USHRT_MAX + 1))) == NULL)) {
    goto MEM_ERROR;
  };
  if (((Pq = (double *)malloc(sizeof(double) * (USHRT_MAX + 1))) == 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);
  Pt[0] = prob[0];
  Pq[0] = 1.0 - Pt[0];
  for (i = 1; i <= USHRT_MAX; i++) {
    Pt[i] = Pt[i - 1] + prob[i];
    Pq[i] = 1.0 - Pt[i - 1];
  }
  start = 0;
  while (prob[start++] <= 0.0)
    ;
  end = USHRT_MAX;
  while (prob[end--] <= 0.0)
    ;
  t = -1;
  for (i = start; i <= end; i++) {
    if (prob[i] <= 0.0)
      continue;
    Sb = _p3dJohannsenThresholding_dlog(Pt[i]) +
         (1.0 / Pt[i]) * (_p3dJohannsenThresholding_entropy(prob[i]) +
                          _p3dJohannsenThresholding_entropy(Pt[i - 1]));
    Sw = _p3dJohannsenThresholding_dlog(Pq[i]) +
         (1.0 / Pq[i]) * (_p3dJohannsenThresholding_entropy(prob[i]) +
                          _p3dJohannsenThresholding_entropy(Pq[i + 1]));
    F[i] = Sb + Sw;
    if (t < 0)
      t = i;
    else if (F[i] < F[t])
      t = i;
  }
  *thresh = (unsigned short)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 (Pq != NULL)
    free(Pq);
  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);
  if (Pq != NULL)
    free(Pq);
  return 0;
}


x86 assembly (clang, -O0):
<p3dJohannsenThresholding_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%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)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,0x10(%rbp)
je     11e7 <p3dJohannsenThresholding_16+0x67>
mov    $0x0,%al
call   1080 <p3dResetStartTime@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1210 <p3dJohannsenThresholding_16+0x90>
jmp    1746 <p3dJohannsenThresholding_16+0x5c6>
mov    0x2dc9(%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    123c <p3dJohannsenThresholding_16+0xbc>
jmp    1746 <p3dJohannsenThresholding_16+0x5c6>
mov    0x2d9d(%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    1268 <p3dJohannsenThresholding_16+0xe8>
jmp    1746 <p3dJohannsenThresholding_16+0x5c6>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1294 <p3dJohannsenThresholding_16+0x114>
jmp    1746 <p3dJohannsenThresholding_16+0x5c6>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    12f1 <p3dJohannsenThresholding_16+0x171>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x74(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  0xd37(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x74(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    129b <p3dJohannsenThresholding_16+0x11b>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2cde(%rip),%rcx
cmp    (%rcx),%eax
jg     1345 <p3dJohannsenThresholding_16+0x1c5>
mov    -0x38(%rbp),%rax
movslq -0x74(%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 -0x74(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    12f8 <p3dJohannsenThresholding_16+0x178>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x40(%rbp),%rax
movsd  0xc9f(%rip),%xmm0
subsd  (%rax),%xmm0
mov    -0x50(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2c62(%rip),%rcx
cmp    (%rcx),%eax
jg     13e7 <p3dJohannsenThresholding_16+0x267>
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xc39(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1374 <p3dJohannsenThresholding_16+0x1f4>
movl   $0x0,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x5c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x5c(%rbp)
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     1413 <p3dJohannsenThresholding_16+0x293>
jmp    13ee <p3dJohannsenThresholding_16+0x26e>
mov    0x2bc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x60(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x60(%rbp)
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     1444 <p3dJohannsenThresholding_16+0x2c4>
jmp    141f <p3dJohannsenThresholding_16+0x29f>
movl   $0xffffffff,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x60(%rbp),%eax
jg     1608 <p3dJohannsenThresholding_16+0x488>
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     1478 <p3dJohannsenThresholding_16+0x2f8>
jmp    15fa <p3dJohannsenThresholding_16+0x47a>
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   10a0 <_p3dJohannsenThresholding_dlog@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  0xb5e(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  -0xa8(%rbp),%xmm2
ff
movsd  -0xa0(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0x98(%rbp),%xmm0
ff
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   10a0 <_p3dJohannsenThresholding_dlog@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  0xaca(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x50(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  -0x90(%rbp),%xmm2
ff
movsd  -0x88(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0x80(%rbp),%xmm0
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cmpl   $0x0,-0x58(%rbp)
jge    15c6 <p3dJohannsenThresholding_16+0x446>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    15f5 <p3dJohannsenThresholding_16+0x475>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    15f0 <p3dJohannsenThresholding_16+0x470>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    15f5 <p3dJohannsenThresholding_16+0x475>
jmp    15fa <p3dJohannsenThresholding_16+0x47a>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1451 <p3dJohannsenThresholding_16+0x2d1>
mov    -0x58(%rbp),%eax
mov    %ax,%cx
mov    -0x30(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1690 <p3dJohannsenThresholding_16+0x510>
mov    -0x10(%rbp),%rax
movslq -0x74(%rbp),%rcx
movzwl (%rax,%rcx,2),%eax
mov    -0x30(%rbp),%rcx
movzwl (%rcx),%ecx
cmp    %ecx,%eax
jle    1662 <p3dJohannsenThresholding_16+0x4e2>
mov    0x299c(%rip),%rax
movzbl (%rax),%eax
mov    %eax,-0xac(%rbp)
jmp    166f <p3dJohannsenThresholding_16+0x4ef>
xor    %eax,%eax
mov    %eax,-0xac(%rbp)
jmp    166f <p3dJohannsenThresholding_16+0x4ef>
mov    -0xac(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    161c <p3dJohannsenThresholding_16+0x49c>
cmpq   $0x0,-0x38(%rbp)
je     16a4 <p3dJohannsenThresholding_16+0x524>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     16b8 <p3dJohannsenThresholding_16+0x538>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     16cc <p3dJohannsenThresholding_16+0x54c>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x50(%rbp)
je     16e0 <p3dJohannsenThresholding_16+0x560>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,0x10(%rbp)
je     173a <p3dJohannsenThresholding_16+0x5ba>
mov    0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
movzwl (%rax),%esi
lea    0x94a(%rip),%rdi
mov    $0x0,%al
call   *%rcx
mov    0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    $0x0,%al
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,-0xbc(%rbp)
mov    $0x0,%al
call   1050 <p3dGetElapsedTime_sec@plt>
mov    -0xbc(%rbp),%esi
mov    -0xb8(%rbp),%rcx
mov    %eax,%edx
lea    0x92c(%rip),%rdi
mov    $0x0,%al
call   *%rcx
movl   $0x2,-0x4(%rbp)
jmp    17b4 <p3dJohannsenThresholding_16+0x634>
cmpq   $0x0,0x10(%rbp)
je     175d <p3dJohannsenThresholding_16+0x5dd>
lea    0x940(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1771 <p3dJohannsenThresholding_16+0x5f1>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1785 <p3dJohannsenThresholding_16+0x605>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     1799 <p3dJohannsenThresholding_16+0x619>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x50(%rbp)
je     17ad <p3dJohannsenThresholding_16+0x62d>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dJohannsenThresholding_16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x8(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,0x58(%rsp)
mov    %rdi,0x50(%rsp)
mov    0xa0(%rsp),%rbp
test   %rbp,%rbp
je     11c4 <p3dJohannsenThresholding_16+0x44>
xor    %eax,%eax
call   1080 <p3dResetStartTime@plt>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   *%rbp
mov    0x2e15(%rip),%rbp
mov    0x0(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     1271 <p3dJohannsenThresholding_16+0xf1>
mov    0x0(%rbp),%eax
lea    0x8(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1271 <p3dJohannsenThresholding_16+0xf1>
mov    0x0(%rbp),%eax
lea    0x8(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,0x28(%rsp)
test   %rax,%rax
je     12c7 <p3dJohannsenThresholding_16+0x147>
mov    0x0(%rbp),%eax
lea    0x8(,%rax,8),%edi
call   1090 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     12d8 <p3dJohannsenThresholding_16+0x158>
imul   %r14d,%ebx
imul   %r15d,%ebx
mov    %ebx,%r9d
test   %ebx,%ebx
mov    0x10(%rsp),%r8
mov    0x50(%rsp),%rdi
jle    139f <p3dJohannsenThresholding_16+0x21f>
lea    -0x1(%r9),%rcx
mov    %r9d,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    12ec <p3dJohannsenThresholding_16+0x16c>
xor    %ecx,%ecx
jmp    1364 <p3dJohannsenThresholding_16+0x1e4>
xor    %ebx,%ebx
xor    %ebp,%ebp
mov    0xa0(%rsp),%rcx
test   %rcx,%rcx
je     128d <p3dJohannsenThresholding_16+0x10d>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   *%rcx
test   %r13,%r13
je     129a <p3dJohannsenThresholding_16+0x11a>
mov    %r13,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     12a7 <p3dJohannsenThresholding_16+0x127>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
test   %rbp,%rbp
je     12b6 <p3dJohannsenThresholding_16+0x136>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    0xa0(%rsp),%rcx
mov    0x10(%rsp),%rbx
jmp    127d <p3dJohannsenThresholding_16+0xfd>
mov    0xa0(%rsp),%rcx
mov    0x10(%rsp),%rbx
mov    0x28(%rsp),%rbp
jmp    127d <p3dJohannsenThresholding_16+0xfd>
mov    %r9d,%edx
and    $0xfffffffc,%edx
xor    %ecx,%ecx
movsd  0xd04(%rip),%xmm0
nopl   0x0(%rax)
movzwl (%rdi,%rcx,2),%esi
movsd  0x0(%r13,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rsi,8)
movzwl 0x2(%rdi,%rcx,2),%esi
movsd  0x0(%r13,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rsi,8)
movzwl 0x4(%rdi,%rcx,2),%esi
movsd  0x0(%r13,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rsi,8)
movzwl 0x6(%rdi,%rcx,2),%esi
movsd  0x0(%r13,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1300 <p3dJohannsenThresholding_16+0x180>
test   %rax,%rax
je     139f <p3dJohannsenThresholding_16+0x21f>
lea    (%rdi,%rcx,2),%rcx
xor    %edx,%edx
movsd  0xc89(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movzwl (%rcx,%rdx,2),%esi
movsd  0x0(%r13,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rsi,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1380 <p3dJohannsenThresholding_16+0x200>
mov    %ebx,0x1c(%rsp)
mov    %r9,0x20(%rsp)
movslq 0x0(%rbp),%rax
mov    %eax,%r14d
test   %rax,%rax
js     144c <p3dJohannsenThresholding_16+0x2cc>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x1c(%rsp),%xmm0
lea    0x1(%r14),%rcx
test   %r14,%r14
je     1470 <p3dJohannsenThresholding_16+0x2f0>
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     1906 <p3dJohannsenThresholding_16+0x786>
mov    %rbx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
movupd 0x0(%r13,%rdi,8),%xmm2
movupd 0x10(%r13,%rdi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,0x0(%r13,%rdi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%r13,%rdi,8)
add    $0x4,%rdi
add    $0xfffffffffffffffe,%rsi
jne    1400 <p3dJohannsenThresholding_16+0x280>
test   $0x1,%bl
je     1445 <p3dJohannsenThresholding_16+0x2c5>
movupd 0x0(%r13,%rdi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,0x0(%r13,%rdi,8)
cmp    %rcx,%rdx
jne    1480 <p3dJohannsenThresholding_16+0x300>
jmp    149b <p3dJohannsenThresholding_16+0x31b>
movsd  0x0(%r13),%xmm0
movsd  %xmm0,(%r8)
movsd  0xba1(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    (%rsp),%rcx
movsd  %xmm1,(%rcx)
jmp    1627 <p3dJohannsenThresholding_16+0x4a7>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x0(%r13,%rdx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1480 <p3dJohannsenThresholding_16+0x300>
movsd  0x0(%r13),%xmm1
movsd  %xmm1,(%r8)
movsd  0xb52(%rip),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
mov    (%rsp),%rdx
movsd  %xmm2,(%rdx)
test   %eax,%eax
jle    1627 <p3dJohannsenThresholding_16+0x4a7>
mov    %ecx,%edi
mov    (%rsp),%rdx
lea    (%rdx,%r14,8),%rsi
add    $0x8,%rsi
add    $0x8,%rdx
cmp    %rsi,%r8
jae    1597 <p3dJohannsenThresholding_16+0x417>
lea    (%r8,%r14,8),%rsi
add    $0x8,%rsi
cmp    %rsi,%rdx
jae    1597 <p3dJohannsenThresholding_16+0x417>
add    $0xffffffffffffffff,%rcx
mov    $0x1,%esi
cmp    $0x2,%edi
je     156d <p3dJohannsenThresholding_16+0x3ed>
mov    %rcx,%rdi
and    $0xfffffffffffffffe,%rdi
neg    %rdi
mov    $0x1,%esi
nop
movsd  -0x8(%r8,%rsi,8),%xmm1
movsd  0x0(%r13,%rsi,8),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r8,%rsi,8)
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,-0x8(%rdx,%rsi,8)
movsd  (%r8,%rsi,8),%xmm1
movsd  0x8(%r13,%rsi,8),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%r8,%rsi,8)
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,(%rdx,%rsi,8)
lea    (%rdi,%rsi,1),%rbx
add    $0x2,%rbx
add    $0x2,%rsi
cmp    $0x1,%rbx
jne    1510 <p3dJohannsenThresholding_16+0x390>
test   $0x1,%cl
je     1627 <p3dJohannsenThresholding_16+0x4a7>
movsd  -0x8(%r8,%rsi,8),%xmm1
movsd  0x0(%r13,%rsi,8),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r8,%rsi,8)
subsd  %xmm1,%xmm0
jmp    161e <p3dJohannsenThresholding_16+0x49e>
movsd  (%r8),%xmm1
add    $0xffffffffffffffff,%rcx
mov    $0x1,%esi
cmp    $0x2,%edi
je     1608 <p3dJohannsenThresholding_16+0x488>
mov    %rcx,%rdi
and    $0xfffffffffffffffe,%rdi
neg    %rdi
mov    $0x1,%esi
nopl   0x0(%rax)
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
addsd  0x0(%r13,%rsi,8),%xmm1
movsd  %xmm1,(%r8,%rsi,8)
movsd  %xmm2,-0x8(%rdx,%rsi,8)
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
addsd  0x8(%r13,%rsi,8),%xmm1
movsd  %xmm1,0x8(%r8,%rsi,8)
movsd  %xmm2,(%rdx,%rsi,8)
lea    (%rdi,%rsi,1),%rbx
add    $0x2,%rbx
add    $0x2,%rsi
cmp    $0x1,%rbx
jne    15c0 <p3dJohannsenThresholding_16+0x440>
test   $0x1,%cl
je     1627 <p3dJohannsenThresholding_16+0x4a7>
subsd  %xmm1,%xmm0
addsd  0x0(%r13,%rsi,8),%xmm1
movsd  %xmm1,(%r8,%rsi,8)
mov    (%rsp),%rcx
movsd  %xmm0,(%rcx,%rsi,8)
xor    %ebx,%ebx
movabs $0x100000000,%rdx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax)
add    %rdx,%rbx
ucomisd 0x0(%r13,%rcx,8),%xmm0
lea    0x1(%rcx),%rcx
jae    1640 <p3dJohannsenThresholding_16+0x4c0>
add    $0x1,%r14d
lea    0x0(,%rax,8),%rax
add    %r13,%rax
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%r14
ucomisd (%rax),%xmm0
lea    -0x8(%rax),%rax
jae    1670 <p3dJohannsenThresholding_16+0x4f0>
mov    $0xffffffff,%edx
cmp    %r14d,%ecx
jge    17b9 <p3dJohannsenThresholding_16+0x639>
sar    $0x20,%rbx
mov    $0xffffffff,%edx
xorpd  %xmm0,%xmm0
jmp    16b3 <p3dJohannsenThresholding_16+0x533>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%r15
mov    %r15,%rbx
cmp    %r14d,%r15d
je     17b9 <p3dJohannsenThresholding_16+0x639>
mov    %ebx,%r12d
ucomisd 0x0(%r13,%r12,8),%xmm0
jae    16a0 <p3dJohannsenThresholding_16+0x520>
mov    0x10(%rsp),%rbp
movsd  0x0(%rbp,%r12,8),%xmm0
mov    %edx,0x4c(%rsp)
call   10a0 <_p3dJohannsenThresholding_dlog@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x91e(%rip),%xmm0
divsd  0x0(%rbp,%r12,8),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0x0(%r13,%r12,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  %xmm0,0x30(%rsp)
movsd  -0x8(%rbp,%rbx,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
addsd  0x30(%rsp),%xmm0
mulsd  0x38(%rsp),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x40(%rsp)
mov    (%rsp),%rbp
movsd  0x0(%rbp,%r12,8),%xmm0
call   10a0 <_p3dJohannsenThresholding_dlog@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x8be(%rip),%xmm0
divsd  0x0(%rbp,%r12,8),%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x0(%r13,%r12,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
movsd  %xmm0,0x60(%rsp)
mov    %rbx,%r15
add    $0x1,%r15
mov    %r15d,%eax
movsd  0x0(%rbp,%rax,8),%xmm0
call   1040 <_p3dJohannsenThresholding_entropy@plt>
mov    0x28(%rsp),%rcx
mov    0x4c(%rsp),%edx
addsd  0x60(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
addsd  0x38(%rsp),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  %xmm0,(%rcx,%r12,8)
test   %edx,%edx
js     17ae <p3dJohannsenThresholding_16+0x62e>
mov    %edx,%eax
movsd  (%rcx,%rax,8),%xmm1
ucomisd %xmm0,%xmm1
jbe    17b0 <p3dJohannsenThresholding_16+0x630>
mov    %ebx,%edx
xorpd  %xmm0,%xmm0
jmp    16a7 <p3dJohannsenThresholding_16+0x527>
mov    0x8(%rsp),%r10
mov    %dx,(%r10)
mov    0x1c(%rsp),%esi
test   %esi,%esi
mov    0xa0(%rsp),%r15
mov    0x58(%rsp),%rax
mov    0x50(%rsp),%rbx
mov    0x20(%rsp),%rbp
jle    1956 <p3dJohannsenThresholding_16+0x7d6>
xor    %ecx,%ecx
cmp    %dx,(%rbx)
mov    0x27ff(%rip),%r11
movzbl (%r11),%edx
cmovbe %ecx,%edx
mov    %dl,(%rax)
cmp    $0x1,%esi
je     1956 <p3dJohannsenThresholding_16+0x7d6>
lea    -0x1(%rbp),%r8
mov    $0x1,%ecx
cmp    $0x10,%r8
jb     1928 <p3dJohannsenThresholding_16+0x7a8>
lea    0x1(%rax),%rdx
lea    (%rax,%rbp,1),%rdi
lea    0x2(%r10),%rsi
lea    0x2(%rbx),%r14
cmp    %rsi,%rdx
setb   %r9b
cmp    %r10,%rdi
seta   %r10b
lea    (%rbx,%rbp,2),%rsi
cmp    %rsi,%rdx
setb   %dl
cmp    %r14,%rdi
seta   %sil
cmp    %r11,%rax
setb   %r14b
cmp    %r11,%rdi
seta   %dil
test   %r10b,%r9b
jne    1916 <p3dJohannsenThresholding_16+0x796>
and    %sil,%dl
mov    0xa0(%rsp),%r15
jne    191e <p3dJohannsenThresholding_16+0x79e>
and    %dil,%r14b
mov    0x8(%rsp),%r10
mov    0x20(%rsp),%rbp
jne    1928 <p3dJohannsenThresholding_16+0x7a8>
mov    %r8,%rsi
and    $0xfffffffffffffff0,%rsi
lea    0x1(%rsi),%rcx
movzwl (%r10),%edx
movd   %edx,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm0
movzbl (%r11),%edx
movd   %edx,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %edi,%edi
movdqa 0x758(%rip),%xmm2
pxor   %xmm2,%xmm0
nopl   0x0(%rax)
movdqu 0x2(%rbx,%rdi,2),%xmm3
movdqu 0x12(%rbx,%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(%rax,%rdi,1)
add    $0x10,%rdi
cmp    %rdi,%rsi
jne    18c0 <p3dJohannsenThresholding_16+0x740>
cmp    %rsi,%r8
jne    1928 <p3dJohannsenThresholding_16+0x7a8>
jmp    1956 <p3dJohannsenThresholding_16+0x7d6>
xor    %edi,%edi
test   $0x1,%bl
jne    1433 <p3dJohannsenThresholding_16+0x2b3>
jmp    1445 <p3dJohannsenThresholding_16+0x2c5>
mov    0xa0(%rsp),%r15
mov    0x8(%rsp),%r10
mov    0x20(%rsp),%rbp
mov    %rcx,%rdx
not    %rdx
test   $0x1,%bpl
jne    194d <p3dJohannsenThresholding_16+0x7cd>
movzwl (%rbx,%rcx,2),%esi
xor    %edi,%edi
cmp    (%r10),%si
movzbl (%r11),%esi
cmovbe %edi,%esi
mov    %sil,(%rax,%rcx,1)
add    $0x1,%rcx
add    %rbp,%rdx
jne    19e1 <p3dJohannsenThresholding_16+0x861>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x2,%ebx
test   %r15,%r15
je     12b6 <p3dJohannsenThresholding_16+0x136>
mov    0x8(%rsp),%rax
movzwl (%rax),%esi
lea    0x6c7(%rip),%rdi
xor    %eax,%eax
call   *%r15
xor    %eax,%eax
call   1070 <p3dGetElapsedTime_min@plt>
mov    %r15,%r14
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_sec@plt>
lea    0x6c3(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%r15
jmp    12b6 <p3dJohannsenThresholding_16+0x136>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %dl,0x1(%rax,%rcx,1)
add    $0x2,%rcx
cmp    %rcx,%rbp
je     1956 <p3dJohannsenThresholding_16+0x7d6>
movzwl (%rbx,%rcx,2),%esi
xor    %edx,%edx
cmp    (%r10),%si
ja     1a00 <p3dJohannsenThresholding_16+0x880>
xor    %esi,%esi
jmp    1a04 <p3dJohannsenThresholding_16+0x884>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r11),%esi
mov    %sil,(%rax,%rcx,1)
movzwl 0x2(%rbx,%rcx,2),%esi
cmp    (%r10),%si
jbe    19d0 <p3dJohannsenThresholding_16+0x850>
movzbl (%r11),%edx
jmp    19d0 <p3dJohannsenThresholding_16+0x850>

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

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