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

	if( aSource.size() == 0)
		return;
	if( aTo.size() == 0 ) {
		aTo.resize( aSource.size() );
		copy(aSource.begin(), aSource.end(), aTo.begin());
		return;
	}

	int32_t ind1 = 0;
	int32_t ind2 = 0;
	int32_t size1 = aTo.size();
	int32_t size2 = aSource.size();
	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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10bf0
cmpq $0x0, %rax
jne 0xf413
jmp 0xf6d2
movq -0x10(%rbp), %rdi
callq 0x10bf0
cmpq $0x0, %rax
jne 0xf480
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10bf0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x10df0
movq -0x18(%rbp), %rdi
callq 0x10c80
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10ef0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10c80
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x10e80
movq %rax, -0x38(%rbp)
jmp 0xf6d2
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10bf0
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10bf0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movl %ecx, -0x48(%rbp)
movq 0xb0(%rax), %rdi
movl 0x2c(%rax), %esi
callq 0x77d0
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x3c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x44(%rbp), %ecx
movb %al, -0x69(%rbp)
jge 0xf4e0
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
setl %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0xf4ec
jmp 0xf5d9
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10da0
movl (%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x10da0
movq %rax, %rcx
movl -0x70(%rbp), %eax
cmpl (%rcx), %eax
jne 0xf54f
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xf5d4
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10da0
movl (%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x10da0
movq %rax, %rcx
movl -0x74(%rbp), %eax
cmpl (%rcx), %eax
jge 0xf5a6
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf5d2
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xf5d4
jmp 0xf4c7
jmp 0xf5db
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0xf611
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf5db
jmp 0xf613
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0xf649
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xf613
movq -0x10(%rbp), %rdi
callq 0x10980
movq -0x10(%rbp), %rdi
callq 0x10f20
movslq -0x54(%rbp), %rcx
cmpq %rcx, %rax
jae 0xf689
cmpl $0x8, -0x54(%rbp)
jge 0xf67a
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x10f40
jmp 0xf687
movq -0x10(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x10f40
jmp 0xf689
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xf6bb
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0x58(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x10d30
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xf690
movq -0x60(%rbp), %rax
movq 0xb0(%rax), %rdi
movq -0x50(%rbp), %rsi
movl 0x2c(%rax), %edx
callq 0x7a30
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)