// File: /workspace/github_cpp_makefile_star2_O2/ADAPTLab[P]MuDBSCAN/MuC_RTree.cpp
// Function: GpickChild(GhdrNd*, GtreeNode*)
GLstNd GpickChild(GHdrNd ptrChildLst, GTreeNode tnInfo)
{  
    if(ptrChildLst == NULL)
		return NULL;

	GLstNd lstNdTemp = ptrChildLst->ptrFirstNd;
	GLstNd lstNdChild = NULL;
	double dMinExp = -1;

    Region rgnNewRect = GinitRgnRect(NULL, NULL);
    Region rgnFinalRect = GinitRgnRect(NULL, NULL);

    int iCnt;

	while(lstNdTemp != NULL)
    {   
		if(GexpansionArea(lstNdTemp->tnInfo->tdInfo->rgnRect, tnInfo, &dMinExp, rgnNewRect))
        {
               if(dMinExp < 0)
               {     dMinExp = 0 - dMinExp;
                     if(Garea(lstNdChild->tnInfo->tdInfo->rgnRect) > Garea(lstNdTemp->tnInfo->tdInfo->rgnRect))
                     {
                     	lstNdChild = lstNdTemp;
                     	    for(iCnt =0; iCnt< DIMENSION; iCnt++)
					        {	rgnFinalRect->iBottomLeft[iCnt] = rgnNewRect->iBottomLeft[iCnt];
								rgnFinalRect->iTopRight[iCnt] = rgnNewRect->iTopRight[iCnt];
							}
                     }
                           
               }
			   else
			   {
			   		lstNdChild = lstNdTemp;
				    for(iCnt =0; iCnt< DIMENSION; iCnt++)
		         	{	rgnFinalRect->iBottomLeft[iCnt] = rgnNewRect->iBottomLeft[iCnt];
						rgnFinalRect->iTopRight[iCnt] = rgnNewRect->iTopRight[iCnt];
				 	}
			   }
		}
    	lstNdTemp = lstNdTemp->ptrNextNd;
	}

    Region rgnRectTemp = lstNdChild->tnInfo->tdInfo->rgnRect;
	lstNdChild->tnInfo->tdInfo->rgnRect = rgnFinalRect;

	free(rgnRectTemp->iBottomLeft);
	free(rgnRectTemp->iTopRight);
	free(rgnRectTemp);

	free(rgnNewRect->iBottomLeft);
	free(rgnNewRect->iTopRight);
	free(rgnNewRect);

	return lstNdChild;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x5506
movq %rsi, %r14
movq 0x8(%rdi), %r13
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
leaq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
callq 0x51a5
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x51a5
movq %rax, %r12
xorl %r15d, %r15d
testq %r13, %r13
je 0x54c5
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x551b
testl %eax, %eax
je 0x54bc
movsd -0x30(%rbp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5476
subsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x568f
movsd %xmm0, -0x38(%rbp)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x568f
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x54bc
leaq 0xeefa(%rip), %rax      # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x54b9
movq (%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r12), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movq 0x8(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq 0x8(%r12), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x5448
leaq 0xeeb7(%rip), %rax      # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x54b9
movq (%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r12), %rdx
movsd %xmm0, (%rdx,%rcx,8)
movq 0x8(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq 0x8(%r12), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x548b
movq %r13, %r15
movq 0x10(%r13), %r13
jmp 0x53bd
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %r14
movq %r12, (%rax)
movq (%r14), %rdi
callq 0x2280
movq 0x8(%r14), %rdi
callq 0x2280
movq %r14, %rdi
callq 0x2280
movq (%rbx), %rdi
callq 0x2280
movq 0x8(%rbx), %rdi
callq 0x2280
movq %rbx, %rdi
callq 0x2280
jmp 0x5509
xorl %r15d, %r15d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq