// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %rax
movq %rdi, %rbx
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %rsi, 0x20(%rdi)
movl %r8d, 0x28(%rdi)
movl 0xc(%rdx), %edx
movl %edx, 0x2c(%rdi)
movl 0x10(%rax), %eax
movl %eax, 0x30(%rdi)
addl %edx, %edx
movl %edx, 0x34(%rdi)
addl %eax, %eax
movl %eax, 0x38(%rdi)
movq 0x50(%rdi), %rsi
testq %rsi, %rsi
je 0x609d
movq 0xb0(%rbx), %rdi
callq 0x4cf0
movq $0x0, 0x50(%rbx)
movq 0xb0(%rbx), %rdi
movl 0x34(%rbx), %esi
callq 0x4b34
movq %rax, 0x50(%rbx)
movq %rbx, %rdi
callq 0x62a2
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x60de
movq %r14, %rdi
callq 0x4758
movl $0x28, %esi
movq %r14, %rdi
callq 0x2190
movq $0x0, 0x40(%rbx)
movq %rbx, %rdi
callq 0x63cc
movq %rax, 0x40(%rbx)
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0x6110
movq %r14, %rdi
callq 0x9100
movl $0x20, %esi
movq %r14, %rdi
callq 0x2190
movq $0x0, 0x48(%rbx)
movq %rbx, %rdi
callq 0x67b2
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x6cdc
movl %eax, %ebp
movq 0x58(%rbx), %r14
testq %r14, %r14
je 0x6180
movq -0x8(%r14), %r15
addq $-0x8, %r14
testq %r15, %r15
je 0x6164
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
movq -0x10(%r14,%r12), %rdi
testq %rdi, %rdi
je 0x615e
movq (%r14,%r12), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %r12
jne 0x6148
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 0x61fb
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 0x4fa8
movq %r14, %rdi
callq 0x4fb0
addl 0x28(%rbx), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6e98
movl %eax, %ebp
movq %r14, %rdi
callq 0x4fbe
movsd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x5ee8
movq 0x58(%rbx), %r14
testq %r14, %r14
je 0x6291
movq -0x8(%r14), %r15
addq $-0x8, %r14
testq %r15, %r15
je 0x6275
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
movq -0x10(%r14,%r12), %rdi
testq %rdi, %rdi
je 0x626f
movq (%r14,%r12), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %r12
jne 0x6259
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