// File: /workspace/github_cpp_makefile_star2_O2/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 0x5284
movq 0xb0(%rbx), %rdi
movl %eax, %edx
callq 0x3fee
andq $0x0, 0x50(%rbx)
movl 0x34(%rbx), %eax
movq 0xb0(%rbx), %rdi
movl %eax, %esi
callq 0x3f1a
movq %rax, 0x50(%rbx)
movq %rbx, %rdi
callq 0x543c
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x52bf
movq %r14, %rdi
callq 0x3b9c
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x2190
andq $0x0, 0x40(%rbx)
movq %rbx, %rdi
callq 0x5558
movq %rax, 0x40(%rbx)
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0x52ec
movq %r14, %rdi
callq 0x7fe8
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x2190
andq $0x0, 0x48(%rbx)
movq %rbx, %rdi
callq 0x5900
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x5d5c
movl %eax, %ebp
movq 0x58(%rbx), %r15
testq %r15, %r15
je 0x5344
leaq -0x8(%r15), %r14
movq -0x8(%r15), %r12
testq %r12, %r12
je 0x532f
addq $-0x18, %r15
imulq $0x18, %r12, %r13
leaq (%r15,%r13), %rdi
callq 0x7806
addq $-0x18, %r13
jne 0x5320
imulq $0x18, %r12, %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x2300
andq $0x0, 0x58(%rbx)
movl 0x2c(%rbx), %r13d
movl 0x28(%rbx), %r12d
addl %ebp, %r12d
movl %r13d, %eax
subl %r12d, %eax
movslq %eax, %r14
pushq $0x18
popq %rcx
movq %r14, %rax
mulq %rcx
seto %cl
addq $0x8, %rax
pushq $-0x1
popq %rdi
cmovbq %rdi, %rax
testb %cl, %cl
cmoveq %rax, %rdi
callq 0x2030
leaq 0x8(%rax), %r15
movq %r14, (%rax)
cmpl %r12d, %r13d
je 0x53ad
imulq $0x18, %r14, %rcx
addq $-0x18, %rcx
movq %rcx, %rax
xorl %edx, %edx
pushq $0x18
popq %rsi
divq %rsi
subq %rdx, %rcx
addq $0x18, %rcx
movq %r15, %rdi
xorl %esi, %esi
movq %rcx, %rdx
callq 0x2100
movq %r15, 0x58(%rbx)
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x43c8
movq %r14, %rdi
callq 0x43d0
addl 0x28(%rbx), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5f0e
movl %eax, %ebp
movq %r14, %rdi
callq 0x43de
movsd %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x50fe
movq 0x58(%rbx), %r15
testq %r15, %r15
je 0x542b
leaq -0x8(%r15), %r14
movq -0x8(%r15), %r12
testq %r12, %r12
je 0x5416
addq $-0x18, %r15
imulq $0x18, %r12, %r13
leaq (%r15,%r13), %rdi
callq 0x7806
addq $-0x18, %r13
jne 0x5407
imulq $0x18, %r12, %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x2300
andq $0x0, 0x58(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq