#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 */
scalar_t__ p3dConnectedComponentsLabeling_ushort(
    unsigned char *, unsigned short *, int /*<<< orphan*/ *,
    int /*<<< orphan*/ *, int /*<<< orphan*/ *, int const, int const, int const,
    int const, int const, int const);
int /*<<< orphan*/ p3dGetElapsedTime_min();
int /*<<< orphan*/ p3dGetElapsedTime_sec();
int /*<<< orphan*/ p3dResetStartTime();
int p3dBlobLabeling_ushort(unsigned char *in_im, unsigned short *out_im,
                           const int dimx, const int dimy, const int dimz,
                           const int conn, const int random_lbl,
                           const int skip_borders,
                           int (*wr_log)(const char *, ...)) {
  if (wr_log != NULL) {
    p3dResetStartTime();
    wr_log("Pore3D - Performing blob labeling...");
    if (conn == 711)
      wr_log("\t6-connectivity used. ");
    else if (conn == 712)
      wr_log("\t18-connectivity used. ");
    else
      wr_log("\t26-connectivity used. ");
    if (random_lbl == 1)
      wr_log("\tRandom labels used. ");
    if (skip_borders == 1)
      wr_log("\tBorders skipped. ");
  }
  if (((p3dConnectedComponentsLabeling_ushort(
           in_im, out_im, NULL, NULL, NULL, dimx, dimy, dimz, conn, random_lbl,
           skip_borders)) == 0)) {
    goto MEM_ERROR;
  };
  if (wr_log != NULL) {
    wr_log("Pore3D - Blob labeling performed 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.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<p3dBlobLabeling_ushort>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %edx,-0x2c(%rbp)
mov    %ecx,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
mov    %r9d,-0x38(%rbp)
cmpq   $0x0,0x20(%rbp)
je     1207 <p3dBlobLabeling_ushort+0xc7>
mov    $0x0,%al
call   1060 <p3dResetStartTime@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
cmpl   $0x2c7,-0x38(%rbp)
jne    11a7 <p3dBlobLabeling_ushort+0x67>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
jmp    11d6 <p3dBlobLabeling_ushort+0x96>
cmpl   $0x2c8,-0x38(%rbp)
jne    11c5 <p3dBlobLabeling_ushort+0x85>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
jmp    11d1 <p3dBlobLabeling_ushort+0x91>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
jmp    11d6 <p3dBlobLabeling_ushort+0x96>
cmpl   $0x1,0x10(%rbp)
jne    11ec <p3dBlobLabeling_ushort+0xac>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
cmpl   $0x1,0x18(%rbp)
jne    1202 <p3dBlobLabeling_ushort+0xc2>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
jmp    1207 <p3dBlobLabeling_ushort+0xc7>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r14d
mov    -0x34(%rbp),%ebx
mov    -0x38(%rbp),%r11d
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
xor    %ecx,%ecx
mov    %ecx,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
call   1030 <p3dConnectedComponentsLabeling_ushort@plt>
cmp    $0x0,%rax
jne    125a <p3dBlobLabeling_ushort+0x11a>
jmp    129e <p3dBlobLabeling_ushort+0x15e>
cmpq   $0x0,0x20(%rbp)
je     1292 <p3dBlobLabeling_ushort+0x152>
mov    0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <p3dGetElapsedTime_min@plt>
mov    %eax,-0x44(%rbp)
mov    $0x0,%al
call   1040 <p3dGetElapsedTime_sec@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rcx
mov    %eax,%edx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   *%rcx
movl   $0x2,-0x14(%rbp)
jmp    12bc <p3dBlobLabeling_ushort+0x17c>
cmpq   $0x0,0x20(%rbp)
je     12b5 <p3dBlobLabeling_ushort+0x175>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   *0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<p3dBlobLabeling_ushort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebx
mov    %r8d,%eax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r12
mov    0x50(%rsp),%rbp
mov    0x48(%rsp),%r10d
mov    0x40(%rsp),%r11d
test   %rbp,%rbp
je     1244 <p3dBlobLabeling_ushort+0x104>
mov    %rax,(%rsp)
xor    %eax,%eax
call   1060 <p3dResetStartTime@plt>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   *%rbp
cmp    $0x2c8,%ebx
lea    0xea4(%rip),%rax
lea    0xeb5(%rip),%rcx
cmove  %rax,%rcx
cmp    $0x2c7,%ebx
lea    0xe75(%rip),%rdi
cmovne %rcx,%rdi
xor    %eax,%eax
call   *%rbp
mov    0x40(%rsp),%eax
cmp    $0x1,%eax
jne    11cc <p3dBlobLabeling_ushort+0x8c>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   *%rbp
mov    0x48(%rsp),%eax
cmp    $0x1,%eax
mov    %r14d,%r9d
jne    11ec <p3dBlobLabeling_ushort+0xac>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   *0x50(%rsp)
mov    0x48(%rsp),%eax
mov    %r14d,%r9d
sub    $0x8,%rsp
xor    %r14d,%r14d
mov    %r12,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
push   %rax
mov    0x50(%rsp),%eax
push   %rax
push   %rbx
push   0x20(%rsp)
push   %r15
call   1030 <p3dConnectedComponentsLabeling_ushort@plt>
add    $0x30,%rsp
test   %rax,%rax
je     1278 <p3dBlobLabeling_ushort+0x138>
xor    %eax,%eax
call   1050 <p3dGetElapsedTime_min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <p3dGetElapsedTime_sec@plt>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   *0x50(%rsp)
mov    $0x2,%r14d
jmp    1285 <p3dBlobLabeling_ushort+0x145>
sub    $0x8,%rsp
mov    %r12,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14d,%r9d
push   %r10
push   %r11
push   %rbx
push   %rax
push   %r15
call   1030 <p3dConnectedComponentsLabeling_ushort@plt>
add    $0x30,%rsp
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
add    %r14d,%r14d
jmp    1285 <p3dBlobLabeling_ushort+0x145>
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   *0x50(%rsp)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Pore3D - Performing blob labeling...\00"
@.str.1 = [23 x i8] c"\096-connectivity used. \00"
@.str.2 = [24 x i8] c"\0918-connectivity used. \00"
@.str.3 = [24 x i8] c"\0926-connectivity used. \00"
@.str.4 = [22 x i8] c"\09Random labels used. \00"
@.str.5 = [19 x i8] c"\09Borders skipped. \00"
@.str.6 = [60 x i8] c"Pore3D - Blob labeling performed successfully in %dm%0.3fs.\00"
@.str.7 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dBlobLabeling_ushort(i8* %0, i16* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 (i8*, ...)* %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i16*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32 (i8*, ...)*
store i8* %0, i8** %11
store i16* %1, i16** %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 (i8*, ...)* %8, i32 (i8*, ...)** %19
%20 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%21 = icmp ne i32 (i8*, ...)* %20, null
br i1 %21, label %22, label %54
22: ; preds = %9
%23 = call i32 (...) @p3dResetStartTime()
%24 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%25 = call i32 (i8*, ...) %24(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* %16
%27 = icmp eq i32 %26, 711
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%30 = call i32 (i8*, ...) %29(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %41
31: ; preds = %22
%32 = load i32, i32* %16
%33 = icmp eq i32 %32, 712
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%36 = call i32 (i8*, ...) %35(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %40
37: ; preds = %31
%38 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%39 = call i32 (i8*, ...) %38(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
br label %41
41: ; preds = %40, %28
%42 = load i32, i32* %17
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%46 = call i32 (i8*, ...) %45(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %44, %41
%48 = load i32, i32* %18
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%52 = call i32 (i8*, ...) %51(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %50, %47
br label %54
54: ; preds = %53, %9
%55 = load i8*, i8** %11
%56 = load i16*, i16** %12
%57 = load i32, i32* %13
%58 = load i32, i32* %14
%59 = load i32, i32* %15
%60 = load i32, i32* %16
%61 = load i32, i32* %17
%62 = load i32, i32* %18
%63 = call i64 @p3dConnectedComponentsLabeling_ushort(i8* %55, i16* %56, i32* null, i32* null, i32* null, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61, i32 %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %54
br label %75
66: ; preds = %54
%67 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%68 = icmp ne i32 (i8*, ...)* %67, null
br i1 %68, label %69, label %74
69: ; preds = %66
%70 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%71 = call i32 (...) @p3dGetElapsedTime_min()
%72 = call i32 (...) @p3dGetElapsedTime_sec()
%73 = call i32 (i8*, ...) %70(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i32 %71, i32 %72)
br label %74
74: ; preds = %69, %66
store i32 2, i32* %10
br label %82
75: ; preds = %65
%76 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%77 = icmp ne i32 (i8*, ...)* %76, null
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32 (i8*, ...)*, i32 (i8*, ...)** %19
%80 = call i32 (i8*, ...) %79(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0))
br label %81
81: ; preds = %78, %75
store i32 0, i32* %10
br label %82
82: ; preds = %81, %74
%83 = load i32, i32* %10
ret i32 %83
}

LLVM IR (-O2):
@.str = [37 x i8] c"Pore3D - Performing blob labeling...\00"
@.str.1 = [23 x i8] c"\096-connectivity used. \00"
@.str.2 = [24 x i8] c"\0918-connectivity used. \00"
@.str.3 = [24 x i8] c"\0926-connectivity used. \00"
@.str.4 = [22 x i8] c"\09Random labels used. \00"
@.str.5 = [19 x i8] c"\09Borders skipped. \00"
@.str.6 = [60 x i8] c"Pore3D - Blob labeling performed successfully in %dm%0.3fs.\00"
@.str.7 = [60 x i8] c"Pore3D - Not enough (contiguous) memory. Program will exit.\00"
define i32 @p3dBlobLabeling_ushort(i8* %0, i16* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 (i8*, ...)* %8) {
%10 = icmp eq i32 (i8*, ...)* %8, null
br i1 %10, label %29, label %11
11: ; preds = %9
%12 = tail call i32 (...) @p3dResetStartTime()
%13 = tail call i32 (i8*, ...) %8(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %5, 712
%15 = select i1 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0)
%16 = icmp eq i32 %5, 711
%17 = select i1 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %15
%18 = tail call i32 (i8*, ...) %8(i8* %17)
%19 = icmp eq i32 %6, 1
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = tail call i32 (i8*, ...) %8(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
%23 = icmp eq i32 %7, 1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 (i8*, ...) %8(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %22, %24
%27 = tail call i64 @p3dConnectedComponentsLabeling_ushort(i8* %0, i16* %1, i32* null, i32* null, i32* null, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7)
%28 = icmp eq i64 %27, 0
br i1 %28, label %37, label %33
29: ; preds = %9
%30 = tail call i64 @p3dConnectedComponentsLabeling_ushort(i8* %0, i16* %1, i32* null, i32* null, i32* null, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7)
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i32 0, i32 2
br label %39
33: ; preds = %26
%34 = tail call i32 (...) @p3dGetElapsedTime_min()
%35 = tail call i32 (...) @p3dGetElapsedTime_sec()
%36 = tail call i32 (i8*, ...) %8(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i32 %34, i32 %35)
br label %39
37: ; preds = %26
%38 = tail call i32 (i8*, ...) %8(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %29, %37, %33
%40 = phi i32 [ 2, %33 ], [ 0, %37 ], [ %32, %29 ]
ret i32 %40
}