// File: /workspace/github_cpp_makefile_star2_O1/ADAPTLab[P]MuDBSCAN/MuC_RTree.cpp
// Function: GcanAssign2(data*, GhdrNd*, region*, double)
Assign GcanAssign2(Data currDataPoint, GHdrNd hdrNdTree, Region x2rgnRect, double eps)
{
	Assign assignStruct;

	// if(GisLstEmpty(hdrNdTree) || rgnRect == NULL || rgnRect->iBottomLeft == NULL || rgnRect->iTopRight == NULL)
	if(GisLstEmpty(hdrNdTree))
	{
		assignStruct = (Assign)calloc(1, sizeof(struct assign));
		// assert(assignStruct != NULL);
		assignStruct->canBeAssigned = -5;
		assignStruct->groupid = -1;
		return assignStruct;
	}
 	
 	unsigned int uiRecCnt = 0;
	int iCnt = 0;
    double t;
    static int flag = 0;
	GLstNd lstNdTemp = hdrNdTree->ptrFirstNd;
	int aflag = -2;
	bool eps2 = 0;

	// Assign assignStruct;
	while(lstNdTemp != NULL)
    {	
    	int assignflag;
		switch(lstNdTemp->tnInfo->ndType)
        {   
        	case INTNODE:   

	            if(RisContains(lstNdTemp->tnInfo->tdInfo->rgnRect, currDataPoint->iData))
	            // if(GisOverLap(, x2rgnRect))
	            {
	            	assignStruct = GcanAssign2(currDataPoint, lstNdTemp->ptrChildLst, x2rgnRect, eps);
	            	if(assignStruct->canBeAssigned==1)
	            	{
            			return assignStruct;
	            	}
	            	else if(assignStruct->canBeAssigned==-1)
	            	{
	            		eps2 = -1;
	            	}
            		free(assignStruct);
	          	}              
            break;

            case EXTNODE:  
            	// fprintf(stderr, "%lf\n", eps); 
				aflag = GisEpsDistant(x2rgnRect, groupList->groupItems[lstNdTemp->tnInfo->tdInfo->groupElem], eps);
				assignStruct = (Assign)calloc(1, sizeof(struct assign));
				// assert(assignStruct != NULL);
				if(aflag == 1)
				{
					assignStruct->canBeAssigned = 1;
					assignStruct->groupid = lstNdTemp->tnInfo->tdInfo->groupElem;
					return assignStruct;
				}
				free(assignStruct);        				    				
            break;
		}

		lstNdTemp = lstNdTemp->ptrNextNd;
	}

	//When eps2=0 it means that there is no group in which this point can be put but you can create a group for this point.
	//When eps=-1 it means that there is no group in which this point can be put and this point will go into the unassigned list.

	assignStruct = (Assign)calloc(1, sizeof(struct assign));
	// assert(assignStruct != NULL);
	assignStruct->canBeAssigned = eps2;
	assignStruct->groupid = -1;

	return assignStruct;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm0, -0x30(%rbp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x42e9
testl %eax, %eax
je 0x7d33
movl $0x1, %edi
movl $0x8, %esi
callq 0x31b0
movq %rax, %r15
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
jmp 0x7e30
movq 0x8(%r15), %r13
movl $0x0, -0x34(%rbp)
movsd -0x30(%rbp), %xmm0
testq %r13, %r13
je 0x7e13
movq (%r13), %rax
movl (%rax), %ecx
cmpl $0x1, %ecx
je 0x7d9d
testl %ecx, %ecx
jne 0x7e03
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r14), %rsi
callq 0x65ae
testl %eax, %eax
je 0x7dfe
movq 0x8(%r13), %rsi
movq %r14, %rdi
movq %rbx, %rdx
movsd -0x30(%rbp), %xmm0
callq 0x7ceb
movl (%rax), %ecx
cmpl $0x1, %ecx
je 0x7dea
cmpl $-0x1, %ecx
jne 0x7df6
movb $0x1, %cl
movl %ecx, -0x34(%rbp)
jmp 0x7df6
leaq 0xf5fc(%rip), %rcx      # 0x173a0
movq (%rcx), %rcx
movq (%rcx), %rcx
movq 0x8(%rax), %rax
movslq 0x8(%rax), %rax
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
callq 0x7bad
movl %eax, %r12d
movl $0x1, %edi
movl $0x8, %esi
callq 0x31b0
cmpl $0x1, %r12d
jne 0x7df6
movl $0x1, (%rax)
movq (%r13), %rcx
movq 0x8(%rcx), %rcx
movl 0x8(%rcx), %ecx
movl %ecx, 0x4(%rax)
xorl %ecx, %ecx
movq %rax, %r15
movsd -0x30(%rbp), %xmm0
jmp 0x7e09
movq %rax, %rdi
callq 0x3310
movsd -0x30(%rbp), %xmm0
movq 0x10(%r13), %r13
movb $0x1, %cl
testb %cl, %cl
jne 0x7d43
jmp 0x7e38
movl $0x1, %edi
movl $0x8, %esi
callq 0x31b0
movq %rax, %r15
movl -0x34(%rbp), %eax
andb $0x1, %al
movzbl %al, %eax
movl %eax, (%r15)
movl $0xffffffff, 0x4(%r15)  # imm = 0xFFFFFFFF
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq