// File: /workspace/github_cpp_makefile_star2_O1/ADAPTLab[P]MuDBSCAN/RTree.cpp
// Function: RexpansionArea(region*, RtreeNode*, double*, region*)
Boolean RexpansionArea(Region rgnRect, RTreeNode tnInfo, Double ptrDMinExp, Region rgnNewRect)
{
    int iCnt = 0;
    Region rgnRectTemp = RinitRgnRect(NULL, NULL);
    // assert(rgnRectTemp != NULL);

    for(iCnt = 0; iCnt < DIMENSION; iCnt++)
    {   switch(tnInfo->ndType)
        {   case INTNODE:
			rgnRectTemp->iTopRight[iCnt] = (tnInfo->tdInfo->rgnRect->iTopRight[iCnt] > rgnRect->iTopRight[iCnt]) ? tnInfo->tdInfo->rgnRect->iTopRight[iCnt] : rgnRect->iTopRight[iCnt];
			rgnRectTemp->iBottomLeft[iCnt] = (tnInfo->tdInfo->rgnRect->iBottomLeft[iCnt] < rgnRect->iBottomLeft[iCnt]) ? tnInfo->tdInfo->rgnRect->iBottomLeft[iCnt] : rgnRect->iBottomLeft[iCnt];
            break;

		    case EXTNODE:
			rgnRectTemp->iTopRight[iCnt] = (tnInfo->tdInfo->dataClstElem->iData[iCnt] > rgnRect->iTopRight[iCnt]) ? tnInfo->tdInfo->dataClstElem->iData[iCnt] : rgnRect->iTopRight[iCnt];
			rgnRectTemp->iBottomLeft[iCnt] = (tnInfo->tdInfo->dataClstElem->iData[iCnt] < rgnRect->iBottomLeft[iCnt]) ? tnInfo->tdInfo->dataClstElem->iData[iCnt] : rgnRect->iBottomLeft[iCnt];
			break;
		}
	}
	double dExp = Rarea(rgnRectTemp) - Rarea(rgnRect);
	if(*ptrDMinExp == -1 || dExp <= *ptrDMinExp)
    {   
    	if(dExp == *ptrDMinExp)
			*ptrDMinExp = 0 - dExp;
		else
			*ptrDMinExp = dExp;
        for(iCnt =0; iCnt< DIMENSION; iCnt++)
        {	rgnNewRect->iBottomLeft[iCnt] = rgnRectTemp->iBottomLeft[iCnt];
			rgnNewRect->iTopRight[iCnt] = rgnRectTemp->iTopRight[iCnt];
		}
		free(rgnRectTemp->iBottomLeft);
		free(rgnRectTemp->iTopRight);
		free(rgnRectTemp);
		return TRUE;
	}

	free(rgnRectTemp->iBottomLeft);
	free(rgnRectTemp->iTopRight);
	free(rgnRectTemp);
	return FALSE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
xorl %edi, %edi
xorl %esi, %esi
callq 0x51e4
movq %rax, %rbx
leaq 0x11e82(%rip), %rax     # 0x17364
movslq (%rax), %rax
testq %rax, %rax
jle 0x558b
movl (%r13), %ecx
leaq (,%rax,8), %rdx
xorl %esi, %esi
xorl %edi, %edi
cmpl $0x1, %ecx
je 0x553a
testl %ecx, %ecx
jne 0x557b
movq 0x8(%r13), %r8
movq (%r8), %r9
movq 0x8(%r9), %r8
movsd (%r8,%rsi), %xmm0
movq 0x8(%r12), %r8
maxsd (%r8,%rsi), %xmm0
movq 0x8(%rbx), %r8
movsd %xmm0, (%r8,%rsi)
leaq (,%rdi,8), %r8
addq (%r9), %r8
jmp 0x5563
movq 0x8(%r13), %r8
movq 0x8(%r8), %r8
movq (%r8), %r8
movsd (%r8,%rsi), %xmm0
addq %rsi, %r8
movq 0x8(%r12), %r9
maxsd (%r9,%rsi), %xmm0
movq 0x8(%rbx), %r9
movsd %xmm0, (%r9,%rsi)
movsd (%r8), %xmm0
movq (%r12), %r8
minsd (%r8,%rsi), %xmm0
movq (%rbx), %r8
movsd %xmm0, (%r8,%rsi)
incq %rdi
addq $0x8, %rsi
cmpq %rsi, %rdx
jne 0x54fe
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rbx, %rbx
je 0x55cd
testl %eax, %eax
jle 0x55c5
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movsd 0xcb35(%rip), %xmm0     # 0x120e0
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm0
incq %rsi
cmpq %rsi, %rax
jne 0x55ad
jmp 0x55cd
movsd 0xcb13(%rip), %xmm0     # 0x120e0
testq %r12, %r12
je 0x5609
testl %eax, %eax
jle 0x5601
movq (%r12), %rcx
movq 0x8(%r12), %rdx
movsd 0xcaf9(%rip), %xmm1     # 0x120e0
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm2
subsd (%rcx,%rsi,8), %xmm2
mulsd %xmm2, %xmm1
incq %rsi
cmpq %rsi, %rax
jne 0x55e9
jmp 0x5609
movsd 0xcad7(%rip), %xmm1     # 0x120e0
subsd %xmm1, %xmm0
movsd (%r15), %xmm1
ucomisd 0xcace(%rip), %xmm1     # 0x120e8
jne 0x561e
jnp 0x5627
xorl %r12d, %r12d
ucomisd %xmm0, %xmm1
jb 0x5680
xorpd %xmm2, %xmm2
subsd %xmm0, %xmm2
cmpeqsd %xmm0, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movlpd %xmm1, (%r15)
movl $0x1, %r12d
testl %eax, %eax
jle 0x5680
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movq (%r14), %rsi
movq 0x8(%r14), %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 0x5660
movq (%rbx), %rdi
callq 0x3310
movq 0x8(%rbx), %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3310
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq