// File: 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:
subq $0x138, %rsp            # imm = 0x138
movq 0x148(%rsp), %rax
movq 0x140(%rsp), %rax
movq %rdi, 0x128(%rsp)
movq %rsi, 0x120(%rsp)
movq %rdx, 0x118(%rsp)
movq %rcx, 0x110(%rsp)
movq %r8, 0x108(%rsp)
movq %r9, 0x100(%rsp)
movq 0x110(%rsp), %rax
subq $0x1, %rax
movq %rax, 0xf0(%rsp)
movq $0x0, 0xe8(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x1cea0
movq (%rax), %rax
movq %rax, 0xf8(%rsp)
movq 0x110(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd8(%rsp)
movq 0x128(%rsp), %rax
subq $0x1, %rax
movq %rax, 0xd0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x1cee0
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0x108(%rsp), %rax
subq $0x1, %rax
movq %rax, 0xc0(%rsp)
movq $0x0, 0xb8(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x1cea0
movq (%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0x108(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
movq 0x120(%rsp), %rax
subq $0x1, %rax
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x1cee0
movq (%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0x100(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x1cea0
movq (%rax), %rax
movq %rax, 0x98(%rsp)
movq 0x100(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
movq 0x118(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x1cee0
movq (%rax), %rax
movq %rax, 0x80(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0xe0(%rsp), %rax
ja 0x18d9b
movq 0xc8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0xb0(%rsp), %rax
ja 0x18d86
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x80(%rsp), %rax
ja 0x18d71
movq 0x148(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x15be0
movss %xmm0, 0x18(%rsp)
movq 0x148(%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq 0x100(%rsp), %rcx
callq 0x15be0
movaps %xmm0, %xmm1
movss 0x18(%rsp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x2c(%rsp)
movq 0x40(%rsp), %rax
movq 0x110(%rsp), %rcx
subq %rcx, %rax
imulq %rax, %rax
movq 0x38(%rsp), %rcx
movq 0x108(%rsp), %rdx
subq %rdx, %rcx
imulq %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rsp), %rcx
movq 0x100(%rsp), %rdx
subq %rdx, %rcx
imulq %rcx, %rcx
addq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x1c(%rsp)
testq %rax, %rax
movss %xmm0, 0x20(%rsp)
js 0x18cc5
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3250
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movss 0x28(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x18cf0
jp 0x18cf0
jmp 0x18d5e
movss 0x2c(%rsp), %xmm0
divss 0x28(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x24(%rsp), %xmm0
ucomiss 0x6c(%rsp), %xmm0
jbe 0x18d5c
movss 0x24(%rsp), %xmm0
movss %xmm0, 0x6c(%rsp)
movq 0x140(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xefc0
cltq
movq %rax, 0x60(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x18d5e
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x18bdd
jmp 0x18d73
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x18bbd
jmp 0x18d88
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x18b9d
movss 0x6c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xf2cb(%rip), %xmm0     # 0x28078
ucomisd %xmm1, %xmm0
jbe 0x18dc0
movl $0x0, 0x134(%rsp)
jmp 0x18e22
cmpq $0x0, 0x60(%rsp)
jne 0x18e16
movq 0x128(%rsp), %rdi
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x48(%rsp), %r9
movq 0x140(%rsp), %r10
movq 0x148(%rsp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x18990
movl %eax, 0x134(%rsp)
jmp 0x18e22
movq 0x60(%rsp), %rax
movl %eax, 0x134(%rsp)
movl 0x134(%rsp), %eax
addq $0x138, %rsp            # imm = 0x138
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)