// File: /workspace/github_cpp_makefile_star2_O3/spatialfruitsalad[P]volume2position/./watershed_segmentation.hpp
// Function: watershedSegmentation::find_label(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, tomogram3d<int>&, tomogram3d<float>&)
static int find_label (unsigned long nx, unsigned long ny, unsigned long nz, unsigned long i, unsigned long j, unsigned long k, tomogram3d<int>& clustermap, tomogram3d<float>& edm )
    {
        unsigned long imin = std::max (long(i -1), long(0));
        unsigned long imax = std::min (long(i +1), long (nx)-1);
        unsigned long jmin = std::max (long(j -1), long(0));
        unsigned long jmax = std::min (long(j +1), long (ny)-1);
        unsigned long kmin = std::max (long(k -1), long(0));
        unsigned long kmax = std::min (long(k +1), long (nz)-1);


        float grad = 0.;
        long grad_label = 0;
        unsigned long ii_s = 0, jj_s = 0, kk_s = 0;
        for (unsigned long ii = imin; ii <= imax; ++ii)
            for (unsigned long jj = jmin; jj <= jmax; ++jj)
                for (unsigned long kk = kmin; kk <= kmax; ++kk)
                {
                    float diff = edm.get(ii,jj,kk) - edm.get(i,j,k);
                    //float distance = sqrt(pow(float(ii-i),2)+pow(float(jj-j),2)+pow(float(kk-k),2));
                    float distance = sqrt(float((ii-i)*(ii-i) + (jj-j)*(jj-j) + (kk-k)*(kk-k)));
                    if (distance == 0) continue;
                    float slope = diff/distance;
                    if (slope > grad)
                    {
                        grad = slope;
                        grad_label = clustermap.get(ii,jj,kk);
                        ii_s = ii;
                        jj_s = jj;
                        kk_s = kk;
                    }
                }
        if (grad < 0.0001)
            return 0;
        else if (grad_label == 0)
            return find_label(nx,ny,nz,ii_s,jj_s,kk_s, clustermap, edm);
        else
            return grad_label;

    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %r15
decq %rdi
movq %rdi, 0x50(%rsp)
decq %rsi
movq %rsi, 0x58(%rsp)
decq %rdx
movq %rdx, 0x60(%rsp)
leaq -0x1(%rcx), %r12
testq %r12, %r12
movl $0x0, %edx
cmovleq %rdx, %r12
movq %rcx, 0x40(%rsp)
incq %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
cmovlq %rax, %rcx
leaq -0x1(%r15), %rbp
testq %rbp, %rbp
cmovleq %rdx, %rbp
leaq 0x1(%r15), %rsi
movq 0x58(%rsp), %rax
cmpq %rsi, %rax
cmovlq %rax, %rsi
movq %rsi, 0x18(%rsp)
leaq -0x1(%r9), %r13
testq %r13, %r13
movl $0x0, %eax
movq %rax, 0x10(%rsp)
cmovleq %rdx, %r13
leaq 0x1(%r9), %rdx
movq 0x60(%rsp), %rax
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, 0x70(%rsp)
cmpq %rcx, %r12
ja 0x11aed
movq %r9, 0x90(%rsp)
negq %r9
movq %r9, 0x88(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq %rbp, 0x68(%rsp)
movq %r13, 0x80(%rsp)
cmpq 0x18(%rsp), %rbp
ja 0x11aa1
movq %r12, %rax
subq 0x40(%rsp), %rax
imulq %rax, %rax
movq %rax, 0x78(%rsp)
cmpq 0x48(%rsp), %r13
ja 0x11a8b
movq %rbp, %r14
subq %r15, %r14
imulq %r14, %r14
addq 0x78(%rsp), %r14
movq 0xd8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xf342
movss %xmm0, 0xc(%rsp)
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movq %r15, %rdx
movq 0x90(%rsp), %rcx
callq 0xf342
movq 0x88(%rsp), %rax
addq %r13, %rax
imulq %rax, %rax
addq %r14, %rax
js 0x11a00
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x11a18
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
sqrtss %xmm1, %xmm1
ucomiss 0x5725(%rip), %xmm1     # 0x17148
jne 0x11a27
jnp 0x11a7d
movss 0xc(%rsp), %xmm2
subss %xmm0, %xmm2
movaps %xmm2, %xmm0
divss %xmm1, %xmm0
ucomiss 0x8(%rsp), %xmm0
jbe 0x11a7d
movq 0xd0(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movss %xmm0, 0xc(%rsp)
callq 0xcef2
cltq
movq %rax, 0x38(%rsp)
movq %r12, 0x20(%rsp)
movq %rbp, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
incq %r13
cmpq 0x48(%rsp), %r13
jbe 0x119ab
incq %rbp
cmpq 0x18(%rsp), %rbp
movq 0x80(%rsp), %r13
jbe 0x11991
incq %r12
cmpq 0x70(%rsp), %r12
movq 0x68(%rsp), %rbp
jbe 0x11975
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd 0x55b3(%rip), %xmm1     # 0x17078
ucomisd %xmm0, %xmm1
ja 0x11aed
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x118ac
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq