// File: SNUCSE-CTA[P]GI/src/backtrack.cpp
// Function: Backtrack::mapBinaryCell()
int32_t Backtrack::mapBinaryCell()
{
	#ifdef DEBUG
	cout << __PRETTY_FUNCTION__ << endl;
	#endif

	int32_t numMatching = 0;
	int32_t i, j, u, v, child;
	int32_t numNode = coloring->numNode;
	int32_t* perm = coloring->perm;
	int32_t* cellSize = coloring->cellSize;
	int32_t* adjPos1 = g1->adjPos;
	char* one1 = g1->one;

	int32_t* childSize = dag->childSize;
	int32_t* parentSize = dag->parentSize;
	int32_t* dagArr = dag->dagArr;

	memset(mapping, -1, sizeof(int32_t) * n2);
	memset(numMappedParent, 0, sizeof(int32_t) * n);
	//for each cell
	for(i = 0; i < numNode; i += cellSize[i]) {
		if( cellSize[i] != 2 ) 
			continue;

		//for each binary cell
		if( perm[i] < n ) {
			u = perm[i];
			v = perm[i + 1];
		}
		else {
			u = perm[i + 1];
			v = perm[i];
		}

		if( one1[u] == 1 ) //coreness-1 vertex
			continue;

		mapping[u] = v;
		mapping[v] = u;
		++numMatching;

		//DAG-ordering
		for(j = 0; j < childSize[u]; ++j) {
			child = dagArr[ adjPos1[u] + parentSize[u] + j ];
			++(numMappedParent[child]);
		}
	} //for(i)

	//build heap for extendable vertices
	heap->size = 0;
	for(u = 0; u < n; ++u) {
		//for each extendable vertex
		if( one1[u] == 0 && mapping[u] == -1 && numMappedParent[u] == parentSize[u] ) {
			weight[u] = computeWeight(u);
			if( weight[u] == 0 ) //isomorphism does not exist
				return -1;

			++(heap->size); //note that heap[0] have to be empty.
			heap->heap[heap->size] = u;
			heap->locate[u] = heap->size;
		}
	}
	heap->buildMinHeap(weight);

	return numMatching;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x14(%rbp)
movq 0x20(%rax), %rcx
movl (%rcx), %ecx
movl %ecx, -0x2c(%rbp)
movq 0x20(%rax), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, -0x38(%rbp)
movq 0x20(%rax), %rcx
movq 0x20(%rcx), %rcx
movq %rcx, -0x40(%rbp)
movq 0x10(%rax), %rcx
movq 0x40(%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rcx
movq 0x30(%rcx), %rcx
movq %rcx, -0x50(%rbp)
movq 0x40(%rax), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, -0x58(%rbp)
movq 0x40(%rax), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x60(%rbp)
movq 0x40(%rax), %rcx
movq 0x20(%rcx), %rcx
movq %rcx, -0x68(%rbp)
movq 0x50(%rax), %rdi
movslq 0x34(%rax), %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x3110
movq -0x70(%rbp), %rax
movq 0x78(%rax), %rdi
movslq 0x2c(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3110
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xd5b7
movq -0x40(%rbp), %rax
movslq -0x18(%rbp), %rcx
cmpl $0x2, (%rax,%rcx,4)
je 0xd4ab
jmp 0xd5a1
movq -0x70(%rbp), %rcx
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rdx
movl (%rax,%rdx,4), %eax
cmpl 0x2c(%rcx), %eax
jge 0xd4e2
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0xd503
movq -0x38(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movq -0x50(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0xd519
jmp 0xd5a1
movq -0x70(%rbp), %rax
movl -0x24(%rbp), %esi
movq 0x50(%rax), %rcx
movslq -0x20(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x20(%rbp), %edx
movq 0x50(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x58(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xd59f
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
movq -0x48(%rbp), %rdx
movslq -0x20(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
movq -0x60(%rbp), %rsi
movslq -0x20(%rbp), %rdi
addl (%rsi,%rdi,4), %edx
addl -0x1c(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x28(%rbp)
movq 0x78(%rax), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd549
jmp 0xd5a1
movq -0x40(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0xd48c
movq -0x70(%rbp), %rax
movq 0x68(%rax), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0x20(%rbp)
movq -0x70(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x2c(%rcx), %eax
jge 0xd6a4
movq -0x50(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xd694
movq -0x70(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0xd694
movq -0x70(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x60(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0xd694
movq -0x70(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0xe6a0
movl %eax, %esi
movq -0x70(%rbp), %rax
movq 0x70(%rax), %rcx
movslq -0x20(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movq 0x70(%rax), %rax
movslq -0x20(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xd658
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd6bb
movq -0x70(%rbp), %rax
movq 0x68(%rax), %rcx
movl 0x10(%rcx), %edx
addl $0x1, %edx
movl %edx, 0x10(%rcx)
movl -0x20(%rbp), %esi
movq 0x68(%rax), %rcx
movq (%rcx), %rcx
movq 0x68(%rax), %rdx
movslq 0x10(%rdx), %rdx
movl %esi, (%rcx,%rdx,4)
movq 0x68(%rax), %rcx
movl 0x10(%rcx), %edx
movq 0x68(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xd696
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xd5cd
movq -0x70(%rbp), %rax
movq 0x68(%rax), %rdi
movq 0x70(%rax), %rsi
callq 0x138b0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)