// File: /workspace/github_cpp_makefile_star2_O3/ADAPTLab[P]MuDBSCAN/MuC_RTree.cpp
// Function: findNeighboursGroup(RhdrNd*, region*, data*, neighbours*, double)
void findNeighboursGroup(RHdrNd hdrNdTree, Region rgnRect, Data data, Neighbours n, double eps)
{
	if(RisLstEmpty(hdrNdTree) || rgnRect == NULL || rgnRect->iBottomLeft == NULL || rgnRect->iTopRight == NULL)
		return;

	unsigned int uiRecCnt = 0;
	int iCnt = 0;
	double t;
	static int flag = 0;
	RLstNd lstNdTemp = hdrNdTree->ptrFirstNd;
	int nop;
	double two = 2.0;

	while(lstNdTemp != NULL)
	{	
		switch(lstNdTemp->tnInfo->ndType)
		{   
			case INTNODE:
										 ;
			    findNeighboursGroup(lstNdTemp->ptrChildLst, rgnRect, data, n, eps);
			    break;
			            
			case EXTNODE:   //incase of external node if the child node is contanied in serach rectangle increment the count and return the count to the parent
				nop = 10;
				if(RisContains(rgnRect, lstNdTemp->tnInfo->tdInfo->dataClstElem->iData))
			    {      
	                if(lstNdTemp->tnInfo->tdInfo->dataClstElem->iData != data->iData || lstNdTemp->tnInfo->tdInfo->dataClstElem->id!=data->id)
	                {     
	                	t = distance(lstNdTemp->tnInfo->tdInfo->dataClstElem->iData, data->iData);
					    if(t <= eps)
		                {
		                	Data neighbour = lstNdTemp->tnInfo->tdInfo->dataClstElem;
		                	addHelper[0] = lstNdTemp->tnInfo->tdInfo->dataClstElem->id;
		                	addHelperDouble[0] = t;
		                	if(neighbour->haloPoint == TRUE)
		                	{
		                		
		                		// VECTOR_ADD(n->neighbours_remote_distance, addHelperDouble);
		                		if(t <= (eps/two))
		                		{
		                			VECTOR_ADD(n->neighbours_remote_inner, addHelper);
		                			// VECTOR_ADD(n->neighbours_remote_distance, addHelperDouble);
		                		}
		                		else
		                		{
		                			VECTOR_ADD(n->neighbours_remote_outer, addHelper);
		                		}
		                	}
		                	else
		                	{
		                		if(t <= (eps/two))
		                		{
		                			VECTOR_ADD(n->neighbours_local_inner, addHelper);
		                			// VECTOR_ADD(n->neighbours_remote_distance, addHelperDouble);
		                		}
		                		else
		                		{
		                			VECTOR_ADD(n->neighbours_local_outer, addHelper);
		                		}
		                	}
		                }
		            }
                }
                break;
		}
				lstNdTemp = lstNdTemp->ptrNextNd;
	}  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, -0x30(%rbp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
callq 0x440d
testq %r15, %r15
je 0x7fa4
testl %eax, %eax
jne 0x7fa4
cmpq $0x0, (%r15)
je 0x7fa4
cmpq $0x0, 0x8(%r15)
je 0x7fa4
movq 0x8(%r12), %r12
testq %r12, %r12
je 0x7fa4
movsd 0xa303(%rip), %xmm0     # 0x12170
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0xf4e6(%rip), %r13      # 0x17364
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0x1, %ecx
je 0x7eae
testl %ecx, %ecx
jne 0x7f96
movq 0x8(%r12), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movsd -0x30(%rbp), %xmm0
callq 0x7e0a
jmp 0x7f96
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x6555
testl %eax, %eax
je 0x7f96
movq (%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
movq (%rdx), %rax
movq (%r14), %rcx
cmpq %rcx, %rax
jne 0x7eed
movl 0x1c(%rdx), %edx
cmpl 0x1c(%r14), %edx
je 0x7f96
movslq (%r13), %rdx
xorpd %xmm0, %xmm0
testq %rdx, %rdx
jle 0x7f16
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm1
subsd (%rcx,%rsi,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rsi
cmpq %rsi, %rdx
jne 0x7efc
ucomisd 0xa1d2(%rip), %xmm0     # 0x120f0
jb 0x7f26
sqrtsd %xmm0, %xmm0
jmp 0x7f2b
callq 0x3230
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x7f96
movq (%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl 0x1c(%rax), %ecx
leaq 0xf444(%rip), %rdx      # 0x17390
movq (%rdx), %rsi
movl %ecx, (%rsi)
leaq 0xf440(%rip), %rcx      # 0x17398
movq (%rcx), %rcx
movsd %xmm0, (%rcx)
cmpl $0x1, 0x8(%rax)
jne 0x7f76
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x7f87
movq 0x18(%rbx), %rdi
jmp 0x7f91
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x7f8d
movq 0x20(%rbx), %rdi
jmp 0x7f91
movq 0x8(%rbx), %rdi
jmp 0x7f91
movq 0x10(%rbx), %rdi
callq 0x3c20
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x7e7e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq