// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %r8, -0x38(%rbp)
movq %rsi, -0x78(%rbp)
movq (%rdx), %rsi
movq 0x8(%rsi), %rax
cmpq 0x10(%rsi), %rax
je 0x4680
movq %r9, %r13
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, -0x30(%rbp)
addq $0x8, %rsi
movq 0x8(%rcx), %rbx
subq (%rcx), %rbx
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x4e70
movq (%r13), %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4aad
movl (%rdi,%rsi,4), %eax
movl %eax, -0x88(%rbp)
testq %rdi, %rdi
je 0x45d0
callq 0x3230
movq (%r13), %rsi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4abb
movl (%rax,%rsi,4), %eax
movl %eax, -0x84(%rbp)
movq (%r12), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x4e70
movq (%r13), %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rdx
subq %rdi, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4a9f
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x4a9f
movl (%rdi,%rsi,4), %ecx
subl (%rax,%rsi,4), %ecx
movl %ecx, %r14d
negl %r14d
cmovsl %ecx, %r14d
testq %rdi, %rdi
je 0x4650
callq 0x3230
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0xc8(%rbp)
testq %rax, %rax
je 0x469a
movq 0x1494a(%rip), %rcx     # 0x18fc0
cmpb $0x0, (%rcx)
je 0x4696
incl 0x8(%rax)
jmp 0x469a
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rdi, %rax
jmp 0x4a8d
lock
incl 0x8(%rax)
movq (%r12), %rax
movq 0x30(%rax), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0xb8(%rbp)
testq %rax, %rax
je 0x46ce
movq 0x14900(%rip), %rcx     # 0x18fc0
cmpb $0x0, (%rcx)
je 0x46ca
incl 0x8(%rax)
jmp 0x46ce
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
jle 0x47ae
movl -0x84(%rbp), %eax
cmpl %eax, -0x88(%rbp)
jge 0x4816
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe8(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq %r15, %rcx
movq -0x38(%rbp), %r8
callq 0x454e
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
leaq -0xe8(%rbp), %r14
movups (%r14), %xmm1
movaps %xmm1, -0x50(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x40(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4ef0
movq %r14, %rdi
callq 0x4ef0
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fc8
jmp 0x4a56
movq (%r12), %rsi
addq $0x8, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x4e70
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rax
subq %rdi, %rax
sete %r14b
je 0x48e3
sarq $0x2, %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %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
jle 0x48b3
xorl %r14d, %r14d
jmp 0x48e3
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe8(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq %r15, %rcx
movq -0x38(%rbp), %r8
callq 0x454e
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
leaq -0xe8(%rbp), %r14
movups (%r14), %xmm1
movaps %xmm1, -0x70(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x60(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4ef0
movq %r14, %rdi
callq 0x4ef0
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fc8
jmp 0x4a56
movl $0x1, %r9d
movq %r9, %r8
cmpq %r9, %rsi
je 0x48dc
movl (%rdi,%r8,4), %r9d
subl (%rdx,%r8,4), %r9d
movl %r9d, %r10d
negl %r10d
cmovsl %r9d, %r10d
leaq 0x1(%r8), %r9
cmpl %ecx, %r10d
jle 0x48b9
cmpq %rax, %r8
setae %r14b
testq %rdi, %rdi
je 0x48ed
callq 0x3230
testb %r14b, %r14b
je 0x492e
movq (%r12), %r14
leaq 0x8(%r14), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x4e70
movq (%r14), %rax
leaq -0xb0(%rbp), %rsi
movq %rax, 0x18(%rsi)
movq -0x30(%rbp), %rdi
callq 0x5db4
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x492e
callq 0x3230
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe8(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
movq -0x78(%rbp), %r12
movq %r12, %rsi
movq %r15, %rcx
movq -0x38(%rbp), %r8
callq 0x454e
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
leaq -0xe8(%rbp), %r14
movups (%r14), %xmm1
movaps %xmm1, -0x50(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x40(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4ef0
movq %r14, %rdi
callq 0x4ef0
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x5fc8
movq (%r13), %rax
incq %rax
xorl %edx, %edx
divq %rbx
leaq -0x80(%rbp), %r9
movq %rdx, (%r9)
leaq -0xe8(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
movq %r12, %rsi
movq %r15, %rcx
movq -0x38(%rbp), %r8
callq 0x454e
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x70(%rbp), %xmm0
movq -0x60(%rbp), %rax
movups (%r14), %xmm1
movaps %xmm1, -0x70(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, -0x60(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0x4ef0
movq %r14, %rdi
callq 0x4ef0
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq %rbx, %rdi
callq 0x5fc8
leaq -0x50(%rbp), %rdi
callq 0x4ef0
leaq -0x70(%rbp), %rdi
callq 0x4ef0
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x4a79
callq 0x508e
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x4a8a
callq 0x508e
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe57a(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
leaq 0xe56c(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
leaq 0xe55e(%rip), %rdi      # 0x13020
xorl %eax, %eax
callq 0x3330
movq %rax, %r14
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4af4
callq 0x3230
jmp 0x4af4
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
jmp 0x4af1
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x4ef0
leaq -0x70(%rbp), %rdi
callq 0x4ef0
movq -0x30(%rbp), %rdi
callq 0x4ef0
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x4b20
callq 0x508e
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x4b49
callq 0x508e
jmp 0x4b49
jmp 0x4b35
movq %rax, %r14
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4b49
callq 0x3230
movq %r14, %rdi
callq 0x33d0
nop