// File: /workspace/github_cpp_makefile_star2_O2/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 0x30ee
testq %r15, %r15
je 0x6582
testl %eax, %eax
jne 0x6582
cmpq $0x0, (%r15)
je 0x6582
cmpq $0x0, 0x8(%r15)
je 0x6582
addq $0x8, %r12
movsd 0x8cca(%rip), %xmm0     # 0xf150
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0xded1(%rip), %r13      # 0x14368
movq (%r12), %r12
testq %r12, %r12
je 0x6582
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0x1, %ecx
je 0x64d4
testl %ecx, %ecx
jne 0x6579
movq 0x8(%r12), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movsd -0x30(%rbp), %xmm0
callq 0x642d
jmp 0x6579
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x4e4e
testl %eax, %eax
je 0x6579
movq (%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r14), %rsi
cmpq %rsi, %rdi
jne 0x650f
movl 0x1c(%rax), %eax
cmpl 0x1c(%r14), %eax
je 0x6579
callq 0x61e9
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x6579
movq (%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl 0x1c(%rax), %ecx
leaq 0xde2b(%rip), %rdx      # 0x14360
movq (%rdx), %rsi
movl %ecx, (%rsi)
movq (%r13), %rcx
movsd %xmm0, (%rcx)
cmpl $0x1, 0x8(%rax)
jne 0x6559
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x656a
movq 0x18(%rbx), %rdi
jmp 0x6574
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x6570
movq 0x20(%rbx), %rdi
jmp 0x6574
movq 0x8(%rbx), %rdi
jmp 0x6574
movq 0x10(%rbx), %rdi
callq 0x29f0
addq $0x10, %r12
jmp 0x6497
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq