// File: /workspace/github_cpp_makefile_star2_O3/kingufl[P]Rmapper/src/KDTree.cpp
// Function: KDTree::neighborhood_(std::shared_ptr<KDNode> const&, std::vector<int, std::allocator<int>> const&, int const&, unsigned long const&)
pointIndexArr KDTree::neighborhood_(  //
    const KDNodePtr &branch,          //
    const point_t &pt,                //
    const int &rad,                //
    const size_t &level               //
) {
    int d, dx, dx2;

    if (!bool(*branch)) {
        // branch has no point, means it is a leaf,
        // no points to add
        return pointIndexArr();
    }

    size_t dim = pt.size();

    int r2 = rad * rad;

//    d = disth(point_t(*branch), pt, rad);
    int nodeval=point_t(*branch).at(level);
    int pointval=pt.at(level);
    dx = abs(point_t(*branch).at(level) - pt.at(level));
//    dx2 = dx * dx;

    KDNodePtr section = branch->left;
    KDNodePtr other = branch->right;

    pointIndexArr nbh, nbh_s, nbh_o;
    if (dx <= rad) {
//        std::cout<<dx<<" "<<nodeval<<" "<<pointval<<" "<<rad<<" "<<level<<"\n";
        if(disth(point_t(*branch), pt, rad)>0)
            nbh.push_back(pointIndex(*branch));
        nbh_o = neighborhood_(other, pt, rad, (level + 1) % dim);
        nbh.insert(nbh.end(), nbh_o.begin(), nbh_o.end());
        nbh_s = neighborhood_(section, pt, rad, (level + 1) % dim);
        nbh.insert(nbh.end(), nbh_s.begin(), nbh_s.end());
    }
    else{

        if(nodeval<pointval){

            //search right branch
            nbh_o = neighborhood_(other, pt, rad, (level + 1) % dim);
            nbh.insert(nbh.end(), nbh_o.begin(), nbh_o.end());

        }
        else{
            //search left branch

            nbh_s = neighborhood_(section, pt, rad, (level + 1) % dim);
            nbh.insert(nbh.end(), nbh_s.begin(), nbh_s.end());

        }
    }

    return nbh;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, -0x78(%rbp)
movq (%rdx), %rsi
movq 0x8(%rsi), %rax
cmpq 0x10(%rsi), %rax
je 0x46a4
movq %r9, %r13
movq %rcx, %r15
movq %rdx, %r12
movq %r8, -0x38(%rbp)
movq %rdi, -0x30(%rbp)
addq $0x8, %rsi
movq 0x8(%rcx), %rbx
subq (%rcx), %rbx
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
callq 0x4e96
movq (%r13), %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4ac6
movl (%rdi,%rsi,4), %eax
movl %eax, -0x88(%rbp)
callq 0x3230
movq (%r13), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4ad4
movl (%rax,%rsi,4), %eax
movl %eax, -0x84(%rbp)
movq (%r12), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x4e96
movq (%r13), %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4ab8
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4ab8
movl (%rdi,%rsi,4), %ecx
subl (%rax,%rsi,4), %ecx
movl %ecx, %r14d
negl %r14d
cmovsl %ecx, %r14d
callq 0x3230
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0xc8(%rbp)
movq 0x28(%rax), %rcx
movq %rcx, -0xc0(%rbp)
testq %rcx, %rcx
je 0x46c2
movq 0x14926(%rip), %rdx     # 0x18fc0
cmpb $0x0, (%rdx)
je 0x46ba
incl 0x8(%rcx)
jmp 0x46c2
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rdi, %rax
jmp 0x4aa6
lock
incl 0x8(%rcx)
movq (%r12), %rax
movq 0x30(%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0xb0(%rbp)
testq %rax, %rax
je 0x46f2
movq 0x148dc(%rip), %rcx     # 0x18fc0
cmpb $0x0, (%rcx)
je 0x46ee
incl 0x8(%rax)
jmp 0x46f2
lock
incl 0x8(%rax)
sarq $0x2, %rbx
xorps %xmm0, %xmm0
movq -0x30(%rbp), %rcx
movups %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
movq %rax, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movq %rax, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movq -0x38(%rbp), %rax
cmpl (%rax), %r14d
movq %rax, %r14
jle 0x47ce
movl -0x84(%rbp), %eax
cmpl %eax, -0x88(%rbp)
jge 0x485f
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe0(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x457c
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
leaq -0xe0(%rbp), %r14
movaps (%r14), %xmm1
movaps %xmm1, -0x50(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x40(%rbp)
leaq -0xa8(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4f16
movq %r14, %rdi
callq 0x4f16
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fbe
jmp 0x4a6f
movq (%r12), %rsi
addq $0x8, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x4e96
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rax
subq %rdi, %rax
je 0x48f5
sarq $0x2, %rax
movl (%r14), %ecx
movq (%r15), %rdx
cmpq $0x1, %rax
movq %rax, %rsi
adcq $0x0, %rsi
movl (%rdi), %r8d
subl (%rdx), %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %ecx, %r9d
jg 0x494f
movl $0x1, %r8d
cmpq %r8, %rsi
je 0x48fa
movl (%rdi,%r8,4), %r9d
subl (%rdx,%r8,4), %r9d
movl %r9d, %r10d
negl %r10d
cmovsl %r9d, %r10d
incq %r8
cmpl %ecx, %r10d
jbe 0x482d
decq %r8
cmpq %rax, %r8
setb %r14b
jmp 0x4906
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe0(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x457c
movaps -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
leaq -0xe0(%rbp), %r14
movaps (%r14), %xmm1
movaps %xmm1, -0x70(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x60(%rbp)
leaq -0xa8(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4f16
movq %r14, %rdi
callq 0x4f16
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fbe
jmp 0x4a6f
xorl %r14d, %r14d
jmp 0x4901
cmpq %rax, %r8
setb %r14b
testq %rdi, %rdi
je 0x490b
callq 0x3230
testb %r14b, %r14b
movq -0x38(%rbp), %r14
jne 0x4954
movq (%r12), %r14
leaq 0x8(%r14), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x4e96
movq (%r14), %rax
leaq -0xa8(%rbp), %rsi
movq %rax, 0x18(%rsi)
movq -0x30(%rbp), %rdi
callq 0x5daa
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
movq -0x38(%rbp), %r14
je 0x4954
callq 0x3230
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe0(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
movq -0x78(%rbp), %r12
movq %r12, %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x457c
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
leaq -0xe0(%rbp), %r14
movaps (%r14), %xmm1
movaps %xmm1, -0x50(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x40(%rbp)
leaq -0xa8(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4f16
movq %r14, %rdi
callq 0x4f16
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x5fbe
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe0(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
movq %r12, %rsi
movq %r15, %rcx
movq -0x38(%rbp), %r8
callq 0x457c
movaps -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
movaps (%r14), %xmm1
movaps %xmm1, -0x70(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x60(%rbp)
leaq -0xa8(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4f16
movq %r14, %rdi
callq 0x4f16
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fbe
leaq -0x50(%rbp), %rdi
callq 0x4f16
leaq -0x70(%rbp), %rdi
callq 0x4f16
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4a92
callq 0x50cc
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x4aa3
callq 0x50cc
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe561(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
leaq 0xe553(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
leaq 0xe545(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
movq %rax, %r14
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x4b0d
callq 0x3230
jmp 0x4b0d
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
jmp 0x4b0a
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x4f16
leaq -0x70(%rbp), %rdi
callq 0x4f16
movq -0x30(%rbp), %rdi
callq 0x4f16
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4b39
callq 0x50cc
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x4b62
callq 0x50cc
jmp 0x4b62
jmp 0x4b4e
movq %rax, %r14
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x4b62
callq 0x3230
movq %r14, %rdi
callq 0x33d0