// File: /workspace/github_cpp_makefile_star2_O2/ADAPTLab[P]MuDBSCAN/RTree.cpp
// Function: RpickChild(RhdrNd*, RtreeNode*)
RLstNd RpickChild(RHdrNd ptrChildLst, RTreeNode tnInfo)
{
    if(ptrChildLst == NULL)
		return NULL;

	RLstNd lstNdTemp = ptrChildLst->ptrFirstNd;
	RLstNd lstNdChild = NULL;
	double dMinExp = -1;
	int iCnt;
    Region rgnNewRect = RinitRgnRect(NULL, NULL);
    // assert(rgnNewRect != NULL);

    Region rgnFinalRect = RinitRgnRect(NULL, NULL);
    // assert(rgnFinalRect != NULL);

	while(lstNdTemp != NULL)
	{
		if(RexpansionArea(lstNdTemp->tnInfo->tdInfo->rgnRect, tnInfo, &dMinExp, rgnNewRect))
		{
               if(dMinExp < 0)
               {     dMinExp = 0 - dMinExp;
                     if(Rarea(lstNdChild->tnInfo->tdInfo->rgnRect) > Rarea(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 0x42b7
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 0x3c84
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x3c84
movq %rax, %r12
xorl %r15d, %r15d
testq %r13, %r13
je 0x4276
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x3f43
testl %eax, %eax
je 0x426d
movsd -0x30(%rbp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4227
subsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x40db
movsd %xmm0, -0x38(%rbp)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x40db
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x426d
leaq 0x10149(%rip), %rax     # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x426a
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 0x41f9
leaq 0x10106(%rip), %rax     # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x426a
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 0x423c
movq %r13, %r15
movq 0x10(%r13), %r13
jmp 0x416e
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 0x42ba
xorl %r15d, %r15d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq