// File: /workspace/github_cpp_makefile_star2_O1/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 0x62e3
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
callq 0x4481
testl %eax, %eax
jne 0x62d5
xorl %eax, %eax
leaq -0x78(%rbp), %r14
movq %rax, (%r14)
leaq -0x70(%rbp), %r15
movq %rax, (%r15)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5920
movq (%r14), %r12
testq %r12, %r12
sete %al
movq (%r15), %r15
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x62d5
xorl %edi, %edi
xorl %esi, %esi
callq 0x5321
movq %rax, %rdi
callq 0x43f6
movq %rax, %r14
xorl %edi, %edi
xorl %esi, %esi
callq 0x5321
movq %rax, %rdi
callq 0x43f6
movq %rax, %r13
callq 0x43d4
movq %rax, 0x8(%r14)
callq 0x43d4
movq %rax, 0x8(%r13)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r13)
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x445d
movq (%r12), %rsi
movq %r14, -0x60(%rbp)
movq %r14, %rdi
callq 0x526c
movq 0x8(%r13), %rdi
movq %r15, %rsi
callq 0x445d
movq (%r15), %rsi
movq %r13, -0x30(%rbp)
movq %r13, %rdi
callq 0x526c
xorl %edi, %edi
xorl %esi, %esi
callq 0x51e4
movq %rax, -0x58(%rbp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x51e4
movq %rax, -0x50(%rbp)
movq 0x8(%rbx), %rdi
callq 0x4515
testq %rax, %rax
je 0x61fc
movq %rax, %r15
movl $0x1, %esi
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %rbx, -0x68(%rbp)
movq -0x60(%rbp), %r12
movq 0x8(%r12), %rax
movq 0x8(%rbx), %rcx
movl (%rcx), %ecx
movl (%rax), %eax
addl %ecx, %eax
leaq 0x11452(%rip), %rdx     # 0x17378
movl (%rdx), %edx
decl %edx
cmpl %edx, %eax
cmovel %esi, %r14d
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rax
addl (%rax), %ecx
cmpl %edx, %ecx
cmovel %esi, %edi
movl %r14d, %eax
orl %edi, %eax
movl %edi, -0x44(%rbp)
je 0x5f60
testl %r14d, %r14d
cmovnel %esi, %r13d
testl %edi, %edi
movl $0x0, %eax
cmovnel %eax, %r13d
jmp 0x60af
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r15), %rsi
leaq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x54b5
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r15), %rsi
leaq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x54b5
movl $0x1, %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
cmoval %edi, %r13d
ucomisd %xmm1, %xmm0
movl $0x0, %eax
cmoval %eax, %r13d
jne 0x60af
jp 0x60af
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
testq %rdx, %rdx
je 0x602d
leaq 0x1136e(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc0df(%rip), %xmm1     # 0x120e0
testq %rax, %rax
jle 0x602d
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc0c9(%rip), %xmm1     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x6017
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x607e
leaq 0x1131d(%rip), %rax     # 0x17364
movslq (%rax), %rax
movsd 0xc08e(%rip), %xmm0     # 0x120e0
testq %rax, %rax
jle 0x607e
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
xorl %esi, %esi
movsd 0xc078(%rip), %xmm0     # 0x120e0
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x6068
ucomisd %xmm1, %xmm0
cmoval %edi, %r13d
ucomisd %xmm0, %xmm1
movl $0x0, %eax
cmoval %eax, %r13d
jne 0x60af
jp 0x60af
movq 0x8(%r12), %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
xorl %r13d, %r13d
cmpl (%rcx), %eax
setb %r13b
testl %r13d, %r13d
je 0x614b
movq 0x8(%r12), %rdi
movq %r15, %rsi
callq 0x445d
testl %r14d, %r14d
je 0x60f3
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x40(%rbp)
movq (%r12), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r15), %rsi
leaq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x54b5
leaq 0x1126a(%rip), %rax     # 0x17364
movslq (%rax), %rax
testq %rax, %rax
jle 0x61db
movq -0x58(%rbp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
movq (%r12), %rsi
movq 0x8(%rsi), %rsi
movq (%rsi), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %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 0x6126
jmp 0x61db
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x445d
cmpl $0x0, -0x44(%rbp)
je 0x6189
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x38(%rbp)
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq (%r15), %rsi
leaq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x54b5
leaq 0x111d4(%rip), %rax     # 0x17364
movslq (%rax), %rax
testq %rax, %rax
jle 0x61db
movq -0x50(%rbp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
movq -0x30(%rbp), %rsi
movq (%rsi), %rsi
movq 0x8(%rsi), %rsi
movq (%rsi), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %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 0x61bb
movq -0x68(%rbp), %rbx
movq 0x8(%rbx), %rdi
callq 0x4515
movq %rax, %r15
testq %rax, %rax
movl $0x1, %esi
movl -0x44(%rbp), %edi
jne 0x5f10
movq -0x60(%rbp), %r15
movq 0x8(%r15), %rax
movq %r15, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rcx, 0x10(%rax)
movq %rcx, 0x10(%r15)
movq 0x8(%rbx), %rdi
xorl %r14d, %r14d
movq %r14, 0x10(%rdi)
callq 0x3310
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x3310
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3310
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x3310
movq (%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3310
movq (%rbx), %rdi
callq 0x3310
movq (%r15), %rax
movq %rax, (%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r14, 0x10(%r15)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq %r15, %rdi
callq 0x3310
movq -0x58(%rbp), %rbx
movq (%rbx), %rdi
callq 0x3310
movq 0x8(%rbx), %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3310
movq -0x50(%rbp), %rbx
movq (%rbx), %rdi
callq 0x3310
movq 0x8(%rbx), %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3310
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq