// File: /workspace/github_cpp_makefile_star2_O2/spatialfruitsalad[P]volume2position/./hk.hpp
// Function: HoshenKopelman::Process(tomogram3d<unsigned char>&, tomogram3d<int>&)
static void Process (tomogram3d <uint8_t>& matrix_in, tomogram3d<int>& out) {
        // code by fabian.
        std::cout << "start hoshen_kopelman ... " << std::flush;

        std::vector <int> rename;

        int nx = matrix_in.get_sx();
        int ny = matrix_in.get_sy();
        int nz = matrix_in.get_sz();

        // initialise
        rename.clear ();
        rename.push_back (0);
        out.clear();
        out.initialise (nx, ny, nz, 0);

        for (int k = 0; k != nz; ++k){
            for (int j = 0; j != ny; ++j)
                for (int i = 0; i != nx; ++i){
                    if (voxset (i,j,k,matrix_in)) {
                        int imin = std::max (i-1, 0);
                        int imax = std::min (i+1, int (nx-1));
                        int jmin = std::max (j-1, 0);
                        int jmax = std::min (j+1, int (ny-1));
                        int kmin = std::max (k-1, 0);
                        int kmax = std::min (k+1, int (nz-1));
                        int cluster_id = rename.size (); // possibly start a new cluster.

                        // this is all very suboptimal, but coding it the
                        // _right_ way generates a 100-line if-then-else block.
                        for (int ii = imin; ii <= imax; ++ii)
                            for (int jj = jmin; jj <= jmax; ++jj)
                                for (int kk = kmin; kk <= kmax; ++kk) {
                                    if (voxset (ii,jj,kk,matrix_in) && out.get(ii,jj,kk) != 0) {
                                        int oclid = lookup (out.get(ii,jj,kk),rename);
                                        if (cluster_id == (int)rename.size ())
                                            cluster_id = oclid;
                                        else if (cluster_id != oclid)
                                            cluster_id = merge_clusters (oclid, cluster_id, rename);
                                    }
                                }

                        // start a new cluster
                        if (cluster_id == (int)rename.size ())
                            rename.push_back (cluster_id);

                        out.set(i,j,k,cluster_id);
                    }
                }
        }

        int newindex = 0;
        for (int i = 0; i != (int)rename.size (); ++i)
            if (rename.at(i) >= 0)
                rename.at(i) = newindex++;

        // resolve all indirections in the indirection map
        for (int i = 0; i != (int)rename.size (); ++i)
            rename[i] = lookup (i, rename);

        // resolve the indirections on the facing planes
        // in the cluster map (other data is not needed)
    //    rename.insert (rename.begin (), -1);
        for (int i = 0; i != nx; ++i)
        for (int j = 0; j != ny; ++j)
        for (int k = 0; k != nz; ++k)
            out.set(i,j,k, rename[out.get(i,j,k)]);

        std::cout << " done" << std::endl;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0xb8ac(%rip), %rdi      # 0x17fc8
leaq 0x51f9(%rip), %rsi      # 0x1191c
callq 0x3260
movq %rax, %rdi
callq 0x31b0
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
andq $0x0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movq 0x18(%r14), %r15
movq 0x20(%r14), %r12
movq 0x28(%r14), %r13
leaq 0xc(%rsp), %rsi
andl $0x0, (%rsi)
callq 0xdfb2
movl %r15d, %eax
movq %rax, 0x38(%rsp)
movl %r12d, %eax
movq %rax, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movl %r13d, %eax
movq %rax, 0x40(%rsp)
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0xc783
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
andq $0x0, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
movslq 0x38(%rsp), %rsi
movslq 0x30(%rsp), %rdx
movslq 0x40(%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0xa6f4
decl %r15d
decl %r12d
movq 0x28(%rsp), %rax
decl %eax
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %rbp
movq %r15, 0x70(%rsp)
movq %r12, 0x60(%rsp)
cmpl $0x2, %ecx
movl %ebp, %eax
cmovgel %ecx, %eax
cmpq 0x40(%rsp), %rcx
je 0xc9d3
decq %rax
movq %rax, 0x98(%rsp)
leaq 0x1(%rcx), %rax
movq 0x28(%rsp), %rdx
cmpl %eax, %edx
movq %rax, 0x58(%rsp)
cmovll %edx, %eax
movslq %eax, %r12
xorl %eax, %eax
movq %rcx, 0x48(%rsp)
cmpl $0x2, %eax
movl %ebp, %edx
cmovgel %eax, %edx
decq %rdx
movq %rdx, 0x88(%rsp)
cmpq 0x30(%rsp), %rax
je 0xc9c9
movq %rax, 0x50(%rsp)
incq %rax
movq 0x60(%rsp), %rcx
cmpl %eax, %ecx
movq %rax, 0x68(%rsp)
cmovll %ecx, %eax
cltq
movq %rax, 0xa0(%rsp)
xorl %r13d, %r13d
cmpl $0x2, %r13d
movl %ebp, %r15d
cmovgel %r13d, %r15d
decq %r15
cmpq 0x38(%rsp), %r13
je 0xc9bf
movl %r13d, %edi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rcx
callq 0xdf0a
movq %r13, 0x80(%rsp)
incq %r13
testb %al, %al
je 0xc847
movq 0x70(%rsp), %rcx
cmpl %r13d, %ecx
movq %r13, 0x78(%rsp)
movl %r13d, %eax
cmovll %ecx, %eax
movq 0x18(%rsp), %rcx
subq 0x10(%rsp), %rcx
shrq $0x2, %rcx
movl %ecx, 0xc(%rsp)
cltq
movq %rax, 0x90(%rsp)
cmpq 0x90(%rsp), %r15
jg 0xc96c
movq 0x88(%rsp), %rbp
cmpq 0xa0(%rsp), %rbp
jg 0xc961
movq 0x98(%rsp), %r13
cmpq %r12, %r13
jg 0xc959
movl %r15d, %edi
movl %ebp, %esi
movl %r13d, %edx
movq %r14, %rcx
callq 0xdf0a
testb %al, %al
je 0xc954
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x9746
testl %eax, %eax
je 0xc954
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x9746
movl %eax, %edi
leaq 0x10(%rsp), %rsi
callq 0xdf2c
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rcx
subq 0x10(%rsp), %rcx
shrq $0x2, %rcx
cmpl %ecx, %esi
je 0xc950
cmpl %eax, %esi
je 0xc954
movl %eax, %edi
leaq 0x10(%rsp), %rdx
callq 0xdf6a
movl %eax, 0xc(%rsp)
incq %r13
jmp 0xc8df
incq %rbp
jmp 0xc8c9
incq %r15
pushq $0x1
popq %rbp
jmp 0xc8b3
movl 0xc(%rsp), %r8d
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
shrq $0x2, %rax
cmpl %eax, %r8d
movq 0x48(%rsp), %r15
jne 0xc99d
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xa83c
movl 0xc(%rsp), %r8d
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r15, %rcx
callq 0xa85a
movq 0x78(%rsp), %r13
jmp 0xc847
movq 0x68(%rsp), %rax
jmp 0xc805
movq 0x58(%rsp), %rcx
jmp 0xc7ca
xorl %r14d, %r14d
leaq 0x10(%rsp), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rax, %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
movl %edx, %edx
cmpq %rdx, %r14
je 0xca1c
movq %r15, %rdi
movq %r14, %rsi
callq 0xaaee
cmpl $0x0, (%rax)
js 0xca17
movq %r15, %rdi
movq %r14, %rsi
callq 0xaaee
movl %ebp, (%rax)
incl %ebp
incq %r14
jmp 0xc9dd
xorl %r14d, %r14d
leaq 0x10(%rsp), %r15
subq %rcx, %rax
shrq $0x2, %rax
movl %eax, %eax
cmpq %rax, %r14
je 0xca50
movl %r14d, %edi
movq %r15, %rsi
callq 0xdf2c
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r14,4)
incq %r14
movq 0x18(%rsp), %rax
jmp 0xca24
xorl %r14d, %r14d
cmpq 0x38(%rsp), %r14
je 0xcaaa
xorl %r15d, %r15d
cmpq 0x30(%rsp), %r15
je 0xcaa5
xorl %r12d, %r12d
cmpq %r12, 0x40(%rsp)
je 0xcaa0
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x9746
cltq
movq 0x10(%rsp), %rcx
movl (%rcx,%rax,4), %r8d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa85a
incq %r12
jmp 0xca67
incq %r15
jmp 0xca5d
incq %r14
jmp 0xca53
movq 0xb517(%rip), %rdi      # 0x17fc8
leaq 0x4dca(%rip), %rsi      # 0x11882
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x10(%rsp), %rdi
callq 0xb1c8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
jmp 0xcaf3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xb1c8
movq %rbx, %rdi
callq 0x3420