// File: /workspace/github_cpp_makefile_star2_O1/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 0x590b
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 0x51e4
movq %rax, %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x51e4
movq %rax, %r13
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x54b5
testl %eax, %eax
je 0x58bc
movsd -0x30(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5875
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 0x57d7
leaq 0x11bc4(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc935(%rip), %xmm1     # 0x120e0
testq %rax, %rax
jle 0x57d7
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc91f(%rip), %xmm1     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x57c1
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x5825
leaq 0x11b76(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc8e7(%rip), %xmm0     # 0x120e0
testq %rax, %rax
jle 0x5825
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc8d1(%rip), %xmm0     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x580f
ucomisd %xmm0, %xmm1
jbe 0x58bc
leaq 0x11b2e(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x58bc
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 0x5853
jmp 0x58b9
leaq 0x11ae8(%rip), %rax     # 0x17364
movslq (%rax), %rax
movq %r12, %r15
testq %rax, %rax
jle 0x58bc
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 0x5899
movq %r12, %r15
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x5744
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 0x590e
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq