// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
testq %rdi, %rdi
je 0x6c94
movq %rsi, %r14
movq 0x8(%rdi), %r12
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
leaq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %r15d, %r15d
xorl %edi, %edi
xorl %esi, %esi
callq 0x68bb
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x68bb
movq %rax, %r13
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x6ca9
testl %eax, %eax
je 0x6c45
movsd -0x30(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6bfe
xorpd %xmm2, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, -0x30(%rbp)
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
xorpd %xmm1, %xmm1
testq %rdx, %rdx
je 0x6b60
leaq 0x1083b(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xb5ac(%rip), %xmm1     # 0x120e0
testq %rax, %rax
jle 0x6b60
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xb596(%rip), %xmm1     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x6b4a
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x6bae
leaq 0x107ed(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xb55e(%rip), %xmm0     # 0x120e0
testq %rax, %rax
jle 0x6bae
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xb548(%rip), %xmm0     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x6b98
ucomisd %xmm0, %xmm1
jbe 0x6c45
leaq 0x107a5(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x6c45
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movq (%r13), %rsi
movq 0x8(%r13), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rax
jne 0x6bdc
jmp 0x6c42
leaq 0x1075f(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x6c45
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movq (%r13), %rsi
movq 0x8(%r13), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rax
jne 0x6c22
movq %r12, %r15
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x6acd
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %r14
movq %r13, (%rax)
movq (%r14), %rdi
callq 0x3310
movq 0x8(%r14), %rdi
callq 0x3310
movq %r14, %rdi
callq 0x3310
movq (%rbx), %rdi
callq 0x3310
movq 0x8(%rbx), %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3310
jmp 0x6c97
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq