// File: /workspace/github_cpp_makefile_star2_O1/SNUCSE-CTA[P]GI/src/backtrack.cpp
// Function: Backtrack::merge(std::vector<int, std::allocator<int>>&, int*, int)
void Backtrack::merge(vector<int32_t>& aTo, int32_t* aSource, int32_t aSize)
{
	#ifdef DEBUG
	cout << __PRETTY_FUNCTION__ << endl;
	#endif

	if( aSize == 0)
		return;
	if( aTo.size() == 0 ) {
		aTo.resize( aSize );
		for(int32_t i = 0; i < aSize; ++i)
			aTo[i] = aSource[i];
		return;
	}

	int32_t ind1 = 0;
	int32_t ind2 = 0;
	int32_t size1 = aTo.size();
	int32_t size2 = aSize;
	int32_t* mergeSet = global_memory->getLLArray(n);
	int32_t setSize = 0;

	while( ind1 < size1 && ind2 < size2 ) {
		if( aTo[ind1] == aSource[ind2] ) {
			mergeSet[setSize] = aTo[ind1];
			++setSize;
			++ind1;
			++ind2;
		}
		else if( aTo[ind1] < aSource[ind2] ) {
			mergeSet[setSize] = aTo[ind1];
			++setSize;
			++ind1;
		}
		else { //aTo[ind1] > aSource[ind2]
			mergeSet[setSize] = aSource[ind2];
			++setSize;
			++ind2;
		}
	}

	while( ind1 < size1 ) {
		mergeSet[setSize] = aTo[ind1];
		++setSize;
		++ind1;
	}
	while( ind2 < size2 ) {
		mergeSet[setSize] = aSource[ind2];
		++setSize;
		++ind2;
	}

	aTo.clear();
	if( aTo.capacity() < setSize ) { //need resize
		if( setSize < INIT_FSIZE )
			aTo.reserve(INIT_FSIZE);
		else
			aTo.reserve(setSize);
	}
	for(int i = 0; i < setSize; ++i) {
		aTo.push_back( mergeSet[i] );
	}

	global_memory->returnLLArray(mergeSet, n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testl %ecx, %ecx
je 0x84d6
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %rbx
movq 0x8(%rsi), %r14
subq (%rsi), %r14
je 0x84b1
movq %rdi, %rax
shrq $0x2, %r14
movq 0xb0(%rdi), %rdi
movq %rax, (%rsp)
movl 0x2c(%rax), %esi
callq 0x4b34
movq %rax, %r15
testl %r14d, %r14d
setle %cl
testl %ebp, %ebp
setle %dl
xorl %eax, %eax
orb %cl, %dl
movl $0x0, %ecx
movl $0x0, %r13d
jne 0x83c2
movq (%rbx), %rdx
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %eax, %eax
movslq %ecx, %rsi
movl (%rdx,%rsi,4), %esi
movslq %eax, %rdi
movl (%r12,%rdi,4), %edi
cmpl %edi, %esi
jne 0x83a6
movl %esi, (%r15,%r13,4)
incl %ecx
jmp 0x83b4
jge 0x83b0
movl %esi, (%r15,%r13,4)
incl %ecx
jmp 0x83b6
movl %edi, (%r15,%r13,4)
incl %eax
incq %r13
cmpl %r14d, %ecx
jge 0x83c2
cmpl %ebp, %eax
jl 0x838d
cmpl %r14d, %ecx
jge 0x83f7
movl %r13d, %r13d
movslq %ecx, %rdx
leaq (,%rdx,4), %rcx
addq (%rbx), %rcx
movslq %r14d, %rsi
subq %rdx, %rsi
leaq (%r15,%r13,4), %rdi
xorl %edx, %edx
movl (%rcx,%rdx,4), %r8d
movl %r8d, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rsi
jne 0x83e4
addl %edx, %r13d
cmpl %ebp, %eax
jge 0x8422
movl %r13d, %r13d
movslq %eax, %rcx
movslq %ebp, %rax
leaq (%r12,%rcx,4), %rdx
subq %rcx, %rax
leaq (%r15,%r13,4), %rsi
xorl %ecx, %ecx
movl (%rdx,%rcx,4), %edi
movl %edi, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x8411
addl %ecx, %r13d
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x842f
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movl %r13d, %r14d
cmpq %r14, %rcx
jae 0x8457
cmpl $0x9, %r13d
movl $0x8, %esi
cmovael %r13d, %esi
movq %rbx, %rdi
callq 0x8a00
testl %r13d, %r13d
je 0x848d
movq %r15, %r12
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x8479
movl (%r12), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x8484
movq %rbx, %rdi
movq %r12, %rdx
callq 0x8df0
addq $0x4, %r12
decq %r14
jne 0x845f
movq (%rsp), %rax
movq 0xb0(%rax), %rdi
movl 0x2c(%rax), %edx
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4cf0
movslq %ebp, %rsi
movq %rbx, %rdi
callq 0x89ce
testl %ebp, %ebp
jle 0x84d6
movq (%rbx), %rax
movl %ebp, %ecx
xorl %edx, %edx
movl (%r12,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x84c7
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq