// File: /workspace/github_cpp_makefile_star2_O2/ADAPTLab[P]MuDBSCAN/RTree.cpp
// Function: RsplitNode(RlstNd*)
void RsplitNode(RLstNd ptrChild)
{    
	if(ptrChild == NULL || RisLstEmpty(ptrChild->ptrChildLst))
		return;

	RLstNd lstNdOne = NULL;
	RLstNd lstNdTwo = NULL;
	RTreeNode tnInfoTemp = NULL;

	RLstNd lstNdTemp = NULL;

	double dExpOne = -1;
	double dExpTwo = -1;

	RpickSeeds(ptrChild->ptrChildLst, &lstNdOne, &lstNdTwo);

	if(lstNdOne == NULL || lstNdTwo == NULL)
		return;

	RLstNd ptrChildTemp = RinitLstNd(RinitIntNd(NULL, NULL));
	RLstNd ptrChildSib = RinitLstNd(RinitIntNd(NULL, NULL));

	ptrChildTemp->ptrChildLst = RinitHdrNd();
	ptrChildSib->ptrChildLst = RinitHdrNd();
	ptrChildSib->ptrNextNd = ptrChild->ptrNextNd;

	RinsertLstNd(ptrChildTemp->ptrChildLst, lstNdOne);
	RsetRect(ptrChildTemp, lstNdOne->tnInfo);
	RinsertLstNd(ptrChildSib->ptrChildLst, lstNdTwo);
	RsetRect(ptrChildSib, lstNdTwo->tnInfo);

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

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

	Boolean bIsOne = FALSE;
	Boolean bIsNdOneInComp = FALSE;
	Boolean bIsNdTwoInComp = FALSE;

	int iCnt = 0;

	lstNdTemp = RdeleteLstFirst(ptrChild->ptrChildLst);

	while(lstNdTemp != NULL)
	{
		if(ptrChildTemp->ptrChildLst->uiCnt + ptrChild->ptrChildLst->uiCnt == RMINENTRIES - 1)
			bIsNdOneInComp = TRUE;

		if(ptrChildSib->ptrChildLst->uiCnt + ptrChild->ptrChildLst->uiCnt == RMINENTRIES - 1)
			bIsNdTwoInComp = TRUE;
		if(!bIsNdOneInComp && !bIsNdTwoInComp)
        {   
        	dExpOne = -1;
		    dExpTwo = -1;
		    RexpansionArea(ptrChildTemp->tnInfo->tdInfo->rgnRect, lstNdTemp->tnInfo, &dExpOne, rgnNewRectOne);
		    RexpansionArea(ptrChildSib->tnInfo->tdInfo->rgnRect, lstNdTemp->tnInfo, &dExpTwo, rgnNewRectTwo);

		    if(dExpOne < dExpTwo)
			     bIsOne = TRUE;
	        if(dExpOne > dExpTwo)
		         bIsOne = FALSE;
	        if(dExpOne == dExpTwo)
	        {
		         double dAreaOne = Rarea(ptrChildTemp->tnInfo->tdInfo->rgnRect);
			     double dAreaTwo = Rarea(ptrChildSib->tnInfo->tdInfo->rgnRect);
			     if(dAreaOne < dAreaTwo)
                      bIsOne = TRUE;
                 if(dAreaOne > dAreaTwo)
                      bIsOne = FALSE;
                 if(dAreaOne == dAreaTwo)
                 {
                      if(ptrChildTemp->ptrChildLst->uiCnt < ptrChildSib->ptrChildLst->uiCnt)
                           bIsOne = TRUE;
                      else
					       bIsOne = FALSE;
                 }
            }
		}
		else
		{
		    if(bIsNdOneInComp)
                  bIsOne = TRUE;
		    if(bIsNdTwoInComp)
			      bIsOne = FALSE;
		}

		if(bIsOne)
		{
			RinsertLstNd(ptrChildTemp->ptrChildLst, lstNdTemp);
            if(bIsNdOneInComp)
            {   dExpOne = -1;
				RexpansionArea(ptrChildTemp->tnInfo->tdInfo->rgnRect, lstNdTemp->tnInfo, &dExpOne, rgnNewRectOne);
			}
			for(iCnt = 0; iCnt < DIMENSION; iCnt++)
            {	ptrChildTemp->tnInfo->tdInfo->rgnRect->iBottomLeft[iCnt] = rgnNewRectOne->iBottomLeft[iCnt];
				ptrChildTemp->tnInfo->tdInfo->rgnRect->iTopRight[iCnt] = rgnNewRectOne->iTopRight[iCnt];
			}
		}
		else
		{
			RinsertLstNd(ptrChildSib->ptrChildLst, lstNdTemp);
            if(bIsNdTwoInComp)
            {   dExpTwo = -1;
				RexpansionArea(ptrChildSib->tnInfo->tdInfo->rgnRect, lstNdTemp->tnInfo, &dExpTwo, rgnNewRectTwo);
			}
			for(iCnt = 0; iCnt < DIMENSION; iCnt++)
            {	ptrChildSib->tnInfo->tdInfo->rgnRect->iBottomLeft[iCnt] = rgnNewRectTwo->iBottomLeft[iCnt];
				ptrChildSib->tnInfo->tdInfo->rgnRect->iTopRight[iCnt] = rgnNewRectTwo->iTopRight[iCnt];
			}
		}
		lstNdTemp = RdeleteLstFirst(ptrChild->ptrChildLst);
	}

	ptrChildTemp->ptrChildLst->ptrParentNd = ptrChildTemp;
	ptrChildSib->ptrChildLst->ptrParentNd = ptrChildSib;
	ptrChildTemp->ptrNextNd = ptrChildSib;
	ptrChild->ptrChildLst->ptrParentNd = NULL;
	free(ptrChild->ptrChildLst);

	free(ptrChild->tnInfo->tdInfo->rgnRect->iBottomLeft);
	free(ptrChild->tnInfo->tdInfo->rgnRect->iTopRight);
	free(ptrChild->tnInfo->tdInfo->rgnRect);

	free(ptrChild->tnInfo->tdInfo);
	free(ptrChild->tnInfo);

	ptrChild->tnInfo = ptrChildTemp->tnInfo;
	ptrChild->ptrChildLst = ptrChildTemp->ptrChildLst;
	ptrChild->ptrNextNd = ptrChildTemp->ptrNextNd;

	ptrChildTemp->ptrNextNd = NULL;
	ptrChildTemp->ptrChildLst = NULL;
	ptrChildTemp->tnInfo = NULL;
	free(ptrChildTemp);

	free(rgnNewRectOne->iBottomLeft);
	free(rgnNewRectOne->iTopRight);
	free(rgnNewRectOne);
	free(rgnNewRectTwo->iBottomLeft);
	free(rgnNewRectTwo->iTopRight);
	free(rgnNewRectTwo);

	return;
}

// Assembly:
testq %rdi, %rdi
je 0x4b9c
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r12
movq 0x8(%rdi), %rdi
callq 0x30ee
testl %eax, %eax
jne 0x4b8e
leaq -0x70(%rbp), %rbx
andq $0x0, (%rbx)
leaq -0x68(%rbp), %r14
andq $0x0, (%r14)
movq 0x8(%r12), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x42cc
movq (%rbx), %r15
testq %r15, %r15
sete %al
movq (%r14), %rbx
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x4b8e
xorl %edi, %edi
xorl %esi, %esi
callq 0x3db7
movq %rax, %rdi
callq 0x308a
movq %rax, %r14
xorl %edi, %edi
xorl %esi, %esi
callq 0x3db7
movq %rax, %rdi
callq 0x308a
movq %rax, %r13
callq 0x306c
movq %rax, 0x8(%r14)
callq 0x306c
movq %rax, 0x8(%r13)
movq 0x10(%r12), %rax
movq %rax, 0x10(%r13)
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x30ca
movq (%r15), %rsi
movq %r14, %rdi
callq 0x3d09
movq 0x8(%r13), %rdi
movq %rbx, %rsi
callq 0x30ca
movq (%rbx), %rsi
movq %r13, %rdi
callq 0x3d09
xorl %edi, %edi
xorl %esi, %esi
callq 0x3c84
movq %r12, %rbx
movq %rax, %r12
xorl %edi, %edi
xorl %esi, %esi
callq 0x3c84
movq %rax, %r15
movq %rbx, -0x58(%rbp)
movq 0x8(%rbx), %rdi
callq 0x315c
movq %rax, %r10
pushq $0x1
popq %rsi
xorl %ebx, %ebx
xorl %r8d, %r8d
xorl %r9d, %r9d
movq 0x8(%r14), %rax
testq %r10, %r10
je 0x4ad7
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl (%rcx), %ecx
movl (%rax), %eax
addl %ecx, %eax
leaq 0xfac7(%rip), %rdx      # 0x14348
movl (%rdx), %edx
decl %edx
cmpl %edx, %eax
cmovel %esi, %r8d
movq 0x8(%r13), %rdi
addl (%rdi), %ecx
cmpl %edx, %ecx
cmovel %esi, %r9d
movl %r8d, %eax
orl %r9d, %eax
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x5c(%rbp)
movq %r10, -0x50(%rbp)
je 0x48f2
testl %r8d, %r8d
cmovnel %esi, %ebx
testl %r9d, %r9d
je 0x49c4
movq %r10, %rsi
movq %r10, %rbx
callq 0x30ca
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x38(%rbp)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%rbx), %rsi
leaq -0x38(%rbp), %rdx
movq %r15, %rcx
callq 0x3f43
jmp 0x4a69
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq (%r14), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r10), %rsi
leaq -0x40(%rbp), %rdx
movq %r12, %rcx
movl %ebx, -0x48(%rbp)
movq %r10, %rbx
callq 0x3f43
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%rbx), %rsi
movl -0x48(%rbp), %ebx
leaq -0x38(%rbp), %rdx
movq %r15, %rcx
callq 0x3f43
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
pushq $0x1
popq %rax
cmoval %eax, %ebx
ucomisd %xmm1, %xmm0
movl $0x0, %eax
cmoval %eax, %ebx
jne 0x49c0
jp 0x49c0
movq (%r14), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x40db
movsd %xmm0, -0x48(%rbp)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x40db
pushq $0x1
popq %rdx
movsd -0x48(%rbp), %xmm1
ucomisd %xmm1, %xmm0
cmoval %edx, %ebx
ucomisd %xmm0, %xmm1
movl $0x0, %eax
cmoval %eax, %ebx
movq -0x50(%rbp), %r10
jne 0x49c4
jp 0x49c4
movq 0x8(%r14), %rdi
movl (%rdi), %ecx
movq 0x8(%r13), %rax
movl %edx, %ebx
cmpl (%rax), %ecx
jb 0x49d0
jmp 0x4a5e
movq -0x50(%rbp), %r10
testl %ebx, %ebx
je 0x4a5a
movq 0x8(%r14), %rdi
movq %r10, %rsi
callq 0x30ca
cmpl $0x0, -0x2c(%rbp)
je 0x4a09
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movq (%r14), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq -0x50(%rbp), %rax
movq (%rax), %rsi
leaq -0x40(%rbp), %rdx
movq %r12, %rcx
callq 0x3f43
leaq 0xf924(%rip), %rax      # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x4ab7
movq (%r12), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r14), %rdx
movq 0x8(%rdx), %rdx
movq (%rdx), %rdx
movq (%rdx), %rsi
movsd %xmm0, (%rsi,%rcx,8)
movq 0x8(%r12), %rsi
movsd (%rsi,%rcx,8), %xmm0
movq 0x8(%rdx), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x4a1e
movq 0x8(%r13), %rax
movq %rax, %rdi
movq %r10, %rsi
callq 0x30ca
leaq 0xf8c4(%rip), %rax      # 0x14334
movl (%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x4ab5
movq (%r15), %rdx
movsd (%rdx,%rcx,8), %xmm0
movq (%r13), %rdx
movq 0x8(%rdx), %rdx
movq (%rdx), %rdx
movq (%rdx), %rsi
movsd %xmm0, (%rsi,%rcx,8)
movq 0x8(%r15), %rsi
movsd (%rsi,%rcx,8), %xmm0
movq 0x8(%rdx), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x4a7e
xorl %ebx, %ebx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x315c
movq %rax, %r10
pushq $0x1
popq %rsi
movl -0x2c(%rbp), %r8d
movl -0x5c(%rbp), %r9d
jmp 0x485f
movq %r14, 0x10(%rax)
movq 0x8(%r13), %rax
movq %r13, 0x10(%rax)
movq %r13, 0x10(%r14)
movq -0x58(%rbp), %rbx
movq 0x8(%rbx), %rdi
callq 0x2280
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x2280
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
callq 0x2280
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x2280
movq (%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x2280
movq (%rbx), %rdi
callq 0x2280
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx)
movq %r14, %rdi
callq 0x2280
movq (%r12), %rdi
callq 0x2280
movq 0x8(%r12), %rdi
callq 0x2280
movq %r12, %rdi
callq 0x2280
movq (%r15), %rdi
callq 0x2280
movq 0x8(%r15), %rdi
callq 0x2280
movq %r15, %rdi
callq 0x2280
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq