// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0x28(%rax)
movq 0x10(%rax), %rcx
movl 0xc(%rcx), %ecx
movl %ecx, 0x2c(%rax)
movq 0x10(%rax), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x30(%rax)
movl 0x2c(%rax), %ecx
shll %ecx
movl %ecx, 0x34(%rax)
movl 0x30(%rax), %ecx
shll %ecx
movl %ecx, 0x38(%rax)
cmpq $0x0, 0x50(%rax)
je 0xc1f3
movq -0x48(%rbp), %rax
movq 0xb0(%rax), %rdi
movq 0x50(%rax), %rsi
movl 0x34(%rax), %edx
callq 0x7a30
movq -0x48(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x48(%rbp), %rax
movq 0xb0(%rax), %rdi
movl 0x34(%rax), %esi
callq 0x77d0
movq -0x48(%rbp), %rdi
movq %rax, 0x50(%rdi)
callq 0xc520
movq -0x48(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xc253
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0xc247
movq -0x50(%rbp), %rdi
callq 0x67b0
movq -0x50(%rbp), %rdi
movl $0x28, %esi
callq 0x31d0
movq -0x48(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x48(%rbp), %rdi
callq 0xc6c0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x40(%rax)
cmpq $0x0, 0x48(%rax)
je 0xc2a3
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0xc297
movq -0x58(%rbp), %rdi
callq 0x13640
movq -0x58(%rbp), %rdi
movl $0x20, %esi
callq 0x31d0
movq -0x48(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x48(%rbp), %rdi
callq 0xcd10
movq -0x48(%rbp), %rdi
movq %rax, 0x48(%rdi)
callq 0xd3e0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, -0x28(%rbp)
cmpq $0x0, 0x58(%rax)
je 0xc348
movq -0x48(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0xc33c
movq -0x60(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rcx), %rax
movq %rax, -0x70(%rbp)
imulq $0x18, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x68(%rbp)
je 0xc327
movq -0x68(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x80(%rbp)
callq 0x108e0
movq -0x60(%rbp), %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x68(%rbp)
jne 0xc305
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rax
imulq $0x18, %rax, %rsi
addq $0x8, %rsi
callq 0x33c0
movq -0x48(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x48(%rbp), %rcx
movl 0x2c(%rcx), %eax
subl -0x28(%rbp), %eax
subl 0x28(%rcx), %eax
cltq
movq %rax, -0x90(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3040
movq %rax, %rcx
movq -0x90(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x88(%rbp)
cmpq $0x0, %rax
je 0xc3fd
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x108c0
movq -0xa8(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x98(%rbp)
jne 0xc3cc
movq -0x48(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, 0x58(%rax)
leaq -0x38(%rbp), %rdi
callq 0x9790
leaq -0x38(%rbp), %rdi
callq 0x97c0
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %esi
addl 0x28(%rdi), %esi
callq 0xd6d0
andb $0x1, %al
movb %al, -0x39(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x9800
movq -0x48(%rbp), %rdi
callq 0xc120
movq -0x48(%rbp), %rdi
callq 0xbef0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0xc503
movq -0x48(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0xc4f7
movq -0xb0(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rcx), %rax
movq %rax, -0xc0(%rbp)
imulq $0x18, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0xb8(%rbp)
je 0xc4dc
movq -0xb8(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0xd0(%rbp)
callq 0x108e0
movq -0xb0(%rbp), %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xb8(%rbp)
jne 0xc4ab
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rax
imulq $0x18, %rax, %rsi
addq $0x8, %rsi
callq 0x33c0
movq -0x48(%rbp), %rax
movq $0x0, 0x58(%rax)
movb -0x39(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)