// File: /workspace/github_cpp_makefile_star2_O3/SNUCSE-CTA[P]GI/src/backtrack.cpp
// Function: Backtrack::run(Coloring*, Graph*, Graph*, int)
bool Backtrack::run(Coloring* aColoring, Graph* aG1, Graph* aG2, int32_t aNumTreeNode)
{
	#ifdef DEBUG
	cout << __PRETTY_FUNCTION__ << endl;
	#endif

	g1 = aG1;
	g2 = aG2;
	coloring = aColoring;
	numTreeNode = aNumTreeNode; 

	n = g1->numNode;
	e = g1->numEdge;
	n2 = n * 2;
	e2 = e * 2;

	if( mapping != NULL ) {
		global_memory->returnLLArray(mapping, n2);
		mapping = NULL;
	}
	mapping = global_memory->getLLArray(n2);
	initWorkspace();

	if( dag != NULL ) {
		delete dag;
		dag = NULL;
	}
	dag = buildDAG(); //isBinary is set in this function.

	if( cs != NULL ) {
		delete cs;
		cs = NULL;
	}
	cs = buildCS();

	int32_t numMatching = mapBinaryCell();
	if( failingset != NULL ) {
		delete[] failingset;
		failingset = NULL;
	}
	failingset = new vector<int32_t>[n - numMatching - numTreeNode];
	
	Timer t;
	t.start();
	bool result = backtrack(numMatching + numTreeNode);
	setSearchTime(t.end());
	
	clearWorkspace();
	if( failingset != NULL ) {
		delete[] failingset;
		failingset = NULL;
	}

	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %rsi, 0x20(%rdi)
movl %r8d, 0x28(%rdi)
movl 0xc(%rdx), %eax
movl %eax, 0x2c(%rdi)
movl 0x10(%rdx), %ecx
movl %ecx, 0x30(%rdi)
addl %eax, %eax
movl %eax, 0x34(%rdi)
addl %ecx, %ecx
movl %ecx, 0x38(%rdi)
movq 0x50(%rdi), %rsi
testq %rsi, %rsi
je 0x5fed
movq 0xb0(%rbx), %rdi
movl %eax, %edx
callq 0x4c64
movq $0x0, 0x50(%rbx)
movl 0x34(%rbx), %eax
movq 0xb0(%rbx), %rdi
movl %eax, %esi
callq 0x4aba
movq %rax, 0x50(%rbx)
movq %rbx, %rdi
callq 0x61f2
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x602d
movq %r14, %rdi
callq 0x46de
movl $0x28, %esi
movq %r14, %rdi
callq 0x2190
movq $0x0, 0x40(%rbx)
movq %rbx, %rdi
callq 0x631c
movq %rax, 0x40(%rbx)
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0x605f
movq %r14, %rdi
callq 0x9010
movl $0x20, %esi
movq %r14, %rdi
callq 0x2190
movq $0x0, 0x48(%rbx)
movq %rbx, %rdi
callq 0x6712
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x6c40
movl %eax, %ebp
movq 0x58(%rbx), %r14
testq %r14, %r14
je 0x60cf
movq -0x8(%r14), %r15
addq $-0x8, %r14
testq %r15, %r15
je 0x60b3
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
movq -0x10(%r14,%r12), %rdi
testq %rdi, %rdi
je 0x60ad
movq (%r14,%r12), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %r12
jne 0x6097
leaq (%r15,%r15,2), %rax
leaq 0x8(,%rax,8), %rsi
movq %r14, %rdi
callq 0x2320
movq $0x0, 0x58(%rbx)
movl 0x2c(%rbx), %r12d
movl 0x28(%rbx), %r13d
addl %ebp, %r13d
movl %r12d, %eax
subl %r13d, %eax
movslq %eax, %r14
movl $0x18, %ecx
movq %r14, %rax
mulq %rcx
seto %cl
addq $0x8, %rax
movq $-0x1, %rdi
cmovbq %rdi, %rax
testb %cl, %cl
cmoveq %rax, %rdi
callq 0x2030
leaq 0x8(%rax), %r15
movq %r14, (%rax)
cmpl %r13d, %r12d
je 0x614a
leaq (%r14,%r14,2), %rax
leaq -0x18(,%rax,8), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r15, 0x58(%rbx)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4f1c
movq %r14, %rdi
callq 0x4f24
addl 0x28(%rbx), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6dfa
movl %eax, %ebp
movq %r14, %rdi
callq 0x4f32
movsd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x5e36
movq 0x58(%rbx), %r14
testq %r14, %r14
je 0x61e0
movq -0x8(%r14), %r15
addq $-0x8, %r14
testq %r15, %r15
je 0x61c4
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
movq -0x10(%r14,%r12), %rdi
testq %rdi, %rdi
je 0x61be
movq (%r14,%r12), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %r12
jne 0x61a8
leaq (%r15,%r15,2), %rax
leaq 0x8(,%rax,8), %rsi
movq %r14, %rdi
callq 0x2320
movq $0x0, 0x58(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop