// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
xorl %r8d, %r8d
decq %rdi
decq %rsi
decq %rdx
movq %rdx, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
leaq -0x1(%rcx), %r15
testq %r15, %r15
cmovleq %r8, %r15
leaq 0x1(%rcx), %r10
cmpq %r10, %rdi
cmovlq %rdi, %r10
leaq -0x1(%rbp), %r13
testq %r13, %r13
cmovleq %r8, %r13
leaq 0x1(%rbp), %rax
cmpq %rax, %rsi
cmovlq %rsi, %rax
movq %rax, 0x28(%rsp)
leaq -0x1(%r9), %r12
testq %r12, %r12
cmovleq %r8, %r12
leaq 0x1(%r9), %rax
cmpq %rax, %rdx
cmovlq %rdx, %rax
movq %rax, 0x48(%rsp)
movb $0x1, %r11b
movl $0x0, %ebx
movl $0x0, %eax
movq %rax, 0x18(%rsp)
movl $0x0, %eax
movq %rax, 0x10(%rsp)
movl $0x0, %eax
movq %r10, 0x70(%rsp)
cmpq %r10, %r15
ja 0x11c4a
movq %rcx, 0x40(%rsp)
movq %r9, 0x90(%rsp)
negq %r9
movq %r9, 0x88(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x30(%rsp)
movq %r13, 0x68(%rsp)
movq %r12, 0x80(%rsp)
cmpq 0x28(%rsp), %r13
ja 0x11c02
movq %r15, %rax
subq 0x40(%rsp), %rax
imulq %rax, %rax
movq %rax, 0x78(%rsp)
cmpq 0x48(%rsp), %r12
ja 0x11bec
movq %r13, %rbx
subq %rbp, %rbx
imulq %rbx, %rbx
addq 0x78(%rsp), %rbx
movq 0xd8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0xf418
movss %xmm0, 0xc(%rsp)
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq %rbp, %rdx
movq 0x90(%rsp), %rcx
callq 0xf418
movaps %xmm0, %xmm2
movq 0x88(%rsp), %rax
addq %r12, %rax
imulq %rax, %rax
addq %rbx, %rax
js 0x11b48
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x11b60
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
ucomiss 0x55f1(%rip), %xmm0     # 0x17158
jb 0x11b6f
sqrtss %xmm0, %xmm0
jmp 0x11b80
movss %xmm2, 0x24(%rsp)
callq 0x3470
movss 0x24(%rsp), %xmm2
ucomiss 0x55d1(%rip), %xmm0     # 0x17158
jne 0x11b8b
jnp 0x11bde
movss 0xc(%rsp), %xmm1
subss %xmm2, %xmm1
divss %xmm0, %xmm1
ucomiss 0x8(%rsp), %xmm1
jbe 0x11bde
movq 0xd0(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
movss %xmm1, 0xc(%rsp)
callq 0xd03a
cltq
movq %rax, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
incq %r12
cmpq 0x48(%rsp), %r12
jbe 0x11af0
incq %r13
cmpq 0x28(%rsp), %r13
movq 0x80(%rsp), %r12
jbe 0x11ad6
incq %r15
cmpq 0x70(%rsp), %r15
movq 0x68(%rsp), %r13
jbe 0x11aba
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd 0x545a(%rip), %xmm1     # 0x17080
ucomisd %xmm0, %xmm1
seta %r11b
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
xorl %r8d, %r8d
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rbx
testb %r11b, %r11b
jne 0x11c67
movq %rbx, %rcx
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %r9
testq %rax, %rax
je 0x119ed
jmp 0x11c69
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop