// File: /workspace/github_cpp_makefile_star2_O2/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 0x718b
movl %ecx, %r13d
movq %rdx, %r12
movq %rsi, %rbx
movq 0x8(%rsi), %rbp
subq (%rsi), %rbp
je 0x7163
movq %rdi, %r14
shrq $0x2, %rbp
movq 0xb0(%rdi), %rdi
movl 0x2c(%r14), %esi
callq 0x3f1a
movq %rax, %r15
movq (%rbx), %rcx
xorl %eax, %eax
xorl %edx, %edx
xorl %esi, %esi
cmpl %ebp, %esi
jge 0x70b8
cmpl %r13d, %edx
jge 0x70b8
movslq %esi, %rdi
movl (%rcx,%rdi,4), %edi
movslq %edx, %r8
movl (%r12,%r8,4), %r8d
cmpl %r8d, %edi
jne 0x70a3
movl %edi, (%r15,%rax,4)
incl %esi
jmp 0x70b1
jge 0x70ad
movl %edi, (%r15,%rax,4)
incl %esi
jmp 0x70b3
movl %r8d, (%r15,%rax,4)
incl %edx
incq %rax
jmp 0x7080
movslq %esi, %rsi
movslq %edx, %rcx
movq (%rbx), %rdx
movslq %ebp, %rdi
cmpq %rdi, %rsi
jge 0x70d9
movl (%rdx,%rsi,4), %r8d
movl %r8d, (%r15,%rax,4)
incq %rax
incq %rsi
jmp 0x70c4
movslq %r13d, %rdx
cmpq %rdx, %rcx
jge 0x70f1
movl (%r12,%rcx,4), %esi
movl %esi, (%r15,%rax,4)
incq %rax
incq %rcx
jmp 0x70dc
movq (%rbx), %rcx
cmpq %rcx, 0x8(%rbx)
je 0x70fe
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movl %eax, %r13d
cmpq %r13, %rdx
jae 0x7124
cmpq $0x8, %rax
pushq $0x8
popq %rsi
cmovaeq %r13, %rsi
movq %rbx, %rdi
callq 0x7770
xorl %ebp, %ebp
movq %r15, %r12
cmpq %r13, %rbp
jae 0x7142
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7720
incq %rbp
addq $0x4, %r12
jmp 0x7129
movq 0xb0(%r14), %rdi
movl 0x2c(%r14), %edx
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fee
movslq %r13d, %rsi
movq %rbx, %rdi
callq 0x773e
movq (%rbx), %rax
xorl %ecx, %ecx
testl %r13d, %r13d
cmovlel %ecx, %r13d
cmpq %rcx, %r13
je 0x718b
movl (%r12,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x717a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq