#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 _p3dPunThresholding_entropy(double *, int);
double _p3dPunThresholding_flog(double);
double _p3dPunThresholding_maxfromt_16(double *, int);
double _p3dPunThresholding_maxtot(double *, int);
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 p3dPunThresholding_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 *Ht = NULL;
  double *Pt = NULL;
  double *F = NULL;
  double HT, x, y, z, to, from;
  int i, ct, t;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Thresholding image according to Pun's method...");
  }
  if (((Ht = (double *)malloc(sizeof(double) * (USHRT_MAX + 1))) == 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 (((prob = (double *)calloc((USHRT_MAX + 1), sizeof(double))) == NULL)) {
    goto MEM_ERROR;
  };
  for (ct = 0; ct < (dimx * dimy * dimz); ct++)
    prob[in_im[ct]] = prob[in_im[ct]] + 1.0;
  for (ct = 0; ct <= USHRT_MAX; ct++)
    prob[ct] = prob[ct] / (double)(dimx * dimy * dimz);
  HT = Ht[0] = _p3dPunThresholding_entropy(prob, 0);
  Pt[0] = prob[0];
  for (i = 1; i <= USHRT_MAX; i++) {
    Pt[i] = Pt[i - 1] + prob[i];
    x = _p3dPunThresholding_entropy(prob, i);
    Ht[i] = Ht[i - 1] + x;
    HT += x;
  }
  t = 0;
  for (i = 0; i <= USHRT_MAX; i++) {
    to = (_p3dPunThresholding_maxtot(prob, i));
    from = _p3dPunThresholding_maxfromt_16(prob, i);
    if (to > 0.0 && from > 0.0) {
      x = (Ht[i] / HT) * _p3dPunThresholding_flog(Pt[i]) /
          _p3dPunThresholding_flog(to);
      y = 1.0 - (Ht[i] / HT);
      z = _p3dPunThresholding_flog(1 - Pt[i]) / _p3dPunThresholding_flog(from);
    } else
      x = y = z = 0.0;
    F[i] = x + y * z;
    if (i > 0 && 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 (wr_log != NULL) {
    wr_log("\tDetermined threshold: %d.", *thresh);
    wr_log("Pore3D - Image thresholded successfully in %dm%0.3fs.",
           p3dGetElapsedTime_min(), p3dGetElapsedTime_sec());
  }
  if (prob != NULL)
    free(prob);
  if (Ht != NULL)
    free(Ht);
  if (Pt != NULL)
    free(Pt);
  if (F != NULL)
    free(F);
  return 2;
MEM_ERROR:
  if (wr_log != NULL) {
    wr_log("Pore3D - Not enough (contiguous) memory. Program will exit.");
  }
  if (prob != NULL)
    free(prob);
  if (Ht != NULL)
    free(Ht);
  if (Pt != NULL)
    free(Pt);
  if (F != NULL)
    free(F);
  return 0;
}


x86 assembly (clang, -O0):
<p3dPunThresholding_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     1207 <p3dPunThresholding_16+0x67>
mov    $0x0,%al
call   1080 <p3dResetStartTime@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1233 <p3dPunThresholding_16+0x93>
jmp    179a <p3dPunThresholding_16+0x5fa>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    125f <p3dPunThresholding_16+0xbf>
jmp    179a <p3dPunThresholding_16+0x5fa>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    128b <p3dPunThresholding_16+0xeb>
jmp    179a <p3dPunThresholding_16+0x5fa>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    12b4 <p3dPunThresholding_16+0x114>
jmp    179a <p3dPunThresholding_16+0x5fa>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1323 <p3dPunThresholding_16+0x183>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x88(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  0xd0e(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x88(%rbp),%rdx
movzwl (%rcx,%rdx,2),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    12be <p3dPunThresholding_16+0x11e>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    0x2ca6(%rip),%rcx
cmp    (%rcx),%eax
jg     1389 <p3dPunThresholding_16+0x1e9>
mov    -0x38(%rbp),%rax
movslq -0x88(%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 -0x88(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    132d <p3dPunThresholding_16+0x18d>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1090 <_p3dPunThresholding_entropy@plt>
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  %xmm0,-0x58(%rbp)
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x48(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    0x2c18(%rip),%rcx
cmp    (%rcx),%eax
jg     1466 <p3dPunThresholding_16+0x2c6>
mov    -0x48(%rbp),%rax
mov    -0x84(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x84(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   1090 <_p3dPunThresholding_entropy@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x84(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x60(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x60(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    13bb <p3dPunThresholding_16+0x21b>
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    0x2b59(%rip),%rcx
cmp    (%rcx),%eax
jg     1647 <p3dPunThresholding_16+0x4a7>
mov    -0x38(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   10c0 <_p3dPunThresholding_maxtot@plt>
movsd  %xmm0,-0x78(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   10b0 <_p3dPunThresholding_maxfromt_16@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    15b0 <p3dPunThresholding_16+0x410>
movsd  -0x80(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    15b0 <p3dPunThresholding_16+0x410>
mov    -0x40(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0x48(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x78(%rbp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
divsd  -0x58(%rbp),%xmm1
movsd  0xaa1(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  0xa85(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    15c8 <p3dPunThresholding_16+0x428>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x50(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cmpl   $0x0,-0x84(%rbp)
jle    162e <p3dPunThresholding_16+0x48e>
mov    -0x50(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x8c(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    162e <p3dPunThresholding_16+0x48e>
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
jmp    1633 <p3dPunThresholding_16+0x493>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    147a <p3dPunThresholding_16+0x2da>
mov    -0x8c(%rbp),%eax
mov    %ax,%cx
mov    -0x30(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    16e4 <p3dPunThresholding_16+0x544>
mov    -0x10(%rbp),%rax
movslq -0x88(%rbp),%rcx
movzwl (%rax,%rcx,2),%eax
mov    -0x30(%rbp),%rcx
movzwl (%rcx),%ecx
cmp    %ecx,%eax
jle    16ad <p3dPunThresholding_16+0x50d>
mov    0x2951(%rip),%rax
movzbl (%rax),%eax
mov    %eax,-0xac(%rbp)
jmp    16ba <p3dPunThresholding_16+0x51a>
xor    %eax,%eax
mov    %eax,-0xac(%rbp)
jmp    16ba <p3dPunThresholding_16+0x51a>
mov    -0xac(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x88(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1661 <p3dPunThresholding_16+0x4c1>
cmpq   $0x0,0x10(%rbp)
je     173e <p3dPunThresholding_16+0x59e>
mov    0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
movzwl (%rax),%esi
lea    0x940(%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    0x922(%rip),%rdi
mov    $0x0,%al
call   *%rcx
cmpq   $0x0,-0x38(%rbp)
je     1752 <p3dPunThresholding_16+0x5b2>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1766 <p3dPunThresholding_16+0x5c6>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     177a <p3dPunThresholding_16+0x5da>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x50(%rbp)
je     178e <p3dPunThresholding_16+0x5ee>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1808 <p3dPunThresholding_16+0x668>
cmpq   $0x0,0x10(%rbp)
je     17b1 <p3dPunThresholding_16+0x611>
lea    0x8e6(%rip),%rdi
mov    $0x0,%al
call   *0x10(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     17c5 <p3dPunThresholding_16+0x625>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     17d9 <p3dPunThresholding_16+0x639>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     17ed <p3dPunThresholding_16+0x64d>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x50(%rbp)
je     1801 <p3dPunThresholding_16+0x661>
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):
<p3dPunThresholding_16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x40(%rsp)
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %rsi,0x60(%rsp)
mov    %rdi,0x20(%rsp)
mov    0xa0(%rsp),%rbx
test   %rbx,%rbx
je     11e4 <p3dPunThresholding_16+0x44>
xor    %eax,%eax
call   1080 <p3dResetStartTime@plt>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   *%rbx
mov    0x2df5(%rip),%r12
mov    (%r12),%eax
lea    0x8(,%rax,8),%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1294 <p3dPunThresholding_16+0xf4>
mov    (%r12),%eax
lea    0x8(,%rax,8),%edi
call   10a0 <malloc@plt>
mov    %rax,0x28(%rsp)
test   %rax,%rax
je     1294 <p3dPunThresholding_16+0xf4>
mov    (%r12),%eax
lea    0x8(,%rax,8),%edi
call   10a0 <malloc@plt>
mov    %rax,0x58(%rsp)
test   %rax,%rax
je     12d3 <p3dPunThresholding_16+0x133>
mov    (%r12),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     12dd <p3dPunThresholding_16+0x13d>
mov    %rax,%r12
mov    %ebp,%eax
imul   %r15d,%eax
imul   %r13d,%eax
mov    %eax,%ebp
mov    %eax,0x34(%rsp)
test   %eax,%eax
mov    0x28(%rsp),%r13
mov    0x20(%rsp),%rdi
jle    138d <p3dPunThresholding_16+0x1ed>
lea    -0x1(%rbp),%rcx
mov    %ebp,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    12f1 <p3dPunThresholding_16+0x151>
xor    %ecx,%ecx
jmp    135c <p3dPunThresholding_16+0x1bc>
xor    %ebp,%ebp
xor    %r15d,%r15d
test   %rbx,%rbx
je     12a9 <p3dPunThresholding_16+0x109>
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   *%rbx
test   %r14,%r14
je     12b6 <p3dPunThresholding_16+0x116>
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     12c3 <p3dPunThresholding_16+0x123>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
test   %r15,%r15
jne    199b <p3dPunThresholding_16+0x7fb>
jmp    19a3 <p3dPunThresholding_16+0x803>
xor    %r15d,%r15d
mov    0x28(%rsp),%rbp
jmp    1299 <p3dPunThresholding_16+0xf9>
mov    0xa0(%rsp),%rbx
mov    0x58(%rsp),%r15
mov    0x28(%rsp),%rbp
jmp    1299 <p3dPunThresholding_16+0xf9>
mov    %ebp,%edx
and    $0xfffffffc,%edx
xor    %ecx,%ecx
movsd  0xd00(%rip),%xmm0
movzwl (%rdi,%rcx,2),%esi
movsd  (%r12,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rsi,8)
movzwl 0x2(%rdi,%rcx,2),%esi
movsd  (%r12,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rsi,8)
movzwl 0x4(%rdi,%rcx,2),%esi
movsd  (%r12,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rsi,8)
movzwl 0x6(%rdi,%rcx,2),%esi
movsd  (%r12,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rsi,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1300 <p3dPunThresholding_16+0x160>
test   %rax,%rax
je     138d <p3dPunThresholding_16+0x1ed>
lea    (%rdi,%rcx,2),%rcx
xor    %edx,%edx
movsd  0xc91(%rip),%xmm0
nop
movzwl (%rcx,%rdx,2),%esi
movsd  (%r12,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rsi,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1370 <p3dPunThresholding_16+0x1d0>
mov    0x2c4c(%rip),%rax
mov    (%rax),%ecx
test   %ecx,%ecx
mov    0x58(%rsp),%r15
js     1459 <p3dPunThresholding_16+0x2b9>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x34(%rsp),%xmm0
lea    0x1(%rcx),%rax
test   %rcx,%rcx
je     1438 <p3dPunThresholding_16+0x298>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rsi
mov    %rsi,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     18f6 <p3dPunThresholding_16+0x756>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movupd (%r12,%rsi,8),%xmm2
movupd 0x10(%r12,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%r12,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%r12,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rdi
jne    13f0 <p3dPunThresholding_16+0x250>
test   $0x1,%dl
je     1431 <p3dPunThresholding_16+0x291>
movupd (%r12,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%r12,%rsi,8)
cmp    %rax,%rcx
jne    1440 <p3dPunThresholding_16+0x2a0>
jmp    1459 <p3dPunThresholding_16+0x2b9>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movsd  (%r12,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r12,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1440 <p3dPunThresholding_16+0x2a0>
mov    %rbp,0x38(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <_p3dPunThresholding_entropy@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,(%r14)
movsd  (%r12),%xmm0
movsd  %xmm0,0x0(%r13)
mov    0x2b5c(%rip),%rbp
mov    0x0(%rbp),%eax
test   %eax,%eax
jle    152b <p3dPunThresholding_16+0x38b>
addsd  0x8(%r12),%xmm0
movsd  %xmm0,0x8(%r13)
mov    %r12,%rdi
mov    $0x1,%esi
movsd  %xmm1,0x18(%rsp)
call   1090 <_p3dPunThresholding_entropy@plt>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
addsd  (%r14),%xmm0
movsd  %xmm0,0x8(%r14)
mov    0x0(%rbp),%eax
cmp    $0x2,%eax
jl     152b <p3dPunThresholding_16+0x38b>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x18(%rsp)
movsd  -0x8(%r13,%rbx,8),%xmm0
addsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,0x0(%r13,%rbx,8)
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <_p3dPunThresholding_entropy@plt>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
addsd  -0x8(%r14,%rbx,8),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
movslq 0x0(%rbp),%rax
lea    0x1(%rbx),%rcx
cmp    %rax,%rbx
mov    %rcx,%rbx
jl     14e0 <p3dPunThresholding_16+0x340>
test   %eax,%eax
js     161f <p3dPunThresholding_16+0x47f>
movsd  %xmm1,0x18(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <_p3dPunThresholding_maxtot@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <_p3dPunThresholding_maxfromt_16@plt>
movapd %xmm0,%xmm2
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1626 <p3dPunThresholding_16+0x486>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
jbe    162e <p3dPunThresholding_16+0x48e>
movsd  (%r14),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x0(%r13),%xmm0
movsd  %xmm2,0x50(%rsp)
call   1040 <_p3dPunThresholding_flog@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%r14),%xmm1
divsd  0x18(%rsp),%xmm1
movsd  0xa23(%rip),%xmm0
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
subsd  0x0(%r13),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  %xmm0,0x48(%rsp)
movsd  0x50(%rsp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  0x48(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm3
movsd  0x10(%rsp),%xmm0
jmp    162e <p3dPunThresholding_16+0x48e>
xor    %ebx,%ebx
jmp    17a2 <p3dPunThresholding_16+0x602>
xorpd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r15)
xor    %ebx,%ebx
cmpl   $0x0,0x0(%rbp)
jle    17a2 <p3dPunThresholding_16+0x602>
mov    $0x1,%r13d
jmp    1666 <p3dPunThresholding_16+0x4c6>
nop
lea    0x1(%r13),%rcx
movslq 0x0(%rbp),%rdx
mov    %eax,%ebx
cmp    %rdx,%r13
mov    %rcx,%r13
jge    179b <p3dPunThresholding_16+0x5fb>
mov    %r12,%rdi
mov    %r13d,%esi
call   10c0 <_p3dPunThresholding_maxtot@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r12,%rdi
mov    %r13d,%esi
call   10b0 <_p3dPunThresholding_maxfromt_16@plt>
movsd  0x10(%rsp),%xmm1
ucomisd 0x978(%rip),%xmm1
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
jbe    1774 <p3dPunThresholding_16+0x5d4>
ucomisd 0x95a(%rip),%xmm1
xorpd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
jbe    1774 <p3dPunThresholding_16+0x5d4>
movsd  (%r14,%r13,8),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rbp
mov    0x28(%rsp),%r15
movsd  (%r15,%r13,8),%xmm0
movsd  %xmm1,0x50(%rsp)
call   1040 <_p3dPunThresholding_flog@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%r14,%r13,8),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  0x8da(%rip),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
subsd  (%r15,%r13,8),%xmm0
mov    %rbp,%r15
mov    0x2898(%rip),%rbp
call   1040 <_p3dPunThresholding_flog@plt>
movsd  %xmm0,0x48(%rsp)
movsd  0x50(%rsp),%xmm0
call   1040 <_p3dPunThresholding_flog@plt>
movsd  0x48(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm3
movsd  0x8(%rsp),%xmm0
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r15,%r13,8)
movslq %ebx,%rax
ucomisd (%r15,%rax,8),%xmm2
mov    %r13d,%eax
ja     1650 <p3dPunThresholding_16+0x4b0>
mov    %ebx,%eax
jmp    1650 <p3dPunThresholding_16+0x4b0>
mov    %eax,%ebx
mov    0x28(%rsp),%r13
mov    0x40(%rsp),%r11
mov    %bx,(%r11)
mov    0x34(%rsp),%esi
test   %esi,%esi
mov    0x60(%rsp),%rax
mov    0x20(%rsp),%rbp
mov    0x38(%rsp),%r9
jle    1943 <p3dPunThresholding_16+0x7a3>
xor    %ecx,%ecx
cmp    %bx,0x0(%rbp)
mov    0x281d(%rip),%rbx
movzbl (%rbx),%edx
cmovbe %ecx,%edx
mov    %dl,(%rax)
cmp    $0x1,%esi
je     1943 <p3dPunThresholding_16+0x7a3>
lea    -0x1(%r9),%r8
mov    $0x1,%ecx
cmp    $0x10,%r8
jb     1915 <p3dPunThresholding_16+0x775>
lea    0x1(%rax),%rdx
lea    (%rax,%r9,1),%rdi
lea    0x2(%r11),%rsi
mov    %r9,%rax
lea    0x2(%rbp),%r9
cmp    %rsi,%rdx
setb   %r10b
cmp    %r11,%rdi
seta   %r11b
lea    0x0(,%rax,2),%rsi
add    %rbp,%rsi
cmp    %rsi,%rdx
setb   %dl
cmp    %r9,%rdi
mov    0x60(%rsp),%rax
seta   %sil
cmp    %rbx,%rax
setb   %r9b
cmp    %rbx,%rdi
seta   %dil
test   %r11b,%r10b
jne    1906 <p3dPunThresholding_16+0x766>
and    %sil,%dl
jne    1906 <p3dPunThresholding_16+0x766>
and    %dil,%r9b
mov    0x40(%rsp),%r11
mov    0x20(%rsp),%rbp
mov    0x38(%rsp),%r9
jne    1915 <p3dPunThresholding_16+0x775>
mov    %r8,%rsi
and    $0xfffffffffffffff0,%rsi
lea    0x1(%rsi),%rcx
movzwl (%r11),%edx
movd   %edx,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm0
movzbl (%rbx),%edx
movd   %edx,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %edi,%edi
movdqa 0x76c(%rip),%xmm2
pxor   %xmm2,%xmm0
nopl   0x0(%rax,%rax,1)
movdqu 0x2(%rbp,%rdi,2),%xmm3
movdqu 0x12(%rbp,%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    18b0 <p3dPunThresholding_16+0x710>
cmp    %rsi,%r8
jne    1915 <p3dPunThresholding_16+0x775>
jmp    1943 <p3dPunThresholding_16+0x7a3>
xor    %esi,%esi
test   $0x1,%dl
jne    1421 <p3dPunThresholding_16+0x281>
jmp    1431 <p3dPunThresholding_16+0x291>
mov    0x40(%rsp),%r11
mov    0x20(%rsp),%rbp
mov    0x38(%rsp),%r9
mov    %rcx,%rdx
not    %rdx
test   $0x1,%r9b
jne    193a <p3dPunThresholding_16+0x79a>
movzwl 0x0(%rbp,%rcx,2),%esi
xor    %edi,%edi
cmp    (%r11),%si
movzbl (%rbx),%esi
cmovbe %edi,%esi
mov    %sil,(%rax,%rcx,1)
add    $0x1,%rcx
add    %r9,%rdx
jne    19d1 <p3dPunThresholding_16+0x831>
mov    0xa0(%rsp),%rbp
test   %rbp,%rbp
je     197e <p3dPunThresholding_16+0x7de>
movzwl (%r11),%esi
lea    0x6fe(%rip),%rdi
xor    %eax,%eax
call   *%rbp
xor    %eax,%eax
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_sec@plt>
lea    0x6fe(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%rbp
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x2,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %dl,0x1(%rax,%rcx,1)
add    $0x2,%rcx
cmp    %rcx,%r9
je     1943 <p3dPunThresholding_16+0x7a3>
movzwl 0x0(%rbp,%rcx,2),%esi
xor    %edx,%edx
cmp    (%r11),%si
ja     19f0 <p3dPunThresholding_16+0x850>
xor    %esi,%esi
jmp    19f3 <p3dPunThresholding_16+0x853>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%esi
mov    %sil,(%rax,%rcx,1)
movzwl 0x2(%rbp,%rcx,2),%esi
cmp    (%r11),%si
jbe    19c0 <p3dPunThresholding_16+0x820>
movzbl (%rbx),%edx
jmp    19c0 <p3dPunThresholding_16+0x820>

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

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