// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xf70a
jmp 0xf98c
movq -0x10(%rbp), %rdi
callq 0x10bf0
cmpq $0x0, %rax
jne 0xf765
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x10df0
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xf760
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x10da0
movl -0x4c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf72d
jmp 0xf98c
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10bf0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movl %ecx, -0x2c(%rbp)
movl -0x1c(%rbp), %ecx
movl %ecx, -0x30(%rbp)
movq 0xb0(%rax), %rdi
movl 0x2c(%rax), %esi
callq 0x77d0
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2c(%rbp), %ecx
movb %al, -0x4d(%rbp)
jge 0xf7bf
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
setl %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0xf7cb
jmp 0xf897
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x10da0
movl (%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0xf81e
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf892
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x10da0
movl (%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xf868
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xf890
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf892
jmp 0xf7a6
jmp 0xf899
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xf8cf
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x10da0
movl (%rax), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xf899
jmp 0xf8d1
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xf903
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf8d1
movq -0x10(%rbp), %rdi
callq 0x10980
movq -0x10(%rbp), %rdi
callq 0x10f20
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jae 0xf943
cmpl $0x8, -0x3c(%rbp)
jge 0xf934
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x10f40
jmp 0xf941
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x10f40
jmp 0xf943
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0xf975
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x40(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x10d30
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xf94a
movq -0x48(%rbp), %rax
movq 0xb0(%rax), %rdi
movq -0x38(%rbp), %rsi
movl 0x2c(%rax), %edx
callq 0x7a30
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)