// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
testq %rdi, %rdi
je 0x587b
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 0x513c
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x513c
movq %rax, %r13
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x53f8
testl %eax, %eax
je 0x582c
movsd -0x30(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x57e5
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 0x5747
leaq 0x11c54(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc9c5(%rip), %xmm1     # 0x120e0
testq %rax, %rax
jle 0x5747
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc9af(%rip), %xmm1     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x5731
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x5795
leaq 0x11c06(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc977(%rip), %xmm0     # 0x120e0
testq %rax, %rax
jle 0x5795
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc961(%rip), %xmm0     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x577f
ucomisd %xmm0, %xmm1
jbe 0x582c
leaq 0x11bbe(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x582c
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 0x57c3
jmp 0x5829
leaq 0x11b78(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x582c
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 0x5809
movq %r12, %r15
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x56b4
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 0x587e
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq