// File: /workspace/github_cpp_makefile_star2_O3/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 0x8382
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %rbx
movq 0x8(%rsi), %r13
subq (%rsi), %r13
je 0x835d
movq %rdi, %rax
shrq $0x2, %r13
movq 0xb0(%rdi), %rdi
movq %rax, (%rsp)
movl 0x2c(%rax), %esi
callq 0x4aba
movq %rax, %r15
testl %r13d, %r13d
setle %cl
testl %ebp, %ebp
setle %dl
xorl %eax, %eax
orb %cl, %dl
movl $0x0, %ecx
movl $0x0, %r14d
jne 0x82c0
movq (%rbx), %rdx
xorl %r14d, %r14d
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 0x82a4
movl %esi, (%r15,%r14,4)
incl %ecx
jmp 0x82b2
jge 0x82ae
movl %esi, (%r15,%r14,4)
incl %ecx
jmp 0x82b4
movl %edi, (%r15,%r14,4)
incl %eax
incq %r14
cmpl %r13d, %ecx
jge 0x82c0
cmpl %ebp, %eax
jl 0x828b
cmpl %r13d, %ecx
jge 0x82f5
movl %r14d, %r14d
movslq %ecx, %rdx
leaq (,%rdx,4), %rcx
addq (%rbx), %rcx
movslq %r13d, %rsi
subq %rdx, %rsi
leaq (%r15,%r14,4), %rdi
xorl %edx, %edx
movl (%rcx,%rdx,4), %r8d
movl %r8d, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rsi
jne 0x82e2
addl %edx, %r14d
cmpl %ebp, %eax
jge 0x8320
movl %r14d, %r14d
movslq %eax, %rcx
movslq %ebp, %rax
leaq (%r12,%rcx,4), %rdx
subq %rcx, %rax
leaq (%r15,%r14,4), %rsi
xorl %ecx, %ecx
movl (%rdx,%rcx,4), %edi
movl %edi, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x830f
addl %ecx, %r14d
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x832d
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movl %r14d, %r12d
cmpq %r12, %rcx
jae 0x8353
cmpl $0x7, %r14d
ja 0x8391
movl $0x8, %esi
movq %rbx, %rdi
callq 0x891c
movq %r15, %r13
testl %r14d, %r14d
jne 0x839f
jmp 0x83cd
movslq %ebp, %rsi
movq %rbx, %rdi
callq 0x88ea
testl %ebp, %ebp
jle 0x8382
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 0x8373
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r12, %rsi
callq 0x891c
movq %r15, %r13
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x83b9
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x83c4
movq %rbx, %rdi
movq %r13, %rdx
callq 0x8cfa
addq $0x4, %r13
decq %r12
jne 0x839f
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 0x4c64