// File: /workspace/github_cpp_makefile_star2_O3/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 0x7b77
leaq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq %rdx, 0x28(%rsp)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x40(%rax), %r13
movq 0x40(%rcx), %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rbx), %rax
movq 0x18(%rax), %r12
movq 0x20(%rax), %rbp
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %esi
callq 0x4aba
movl (%r12,%r15,4), %edx
testl %edx, %edx
movq %rax, 0x38(%rsp)
jle 0x7ca8
movq 0x50(%rbx), %rdi
xorl %ecx, %ecx
xorl %r14d, %r14d
movslq (%r13,%r15,4), %rsi
addq %rcx, %rsi
movslq (%rbp,%rsi,4), %rsi
cmpl $-0x1, (%rdi,%rsi,4)
je 0x7be7
movslq %r14d, %r14
movl %ecx, (%rax,%r14,4)
incl %r14d
movl (%r12,%r15,4), %edx
incq %rcx
cmpl %edx, %ecx
jl 0x7bc6
testl %r14d, %r14d
je 0x7ca8
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdi
movslq (%r13,%r15,4), %rcx
movslq (%rax), %rdx
addq %rcx, %rdx
movslq (%rbp,%rdx,4), %rcx
movslq (%rdi,%rcx,4), %r8
movslq 0x2c(%rbx), %rax
subq %rax, %r8
movq 0x18(%rsi), %rax
movslq (%rax,%rdx,4), %r9
cmpl $0x1, %r14d
jne 0x7d24
movq 0x20(%rsp), %rax
movslq (%rax,%r8,4), %rax
addq %r9, %rax
movq 0x10(%rsi), %rcx
movslq (%rcx,%rax,4), %r14
testq %r14, %r14
movq 0x28(%rsp), %rbp
jle 0x7f4d
movq 0x18(%rbx), %rcx
movq 0x38(%rcx), %rcx
movq (%rcx,%r8,8), %r12
movq 0x8(%rsi), %rcx
movslq (%rcx,%rax,4), %r13
addq %r13, %r14
leaq 0x44(%rsp), %r15
movq 0x60(%rbx), %rax
leaq (%rax,%rbp,8), %rdi
movl 0x2c(%rbx), %eax
addl (%r12,%r13,4), %eax
movl %eax, 0x44(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x7c93
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x7c9b
movq %r15, %rdx
callq 0x8e1a
incq %r13
cmpq %r14, %r13
jl 0x7c6a
jmp 0x7f4d
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 0x28(%rsp), %r13
jle 0x7f4d
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 0x7d0e
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x7d13
callq 0x8cfa
incq %r14
addq $0x4, %r12
cmpq %r15, %r14
jl 0x7ce4
jmp 0x7f4d
movl 0xc8(%rbx), %r12d
cmpl $0x77359401, %r12d      # imm = 0x77359401
jl 0x7d65
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
xorl %r12d, %r12d
xorl %esi, %esi
movq %r8, 0x18(%rsp)
movq %r9, 0x8(%rsp)
callq 0x20e0
movq 0x8(%rsp), %r9
movq 0x18(%rsp), %r8
movq 0x48(%rbx), %rsi
leal 0x1(%r12), %edi
movl %edi, 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0x38(%rax), %rax
movq %rax, 0x8(%rsp)
movslq %r8d, %rax
movq 0x8(%rsi), %rcx
movq %rcx, 0x30(%rsp)
movq 0x10(%rsi), %rdx
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
addq %r9, %rcx
movq %rdx, 0x18(%rsp)
movslq (%rdx,%rcx,4), %r8
testq %r8, %r8
jle 0x7dd3
movq 0x8(%rsp), %rdx
movq (%rdx,%rax,8), %r9
movq 0x30(%rsp), %rax
movslq (%rax,%rcx,4), %r10
addq %r10, %r8
movq 0xb8(%rbx), %r11
movslq (%r9,%r10,4), %rax
movl %edi, (%r11,%rax,4)
incq %r10
cmpq %r8, %r10
jl 0x7dc3
addl $0x2, %r12d
movl %r12d, 0xc8(%rbx)
leal -0x1(%r14), %eax
movl %eax, 0x14(%rsp)
movq 0x50(%rbx), %rdi
movq 0x18(%rsi), %rsi
cmpl $0x3, %r14d
jl 0x7e9d
movq 0xb8(%rbx), %r9
movl 0x14(%rsp), %r10d
movl $0x1, %r11d
movslq (%r13,%r15,4), %rax
movq 0x38(%rsp), %rcx
movslq (%rcx,%r11,4), %rcx
addq %rax, %rcx
movslq (%rbp,%rcx,4), %rax
movslq (%rdi,%rax,4), %r8
movslq 0x2c(%rbx), %rax
subq %rax, %r8
movslq (%rsi,%rcx,4), %rcx
movq 0x20(%rsp), %rax
movslq (%rax,%r8,4), %rax
addq %rcx, %rax
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %r14
testq %r14, %r14
jle 0x7e87
movq 0x8(%rsp), %rcx
movq (%rcx,%r8,8), %r12
movq 0x30(%rsp), %rcx
movslq (%rcx,%rax,4), %r8
addq %r8, %r14
movslq (%r12,%r8,4), %rax
movl (%r9,%rax,4), %ecx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, %ecx
jne 0x7e78
incl %ecx
movl %ecx, (%r9,%rax,4)
incq %r8
cmpq %r14, %r8
jl 0x7e5e
movl 0xc8(%rbx), %r12d
incl %r12d
movl %r12d, 0xc8(%rbx)
incq %r11
cmpq %r10, %r11
jne 0x7e0a
movslq (%r13,%r15,4), %rax
movslq 0x14(%rsp), %rcx
movq 0x38(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
addq %rax, %rcx
movslq (%rbp,%rcx,4), %rax
movslq (%rdi,%rax,4), %rdi
movslq 0x2c(%rbx), %rax
subq %rax, %rdi
movslq (%rsi,%rcx,4), %rcx
movq 0x20(%rsp), %rax
movslq (%rax,%rdi,4), %rax
addq %rcx, %rax
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %r14
testq %r14, %r14
movq 0x28(%rsp), %rbp
jle 0x7f4d
movq 0x8(%rsp), %rcx
movq (%rcx,%rdi,8), %r12
movq 0x30(%rsp), %rcx
movslq (%rcx,%rax,4), %r13
addq %r13, %r14
leaq 0x40(%rsp), %r15
movslq (%r12,%r13,4), %rax
movq 0xb8(%rbx), %rcx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x7f45
movq 0x60(%rbx), %rcx
leaq (%rcx,%rbp,8), %rdi
addl 0x2c(%rbx), %eax
movl %eax, 0x40(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x7f3d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x7f45
movq %r15, %rdx
callq 0x8e1a
incq %r13
cmpq %r14, %r13
jl 0x7f00
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %edx
movq 0x38(%rsp), %rsi
callq 0x4c64
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq