// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %rbp
decq %rdi
movq %rdi, 0x30(%rsp)
decq %rsi
movq %rsi, 0x38(%rsp)
decq %rdx
movq %rdx, 0x40(%rsp)
leaq -0x1(%rbp), %rsi
testq %rsi, %rsi
movl $0x0, %ecx
cmovleq %rcx, %rsi
leaq 0x1(%rbp), %rdx
movq 0x30(%rsp), %rax
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq %rdx, 0x50(%rsp)
leaq -0x1(%r14), %rax
testq %rax, %rax
cmovleq %rcx, %rax
movq %rax, 0x48(%rsp)
leaq 0x1(%r14), %rdx
movq 0x38(%rsp), %rax
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq %rdx, 0x68(%rsp)
leaq -0x1(%rbx), %rax
testq %rax, %rax
cmovleq %rcx, %rax
movq %rax, 0x58(%rsp)
leaq 0x1(%rbx), %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, 0x80(%rsp)
movq %rbx, %rax
negq %rax
movq %rax, 0x70(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x28(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
cmpq 0x50(%rsp), %rsi
ja 0xd0d8
movq %rsi, %rax
subq %rbp, %rax
imulq %rax, %rax
movq %rax, 0x60(%rsp)
movq 0x48(%rsp), %rdx
movq %rsi, 0x8(%rsp)
cmpq 0x68(%rsp), %rdx
ja 0xd0d0
movq %rdx, %rax
subq %r14, %rax
imulq %rax, %rax
addq 0x60(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %r12
cmpq 0x80(%rsp), %r12
ja 0xd0c8
movq %r14, %r15
movq %rbp, %r14
movq 0xc8(%rsp), %rbp
movq %rbp, %rdi
movq %rdx, %r13
movq %r12, %rcx
callq 0xb5c2
movss %xmm0, 0x4(%rsp)
movq %rbp, %rdi
movq %r14, %rbp
movq %r15, %r14
movq %rbp, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xb5c2
movq 0x70(%rsp), %rax
addq %r12, %rax
imulq %rax, %rax
addq 0x78(%rsp), %rax
js 0xd036
cvtsi2ss %rax, %xmm1
jmp 0xd04b
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
sqrtss %xmm1, %xmm1
ucomiss 0x40f2(%rip), %xmm1     # 0x11148
movq 0x8(%rsp), %rsi
movq %r13, %rdx
jne 0xd062
jnp 0xd0c0
movss 0x4(%rsp), %xmm2
subss %xmm0, %xmm2
movaps %xmm2, %xmm0
divss %xmm1, %xmm0
ucomiss (%rsp), %xmm0
jbe 0xd0c0
movq 0xc0(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movss %xmm0, 0x4(%rsp)
callq 0x9746
movq %r13, %rdx
movq 0x8(%rsp), %rsi
cltq
movq %rax, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rsp)
incq %r12
jmp 0xcfd5
incq %rdx
jmp 0xcfb1
incq %rsi
jmp 0xcf8d
cvtss2sd (%rsp), %xmm0
movsd 0x3f93(%rip), %xmm1     # 0x11078
ucomisd %xmm0, %xmm1
ja 0xd10a
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbx
movq 0x28(%rsp), %rax
testq %rax, %rax
je 0xcee4
jmp 0xd10c
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq