#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int const);
scalar_t__ p3dCrop3D_uchar2uchar(unsigned char *, unsigned char *, int const,
                                 int const, int const, int const);
int /*<<< orphan*/ p3dGetElapsedTime_min();
int /*<<< orphan*/ p3dGetElapsedTime_sec();
int /*<<< orphan*/ p3dResetStartTime();
scalar_t__ p3dThinning(unsigned char *, int const, int const, int const);
scalar_t__ p3dZeroPadding3D_uchar2uchar(unsigned char *, unsigned char *,
                                        int const, int const, int const,
                                        int const);
int p3dThinningSkeletonization(unsigned char *in_im, unsigned char *out_im,
                               const int dimx, const int dimy, const int dimz,
                               int (*wr_log)(const char *, ...)) {
  unsigned char *tmp_im;
  const int a_rad = 1;
  const int a_dimx = dimx + a_rad * 2;
  const int a_dimy = dimy + a_rad * 2;
  const int a_dimz = dimz + a_rad * 2;
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Performing thinning skeletonization...");
  }
  if (((tmp_im = (unsigned char *)malloc(a_dimx * a_dimy * a_dimz *
                                         sizeof(unsigned char))) == NULL)) {
    goto MEM_ERROR;
  };
  if (((p3dZeroPadding3D_uchar2uchar(in_im, tmp_im, dimx, dimy, dimz, a_rad)) ==
       0)) {
    goto MEM_ERROR;
  };
  if (((p3dThinning(tmp_im, a_dimx, a_dimy, a_dimz)) == 0)) {
    goto MEM_ERROR;
  };
  if (((p3dCrop3D_uchar2uchar(tmp_im, out_im, a_dimx, a_dimy, a_dimz, a_rad)) ==
       0)) {
    goto MEM_ERROR;
  };
  if (wr_log != NULL) {
    wr_log("Pore3D - Thinning skeletonization performed successfully in "
           "%dm%0.3fs.",
           p3dGetElapsedTime_min(), p3dGetElapsedTime_sec());
  }
  if (tmp_im != NULL)
    free(tmp_im);
  return 2;
MEM_ERROR:
  if (wr_log != NULL) {
    wr_log("Pore3D - Not enough (contiguous) memory. Program will exit.");
  }
  if (tmp_im != NULL)
    free(tmp_im);
  return 0;
}


x86 assembly (clang, -O0):
<p3dThinningSkeletonization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x48(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11de <p3dThinningSkeletonization+0x5e>
mov    $0x0,%al
call   1080 <p3dResetStartTime@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   *-0x30(%rbp)
mov    -0x40(%rbp),%eax
imul   -0x44(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1209 <p3dThinningSkeletonization+0x89>
jmp    12da <p3dThinningSkeletonization+0x15a>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    $0x1,%r9d
call   1040 <p3dZeroPadding3D_uchar2uchar@plt>
cmp    $0x0,%rax
jne    1235 <p3dThinningSkeletonization+0xb5>
jmp    12da <p3dThinningSkeletonization+0x15a>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
call   1060 <p3dThinning@plt>
cmp    $0x0,%rax
jne    1256 <p3dThinningSkeletonization+0xd6>
jmp    12da <p3dThinningSkeletonization+0x15a>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%edx
mov    -0x44(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    $0x1,%r9d
call   1090 <p3dCrop3D_uchar2uchar@plt>
cmp    $0x0,%rax
jne    1282 <p3dThinningSkeletonization+0x102>
jmp    12da <p3dThinningSkeletonization+0x15a>
cmpq   $0x0,-0x30(%rbp)
je     12ba <p3dThinningSkeletonization+0x13a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,-0x54(%rbp)
mov    $0x0,%al
call   1050 <p3dGetElapsedTime_sec@plt>
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%rcx
mov    %eax,%edx
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   *%rcx
cmpq   $0x0,-0x38(%rbp)
je     12ce <p3dThinningSkeletonization+0x14e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    130c <p3dThinningSkeletonization+0x18c>
cmpq   $0x0,-0x30(%rbp)
je     12f1 <p3dThinningSkeletonization+0x171>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   *-0x30(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1305 <p3dThinningSkeletonization+0x185>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dThinningSkeletonization>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
lea    0x2(%r13),%ebx
lea    0x2(%r12),%eax
mov    %eax,(%rsp)
lea    0x2(%r15),%ebp
test   %r9,%r9
je     11cc <p3dThinningSkeletonization+0x4c>
xor    %eax,%eax
call   1080 <p3dResetStartTime@plt>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   *%r14
mov    (%rsp),%edi
mov    %ebx,0x4(%rsp)
imul   %ebx,%edi
imul   %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1271 <p3dThinningSkeletonization+0xf1>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    $0x1,%r9d
call   1040 <p3dZeroPadding3D_uchar2uchar@plt>
test   %rax,%rax
je     1271 <p3dThinningSkeletonization+0xf1>
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %ebp,%ecx
call   1060 <p3dThinning@plt>
test   %rax,%rax
je     1271 <p3dThinningSkeletonization+0xf1>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    %ebp,%r8d
mov    $0x1,%r9d
call   1090 <p3dCrop3D_uchar2uchar@plt>
test   %rax,%rax
je     1271 <p3dThinningSkeletonization+0xf1>
mov    $0x2,%ebp
test   %r14,%r14
je     1289 <p3dThinningSkeletonization+0x109>
xor    %eax,%eax
call   1070 <p3dGetElapsedTime_min@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_sec@plt>
lea    0xdcb(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *%r14
jmp    1289 <p3dThinningSkeletonization+0x109>
test   %r14,%r14
je     1282 <p3dThinningSkeletonization+0x102>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   *%r14
xor    %ebp,%ebp
test   %rbx,%rbx
je     1291 <p3dThinningSkeletonization+0x111>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Pore3D - Performing thinning skeletonization...\00"
@.str.1 = [71 x i8] c"Pore3D - Thinning skeletonization performed successfully in %dm%0.3fs.\00"
@.str.2 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dThinningSkeletonization(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 (i8*, ...)* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32 (i8*, ...)*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 (i8*, ...)* %5, i32 (i8*, ...)** %13
store i32 1, i32* %15
%19 = load i32, i32* %10
%20 = add nsw i32 %19, 2
store i32 %20, i32* %16
%21 = load i32, i32* %11
%22 = add nsw i32 %21, 2
store i32 %22, i32* %17
%23 = load i32, i32* %12
%24 = add nsw i32 %23, 2
store i32 %24, i32* %18
%25 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%26 = icmp ne i32 (i8*, ...)* %25, null
br i1 %26, label %27, label %31
27: ; preds = %6
%28 = call i32 (...) @p3dResetStartTime()
%29 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%30 = call i32 (i8*, ...) %29(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %27, %6
%32 = load i32, i32* %16
%33 = load i32, i32* %17
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %18
%36 = mul nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %14
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %31
br label %85
44: ; preds = %31
%45 = load i8*, i8** %8
%46 = load i8*, i8** %14
%47 = load i32, i32* %10
%48 = load i32, i32* %11
%49 = load i32, i32* %12
%50 = call i64 @p3dZeroPadding3D_uchar2uchar(i8* %45, i8* %46, i32 %47, i32 %48, i32 %49, i32 1)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %44
br label %85
53: ; preds = %44
%54 = load i8*, i8** %14
%55 = load i32, i32* %16
%56 = load i32, i32* %17
%57 = load i32, i32* %18
%58 = call i64 @p3dThinning(i8* %54, i32 %55, i32 %56, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %53
br label %85
61: ; preds = %53
%62 = load i8*, i8** %14
%63 = load i8*, i8** %9
%64 = load i32, i32* %16
%65 = load i32, i32* %17
%66 = load i32, i32* %18
%67 = call i64 @p3dCrop3D_uchar2uchar(i8* %62, i8* %63, i32 %64, i32 %65, i32 %66, i32 1)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %61
br label %85
70: ; preds = %61
%71 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%72 = icmp ne i32 (i8*, ...)* %71, null
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%75 = call i32 (...) @p3dGetElapsedTime_min()
%76 = call i32 (...) @p3dGetElapsedTime_sec()
%77 = call i32 (i8*, ...) %74(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 %75, i32 %76)
br label %78
78: ; preds = %73, %70
%79 = load i8*, i8** %14
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i8*, i8** %14
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81, %78
store i32 2, i32* %7
br label %98
85: ; preds = %69, %60, %52, %43
%86 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%87 = icmp ne i32 (i8*, ...)* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i32 (i8*, ...)*, i32 (i8*, ...)** %13
%90 = call i32 (i8*, ...) %89(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %91
91: ; preds = %88, %85
%92 = load i8*, i8** %14
%93 = icmp ne i8* %92, null
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i8*, i8** %14
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %94, %91
store i32 0, i32* %7
br label %98
98: ; preds = %97, %84
%99 = load i32, i32* %7
ret i32 %99
}

LLVM IR (-O2):
@.str = [48 x i8] c"Pore3D - Performing thinning skeletonization...\00"
@.str.1 = [71 x i8] c"Pore3D - Thinning skeletonization performed successfully in %dm%0.3fs.\00"
@.str.2 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dThinningSkeletonization(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 (i8*, ...)* %5) {
%7 = add nsw i32 %2, 2
%8 = add nsw i32 %3, 2
%9 = add nsw i32 %4, 2
%10 = icmp eq i32 (i8*, ...)* %5, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 (...) @p3dResetStartTime()
%13 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %6
%15 = mul nsw i32 %8, %7
%16 = mul nsw i32 %15, %9
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %34, label %20
20: ; preds = %14
%21 = tail call i64 @p3dZeroPadding3D_uchar2uchar(i8* %0, i8* %18, i32 %2, i32 %3, i32 %4, i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %20
%24 = tail call i64 @p3dThinning(i8* %18, i32 %7, i32 %8, i32 %9)
%25 = icmp eq i64 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %23
%27 = tail call i64 @p3dCrop3D_uchar2uchar(i8* %18, i8* %1, i32 %7, i32 %8, i32 %9, i32 1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
br i1 %10, label %38, label %30
30: ; preds = %29
%31 = tail call i32 (...) @p3dGetElapsedTime_min()
%32 = tail call i32 (...) @p3dGetElapsedTime_sec()
%33 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
br label %38
34: ; preds = %26, %23, %20, %14
br i1 %10, label %37, label %35
35: ; preds = %34
%36 = tail call i32 (i8*, ...) %5(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %34
br i1 %19, label %41, label %38
38: ; preds = %37, %30, %29
%39 = phi i32 [ 2, %29 ], [ 2, %30 ], [ 0, %37 ]
%40 = tail call i32 @free(i8* %18)
br label %41
41: ; preds = %38, %37
%42 = phi i32 [ 0, %37 ], [ %39, %38 ]
ret i32 %42
}