// File: /workspace/github_cpp_makefile_star2_O2/spatialfruitsalad[P]volume2position/./remove_inside_holes_2.hpp
// Function: removeInsideHoles::Process(tomogram3d<unsigned char>&)
static void Process (tomogram3d <uint8_t> & matrix_in)
    {
        std::cout << "removing inside holes ... " << std::flush;

        tomogram3d<int> clustermap;

        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 ();

        clustermap.initialise (nx, ny, nz, -1);

        // this is basically hoshen kopelman for the black clusters
        for (int k = 0; k != nz; ++k)
        {
            for (int j = 0; j != ny; ++j)
                for (int i = 0; i != nx; ++i)
                {
                    if (voxset_in_2 (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.


                        int pos[6][3] = {{imin,j,k},{imax,j,k},{i,jmin,k},{i,jmax,k},{i,j,kmin},{i,j,kmax}};
                        for (int a = 0; a < 6; ++a)
                        {
//                        std::cout << "a = " << a << std::endl;
                            int ii = pos[a][0];
                            int jj = pos[a][1];
                            int kk = pos[a][2];
//                        std::cout << "ii = " << ii << "  jj = " << jj << "  kk = " << kk << std::endl;
                            if (voxset_in_2 (ii,jj,kk,matrix_in) && clustermap.get(ii,jj,kk) != -1)
                            {
                                int oclid = lookup_in_2 (clustermap.get(ii,jj,kk),rename);
                                if (cluster_id == (int)rename.size ())
                                    cluster_id = oclid;
                                else if (cluster_id != oclid)
                                    cluster_id = merge_clusters_in_2 (oclid, cluster_id, rename);
                            }
                        }



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

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



        // resolve all indirections in the indirection map
        for (int i = 0; i != (int)rename.size (); ++i)
            rename[i] = lookup_in_2 (i, rename);
        int max_clustercount = 0;
        // 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)
                {
                    if(rename[clustermap.get(i,j,k)+1] > max_clustercount) max_clustercount = rename[clustermap.get(i,j,k)+1];
                    clustermap.set(i,j,k, rename[clustermap.get(i,j,k)+1]);
                }
        rename.erase (rename.begin ());

        std::vector<int> clustersizes (max_clustercount + 1);
        for (int k = 0; k != nz; ++k)
            for (int j = 0; j != ny; ++j)
                for (int i = 0; i != nx; ++i)
                {
                    if (clustermap.get(i,j,k) >= 0)
                    {
                        clustersizes.at(clustermap.get(i,j,k))++;
                    }
                }


        tomogram3d <uint8_t> matrix_out;
        matrix_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)
        {
            bool fill = false;
            if (clustermap.get(i,j,k) == -1) 
            {
                fill = true;
            }

            else if (clustermap.get(i,j,k) > 0 && clustersizes.at(clustermap.get(i,j,k)) < 100000) 
            {
                fill = true;
            }

            if(fill == true)
            {
                matrix_out.set(i,j,k,1);
            }
        }


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

        std::swap (matrix_in, matrix_out);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %rbx
movq 0x105d5(%rip), %rdi     # 0x17fc8
leaq 0x9d6e(%rip), %rsi      # 0x11768
callq 0x3260
movq %rax, %rdi
callq 0x31b0
leaq 0x100(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rsp)
movaps %xmm0, (%rdi)
movaps %xmm0, (%rsp)
movl 0x18(%rbx), %r15d
movl 0x20(%rbx), %r14d
movq %rbx, 0x40(%rsp)
movl 0x28(%rbx), %ebx
movslq %r15d, %rsi
movslq %r14d, %rdx
movslq %ebx, %rcx
pushq $-0x1
popq %r8
movq %rsi, 0xe0(%rsp)
movq %rdx, 0xd8(%rsp)
movq %rcx, 0xd0(%rsp)
callq 0xa6f4
leal -0x1(%r15), %eax
movl %eax, 0x6c(%rsp)
movq %r14, 0x18(%rsp)
leal -0x1(%r14), %eax
movl %eax, 0x68(%rsp)
movq %rbx, 0x20(%rsp)
leal -0x1(%rbx), %eax
movl %eax, 0x64(%rsp)
xorl %eax, %eax
movq %r15, 0x28(%rsp)
cmpq 0x20(%rsp), %rax
je 0x7d11
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
decl %ecx
movl %ecx, 0x74(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x1(%rax), %rcx
movl 0x64(%rsp), %eax
cmpl %ecx, %eax
movq %rcx, 0xe8(%rsp)
cmovll %eax, %ecx
movl %ecx, 0x70(%rsp)
xorl %ecx, %ecx
cmpq 0x18(%rsp), %rcx
je 0x7d04
cmpl $0x2, %ecx
pushq $0x1
popq %rax
cmovgel %ecx, %eax
decl %eax
movl %eax, 0x7c(%rsp)
movq %rcx, 0x38(%rsp)
incq %rcx
movl 0x68(%rsp), %eax
cmpl %ecx, %eax
movq %rcx, 0xf0(%rsp)
cmovll %eax, %ecx
movl %ecx, 0x78(%rsp)
xorl %r14d, %r14d
cmpq %r15, %r14
je 0x7cf7
movl %r14d, %edi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0xa7d4
testb %al, %al
je 0x7c9a
cmpl $0x2, %r14d
pushq $0x1
popq %rax
cmovgel %r14d, %eax
decl %eax
leaq 0x1(%r14), %rcx
movl 0x6c(%rsp), %edx
cmpl %ecx, %edx
movq %rcx, 0xf8(%rsp)
cmovll %edx, %ecx
movq 0x8(%rsp), %rdx
subq (%rsp), %rdx
shrq $0x2, %rdx
movl %edx, 0x48(%rsp)
movl %eax, 0x80(%rsp)
movq 0x38(%rsp), %rdx
movl %edx, 0x84(%rsp)
movq 0x30(%rsp), %rax
movl %eax, 0x88(%rsp)
movl %ecx, 0x8c(%rsp)
movl %edx, 0x90(%rsp)
movl %eax, 0x94(%rsp)
movl %r14d, 0x98(%rsp)
movl 0x7c(%rsp), %ecx
movl %ecx, 0x9c(%rsp)
movl %eax, 0xa0(%rsp)
movl %r14d, 0xa4(%rsp)
movl 0x78(%rsp), %ecx
movl %ecx, 0xa8(%rsp)
movl %eax, 0xac(%rsp)
movl %r14d, 0xb0(%rsp)
movl %edx, 0xb4(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0xb8(%rsp)
movl %r14d, 0xbc(%rsp)
movl %edx, 0xc0(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0xc4(%rsp)
pushq $0x8
popq %r15
cmpq $0x50, %r15
je 0x7ca2
movl 0x78(%rsp,%r15), %ebp
movl 0x7c(%rsp,%r15), %r12d
movl 0x80(%rsp,%r15), %ebx
movl %ebp, %edi
movl %r12d, %esi
movl %ebx, %edx
movq 0x40(%rsp), %rcx
callq 0xa7d4
testb %al, %al
je 0x7c91
movslq %ebp, %rbp
movslq %r12d, %r13
movslq %ebx, %r12
leaq 0x100(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x9746
cmpl $-0x1, %eax
je 0x7c91
leaq 0x100(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x9746
movl %eax, %edi
movq %rsp, %rsi
callq 0xa7f6
movl 0x48(%rsp), %esi
movq 0x8(%rsp), %rcx
subq (%rsp), %rcx
shrq $0x2, %rcx
cmpl %ecx, %esi
je 0x7c8d
cmpl %eax, %esi
je 0x7c91
movl %eax, %edi
movq %rsp, %rdx
callq 0xa812
movl %eax, 0x48(%rsp)
addq $0xc, %r15
jmp 0x7bf5
incq %r14
jmp 0x7afa
movl 0x48(%rsp), %r8d
movq 0x8(%rsp), %rax
subq (%rsp), %rax
shrq $0x2, %rax
cmpl %eax, %r8d
movq 0x28(%rsp), %r15
jne 0x7cd0
movq %rsp, %rdi
leaq 0x48(%rsp), %rsi
callq 0xa83c
movl 0x48(%rsp), %r8d
leaq 0x100(%rsp), %rdi
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xa85a
movq 0xf8(%rsp), %r14
jmp 0x7afa
movq 0xf0(%rsp), %rcx
jmp 0x7ac0
movq 0xe8(%rsp), %rax
jmp 0x7a86
movq %rsp, %r14
movq (%r14), %rsi
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
subq %rsi, %rax
shrq $0x2, %rax
movl %eax, %eax
cmpq %rax, %r15
je 0x7d45
movl %r15d, %edi
movq %r14, %rsi
callq 0xa7f6
movq (%rsp), %rsi
movl %eax, (%rsi,%r15,4)
incq %r15
jmp 0x7d1a
leaq 0x80(%rsp), %rdx
orl $-0x1, (%rdx)
movq %rsp, %rdi
callq 0xb044
xorl %r14d, %r14d
leaq 0x100(%rsp), %r15
xorl %ebx, %ebx
cmpq 0x28(%rsp), %r14
je 0x7dfb
xorl %r12d, %r12d
cmpq 0x18(%rsp), %r12
je 0x7df3
xorl %r13d, %r13d
cmpq %r13, 0x20(%rsp)
je 0x7dee
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x9746
movq (%rsp), %rcx
cltq
cmpl %ebx, 0x4(%rcx,%rax,4)
jle 0x7dbc
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x9746
movq (%rsp), %rcx
cltq
movl 0x4(%rcx,%rax,4), %ebx
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x9746
movq (%rsp), %rcx
cltq
movl 0x4(%rcx,%rax,4), %r8d
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xa85a
incq %r13
jmp 0x7d7d
incq %r12
jmp 0x7d73
incq %r14
jmp 0x7d65
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x7e1a
subq %rsi, %rdx
callq 0x33b0
movq 0x8(%rsp), %rdx
addq $-0x4, %rdx
movq %rdx, 0x8(%rsp)
incl %ebx
movslq %ebx, %rsi
leaq 0x48(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0xaa9c
xorl %r14d, %r14d
leaq 0x100(%rsp), %r15
leaq 0x48(%rsp), %r12
cmpq 0x20(%rsp), %r14
je 0x7ea6
xorl %r13d, %r13d
cmpq 0x18(%rsp), %r13
je 0x7ea1
xorl %ebp, %ebp
cmpq %rbp, 0x28(%rsp)
je 0x7e9c
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x9746
testl %eax, %eax
js 0x7e97
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x9746
movslq %eax, %rsi
movq %r12, %rdi
callq 0xaaee
incl (%rax)
incq %rbp
jmp 0x7e5d
incq %r13
jmp 0x7e54
incq %r14
jmp 0x7e4a
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0xe0(%rsp), %rsi
movq 0xd8(%rsp), %rdx
movq 0xd0(%rsp), %rcx
xorl %r8d, %r8d
callq 0x6fda
xorl %r14d, %r14d
leaq 0x100(%rsp), %r15
leaq 0x80(%rsp), %rbx
pushq $0x1
popq %rbp
cmpq 0x20(%rsp), %r14
je 0x7f85
xorl %r13d, %r13d
cmpq 0x18(%rsp), %r13
je 0x7f7d
xorl %r12d, %r12d
cmpq %r12, 0x28(%rsp)
je 0x7f78
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x9746
cmpl $-0x1, %eax
je 0x7f5f
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x9746
testl %eax, %eax
jle 0x7f73
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x9746
movslq %eax, %rsi
leaq 0x48(%rsp), %rdi
callq 0xaaee
cmpl $0x1869f, (%rax)        # imm = 0x1869F
jg 0x7f73
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
callq 0x72fc
incq %r12
jmp 0x7f07
incq %r13
jmp 0x7efd
incq %r14
jmp 0x7eef
movq 0x1003c(%rip), %rdi     # 0x17fc8
leaq 0x98ef(%rip), %rsi      # 0x11882
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x80(%rsp), %rbx
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xab0f
movq %rbx, %rdi
callq 0xb29a
leaq 0x48(%rsp), %rdi
callq 0xb1c8
movq %rsp, %rdi
callq 0xb1c8
leaq 0x100(%rsp), %rdi
callq 0xb1c8
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8021
jmp 0x8021
jmp 0x8021
jmp 0x8001
jmp 0x8021
jmp 0x8021
jmp 0x8021
movq %rax, %rbx
jmp 0x8011
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb29a
leaq 0x48(%rsp), %rdi
callq 0xb1c8
jmp 0x8024
jmp 0x8021
jmp 0x8021
movq %rax, %rbx
movq %rsp, %rdi
callq 0xb1c8
leaq 0x100(%rsp), %rdi
callq 0xb1c8
movq %rbx, %rdi
callq 0x3420
nop