// File: /workspace/github_cpp_makefile_star2_O1/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 0x6ce5
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 0x68ff
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x68ff
movq %rax, %r13
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x6cfa
testl %eax, %eax
je 0x6c96
movsd -0x30(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6c4f
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 0x6bb1
leaq 0x107ea(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xb55b(%rip), %xmm1     # 0x120e0
testq %rax, %rax
jle 0x6bb1
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xb545(%rip), %xmm1     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x6b9b
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x6bff
leaq 0x1079c(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xb50d(%rip), %xmm0     # 0x120e0
testq %rax, %rax
jle 0x6bff
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xb4f7(%rip), %xmm0     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x6be9
ucomisd %xmm0, %xmm1
jbe 0x6c96
leaq 0x10754(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x6c96
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 0x6c2d
jmp 0x6c93
leaq 0x1070e(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x6c96
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 0x6c73
movq %r12, %r15
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x6b1e
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 0x6ce8
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq