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

	extCand[aVertex].clear();

	int32_t i, adjCand, ci;
	int32_t* adjPos1 = g1->adjPos;
	int32_t* adjPos2 = g2->adjPos;
	int32_t* parentSize = dag->parentSize;
	int32_t* dagArr = dag->dagArr;
	int32_t p, s;
	int32_t* neigh = NULL;
	
	//compute the number of mapped parent
	int32_t numMapped = 0;
	int32_t* mappedParent = global_memory->getLLArray(n);
	for(i = 0; i < parentSize[aVertex]; ++i) {
		if( mapping[ dagArr[adjPos1[aVertex] + i] ] != -1 ) {
			mappedParent[numMapped] = i; //keep the index of the parent
			++numMapped;
		}
	}

	//Case 1: there is no mapped parent of aVertex (root)
	if( numMapped == 0 ) {
		p = coloring->color[ coloring->inv[aVertex] ] >> 1;
		s = coloring->cellSize[ coloring->color[ coloring->inv[aVertex] ] ] >> 1;
		for(i = p; i < p + s; ++i) {
			extCand[aVertex].push_back( cs->candArr[i] );
		}
	}
	else {
		adjCand = mapping[ dagArr[ adjPos1[aVertex] + mappedParent[0] ] ] - n;
		ci = cs->dagColorIndex[ adjPos1[aVertex] + mappedParent[0] ];

		if( numMapped == 1 ) {
			neigh = g2->e[adjCand];
			p = cs->P[ adjPos2[adjCand] + ci ];
			s = cs->S[ adjPos2[adjCand] + ci ];
			for(i = p; i < p + s; ++i) {
				extCand[aVertex].push_back( neigh[i] + n );
			}
		}
		else {
			if( global_mark > INFINITY ) {
				memset(markNode, 0, sizeof(int32_t) * n2);
				global_mark = 0;
			}
			++global_mark;
	
			//Step 1. the first array
			int32_t j, v;
			int32_t* neigh = g2->e[adjCand];
			p = cs->P[ adjPos2[adjCand] + ci ];
			s = cs->S[ adjPos2[adjCand] + ci ];
			for(i = p; i < p + s; ++i)
				markNode[ neigh[i] ] = global_mark;
			++global_mark;

			//Step 2. the second to the second last array
			for(j = 1; j < numMapped - 1; ++j) {
				adjCand = mapping[ dagArr[ adjPos1[aVertex] + mappedParent[j] ] ] - n;
				neigh = g2->e[adjCand];
				ci = cs->dagColorIndex[ adjPos1[aVertex] + mappedParent[j] ];
				p = cs->P[ adjPos2[adjCand] + ci ];
				s = cs->S[ adjPos2[adjCand] + ci ];
				for(i = p; i < p + s; ++i) {
					v = neigh[i];
					if( markNode[v] == global_mark - 1 )
						++(markNode[v]);
				}
				++global_mark;
			}

			//Step 3. the last array
			adjCand = mapping[ dagArr[ adjPos1[aVertex] + mappedParent[numMapped - 1] ] ] - n;
			neigh = g2->e[adjCand];
			ci = cs->dagColorIndex[ adjPos1[aVertex] + mappedParent[numMapped - 1] ];
			p = cs->P[ adjPos2[adjCand] + ci ];
			s = cs->S[ adjPos2[adjCand] + ci ];
			for(i = p; i < p + s; ++i) {
				v = neigh[i];
				if( markNode[v] == global_mark - 1 )
					extCand[aVertex].push_back(v + n);
			}
		} //else of (if numMapped == 1)
	} //else of (if numMapped == 0)

	global_memory->returnLLArray(mappedParent, n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x60(%rdi), %rax
movslq %esi, %r15
leaq (%r15,%r15,2), %rdx
movq (%rax,%rdx,8), %rcx
cmpq %rcx, 0x8(%rax,%rdx,8)
je 0x7c89
leaq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq %rdx, 0x18(%rsp)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x40(%rax), %r13
movq 0x40(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rbx), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %rbp
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %esi
callq 0x4b34
cmpl $0x0, (%r14,%r15,4)
jle 0x7cf6
movq 0x50(%rbx), %rsi
xorl %ecx, %ecx
xorl %r12d, %r12d
movslq (%r13,%r15,4), %rdx
addq %rcx, %rdx
movslq (%rbp,%rdx,4), %rdx
cmpl $-0x1, (%rsi,%rdx,4)
je 0x7ceb
movslq %r12d, %r12
movl %ecx, (%rax,%r12,4)
incl %r12d
incq %rcx
cmpl (%r14,%r15,4), %ecx
jl 0x7cce
jmp 0x7cf9
xorl %r12d, %r12d
testl %r12d, %r12d
movq %rax, 0x30(%rsp)
je 0x7db8
movq 0x48(%rbx), %rdi
movq 0x50(%rbx), %rcx
movslq (%r13,%r15,4), %rdx
movslq (%rax), %rsi
addq %rdx, %rsi
movslq (%rbp,%rsi,4), %rdx
movslq (%rcx,%rdx,4), %r8
movslq 0x2c(%rbx), %rcx
subq %rcx, %r8
movq 0x18(%rdi), %rcx
movslq (%rcx,%rsi,4), %r14
cmpl $0x1, %r12d
jne 0x7e34
movq 0x10(%rsp), %rax
movslq (%rax,%r8,4), %rcx
addq %r14, %rcx
movq 0x10(%rdi), %rdx
movslq (%rdx,%rcx,4), %r14
testq %r14, %r14
movq 0x18(%rsp), %rbp
jle 0x805f
movq 0x18(%rbx), %rdx
movq 0x38(%rdx), %rdx
movq (%rdx,%r8,8), %r12
movq 0x8(%rdi), %rax
movslq (%rax,%rcx,4), %r13
addq %r13, %r14
leaq 0x3c(%rsp), %r15
movq 0x60(%rbx), %rax
leaq (%rax,%rbp,8), %rdi
movl 0x2c(%rbx), %eax
addl (%r12,%r13,4), %eax
movl %eax, 0x3c(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x7da3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x7dab
movq %r15, %rdx
callq 0x8f10
incq %r13
cmpq %r14, %r13
jl 0x7d7a
jmp 0x805f
movq 0x20(%rbx), %rcx
movq 0x8(%rcx), %rax
movq 0x18(%rcx), %rdx
movslq (%rdx,%r15,4), %rdx
movslq (%rax,%rdx,4), %rax
movq 0x20(%rcx), %rcx
movl (%rcx,%rax,4), %ecx
sarl %ecx
testl %ecx, %ecx
movq 0x18(%rsp), %r13
jle 0x805f
sarl %eax
addl %eax, %ecx
movslq %eax, %r14
movslq %ecx, %r15
leaq (,%r14,4), %r12
movq 0x48(%rbx), %rax
movq 0x60(%rbx), %rcx
leaq (%rcx,%r13,8), %rdi
movq (%rax), %rdx
addq %r12, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x7e1e
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x7e23
callq 0x8df0
incq %r14
addq $0x4, %r12
cmpq %r15, %r14
jl 0x7df4
jmp 0x805f
cmpl $0x77359401, 0xc8(%rbx) # imm = 0x77359401
jl 0x7e6a
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
movq %r8, 0x8(%rsp)
callq 0x20e0
movq 0x8(%rsp), %r8
movl $0x0, 0xc8(%rbx)
incl 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0x48(%rbx), %rdx
movq 0x38(%rax), %rax
movq %rax, 0x28(%rsp)
movslq %r8d, %rax
movq 0x8(%rdx), %rcx
movq %rcx, 0x20(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x10(%rdx), %rdx
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
addq %r14, %rcx
movq %rdx, 0x8(%rsp)
movslq (%rdx,%rcx,4), %rsi
testq %rsi, %rsi
jle 0x7ee2
movq 0x28(%rsp), %rdx
movq (%rdx,%rax,8), %rdi
movq 0x20(%rsp), %rax
movslq (%rax,%rcx,4), %r8
addq %r8, %rsi
movq 0xb8(%rbx), %r9
movl 0xc8(%rbx), %eax
movslq (%rdi,%r8,4), %rcx
movl %eax, (%r9,%rcx,4)
incq %r8
cmpq %rsi, %r8
jl 0x7ecc
incl 0xc8(%rbx)
leal -0x1(%r12), %eax
movl %eax, 0x4(%rsp)
cmpl $0x3, %r12d
jl 0x7fa2
movq 0x50(%rbx), %r8
movq 0xb8(%rbx), %r9
movq 0x40(%rsp), %rax
movq 0x18(%rax), %r10
movl 0x4(%rsp), %r11d
movl $0x1, %r12d
movslq (%r13,%r15,4), %rax
movq 0x30(%rsp), %rcx
movslq (%rcx,%r12,4), %rcx
addq %rax, %rcx
movslq (%rbp,%rcx,4), %rax
movslq (%r8,%rax,4), %rsi
movslq 0x2c(%rbx), %rax
subq %rax, %rsi
movslq (%r10,%rcx,4), %rcx
movq 0x10(%rsp), %rax
movslq (%rax,%rsi,4), %rax
addq %rcx, %rax
movq 0x8(%rsp), %rcx
movslq (%rcx,%rax,4), %r14
testq %r14, %r14
jle 0x7f90
movq 0x28(%rsp), %rcx
movq (%rcx,%rsi,8), %rdi
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %rsi
addq %rsi, %r14
movslq (%rdi,%rsi,4), %rax
movl (%r9,%rax,4), %ecx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, %ecx
jne 0x7f88
incl %ecx
movl %ecx, (%r9,%rax,4)
incq %rsi
cmpq %r14, %rsi
jl 0x7f6e
incl 0xc8(%rbx)
incq %r12
cmpq %r11, %r12
jne 0x7f1a
movq 0x50(%rbx), %rax
movslq (%r13,%r15,4), %rcx
movslq 0x4(%rsp), %rdx
movq 0x30(%rsp), %rsi
movslq (%rsi,%rdx,4), %rdx
addq %rcx, %rdx
movslq (%rbp,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rsi
movslq 0x2c(%rbx), %rax
subq %rax, %rsi
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movslq (%rax,%rdx,4), %rcx
movq 0x10(%rsp), %rax
movslq (%rax,%rsi,4), %rax
addq %rcx, %rax
movq 0x8(%rsp), %rcx
movslq (%rcx,%rax,4), %r12
testq %r12, %r12
movq 0x18(%rsp), %rbp
jle 0x805f
movq 0x28(%rsp), %rcx
movq (%rcx,%rsi,8), %r14
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %r13
addq %r13, %r12
leaq 0x38(%rsp), %r15
movslq (%r14,%r13,4), %rax
movq 0xb8(%rbx), %rcx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x8057
movq 0x60(%rbx), %rcx
leaq (%rcx,%rbp,8), %rdi
addl 0x2c(%rbx), %eax
movl %eax, 0x38(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x804f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x8057
movq %r15, %rdx
callq 0x8f10
incq %r13
cmpq %r12, %r13
jl 0x8012
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %edx
movq 0x30(%rsp), %rsi
callq 0x4cf0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq