// File: 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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x102b0
cmpl $0x0, %eax
je 0x16cfc
movl $0x1, %edi
movl $0x8, %esi
callq 0x9400
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16e79
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0xfffffffe, -0x4c(%rbp) # imm = 0xFFFFFFFE
movb $0x0, -0x4d(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x16e45
movq -0x48(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
testl %eax, %eax
je 0x16d4b
jmp 0x16d3e
movl -0x58(%rbp), %eax
subl $0x1, %eax
je 0x16db8
jmp 0x16e34
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x14380
cmpl $0x0, %eax
je 0x16db6
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
movsd -0x28(%rbp), %xmm0
callq 0x16ca0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x16d9e
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16e79
movq -0x30(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x16dab
movb $0x1, -0x4d(%rbp)
jmp 0x16dad
movq -0x30(%rbp), %rdi
callq 0x97c0
jmp 0x16e34
movq -0x20(%rbp), %rdi
leaq 0x21a4d(%rip), %rax     # 0x38810
movq (%rax), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
movsd -0x28(%rbp), %xmm0
callq 0x16b80
movl %eax, -0x4c(%rbp)
movl $0x1, %edi
movl $0x8, %esi
callq 0x9400
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x4c(%rbp)
jne 0x16e2b
movq -0x30(%rbp), %rax
movl $0x1, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16e79
movq -0x30(%rbp), %rdi
callq 0x97c0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x16d21
movl $0x1, %edi
movl $0x8, %esi
callq 0x9400
movq %rax, -0x30(%rbp)
movb -0x4d(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)