// File: /workspace/github_cpp_makefile_star2_O2/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
imulq $0x18, %r15, %rdx
movq (%rax,%rdx), %rcx
cmpq %rcx, 0x8(%rax,%rdx)
je 0x6aaa
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq %rdx, 0x20(%rsp)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x40(%rax), %rbp
movq 0x40(%rcx), %rax
movq %rax, 0x18(%rsp)
movq 0x40(%rbx), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r13
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %esi
callq 0x3f1a
movq %rax, 0x8(%rsp)
movq 0x50(%rbx), %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
movq 0x8(%rsp), %rsi
cmpl (%r14,%r15,4), %ecx
jge 0x6b19
movslq (%rbp,%r15,4), %rdx
addq %rcx, %rdx
movslq (%r13,%rdx,4), %rdx
cmpl $-0x1, (%rax,%rdx,4)
je 0x6b14
movslq %r12d, %rdx
movl %ecx, (%rsi,%rdx,4)
incl %r12d
incq %rcx
jmp 0x6af2
testl %r12d, %r12d
je 0x6bb5
movslq (%rbp,%r15,4), %rcx
movq 0x8(%rsp), %rdx
movslq (%rdx), %rdx
addq %rcx, %rdx
movslq (%r13,%rdx,4), %rcx
movslq (%rax,%rcx,4), %r14
movslq 0x2c(%rbx), %rax
subq %rax, %r14
movq 0x48(%rbx), %r10
movq 0x18(%r10), %rax
movslq (%rax,%rdx,4), %rcx
cmpl $0x1, %r12d
jne 0x6c11
movq 0x18(%rbx), %rax
movq 0x38(%rax), %rax
movq (%rax,%r14,8), %r12
movq 0x18(%rsp), %rax
movslq (%rax,%r14,4), %rax
addq %rcx, %rax
movq 0x8(%r10), %rcx
movq 0x10(%r10), %rdx
movslq (%rcx,%rax,4), %r14
movslq (%rdx,%rax,4), %r13
addq %r14, %r13
leaq 0x2c(%rsp), %r15
movq 0x20(%rsp), %rbp
cmpq %r13, %r14
jge 0x6def
movq 0x60(%rbx), %rdi
addq %rbp, %rdi
movl 0x2c(%rbx), %eax
addl (%r12,%r14,4), %eax
movl %eax, 0x2c(%rsp)
movq %r15, %rsi
callq 0x7dae
incq %r14
jmp 0x6b8d
movq 0x20(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rax), %rdx
movslq (%rdx,%r15,4), %rdx
movslq (%rcx,%rdx,4), %rcx
movq 0x20(%rax), %rax
movl (%rax,%rcx,4), %eax
sarl %ecx
sarl %eax
addl %ecx, %eax
movslq %ecx, %r14
movslq %eax, %r15
leaq (,%r14,4), %r12
movq 0x20(%rsp), %r13
cmpq %r15, %r14
jge 0x6def
movq 0x60(%rbx), %rdi
addq %r13, %rdi
movq 0x48(%rbx), %rax
movq (%rax), %rsi
addq %r12, %rsi
callq 0x7720
incq %r14
addq $0x4, %r12
jmp 0x6be9
movq %rcx, 0x10(%rsp)
movl 0xc8(%rbx), %eax
cmpl $0x77359401, %eax       # imm = 0x77359401
jl 0x6c3f
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
xorl %eax, %eax
movq 0x48(%rbx), %r10
movq %rax, 0x40(%rsp)
leal 0x1(%rax), %edi
movl %edi, 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0xb8(%rbx), %r8
movq 0x38(%rax), %rsi
movslq %r14d, %rax
movq (%rsi,%rax,8), %r9
movq 0x8(%r10), %rdx
movq %r10, 0x38(%rsp)
movq 0x10(%r10), %r11
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
addq 0x10(%rsp), %rax
movq %rdx, 0x10(%rsp)
movslq (%rdx,%rax,4), %r10
movq %r11, 0x30(%rsp)
movslq (%r11,%rax,4), %r11
addq %r10, %r11
cmpq %r11, %r10
jge 0x6ca5
movslq (%r9,%r10,4), %rax
movl %edi, (%r8,%rax,4)
incq %r10
jmp 0x6c93
movq 0x40(%rsp), %rax
addl $0x2, %eax
movl %eax, 0xc8(%rbx)
decl %r12d
movq 0x50(%rbx), %r8
movslq %r12d, %rdi
pushq $0x1
popq %r9
cmpq %rdi, %r9
jge 0x6d56
movslq (%rbp,%r15,4), %rax
movq 0x8(%rsp), %rcx
movslq (%rcx,%r9,4), %rcx
addq %rax, %rcx
movslq (%r13,%rcx,4), %rax
movslq (%r8,%rax,4), %rax
movslq 0x2c(%rbx), %r10
subq %r10, %rax
movq (%rsi,%rax,8), %r10
movq 0x38(%rsp), %rdx
movq 0x18(%rdx), %r11
movslq (%r11,%rcx,4), %rcx
movq 0x18(%rsp), %rdx
movslq (%rdx,%rax,4), %rax
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %r11
movq 0x30(%rsp), %rcx
movslq (%rcx,%rax,4), %r14
addq %r11, %r14
movq 0xb8(%rbx), %r12
cmpq %r14, %r11
jge 0x6d48
movslq (%r10,%r11,4), %rax
movl (%r12,%rax,4), %ecx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, %ecx
jne 0x6d43
incl %ecx
movl %ecx, (%r12,%rax,4)
incq %r11
jmp 0x6d24
incl 0xc8(%rbx)
incq %r9
jmp 0x6cc1
movq 0x50(%rbx), %rax
movslq (%rbp,%r15,4), %rcx
movq 0x8(%rsp), %rdx
movslq (%rdx,%rdi,4), %rdx
addq %rcx, %rdx
movslq (%r13,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rax
movslq 0x2c(%rbx), %rcx
subq %rcx, %rax
movq (%rsi,%rax,8), %r14
movq 0x38(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq (%rcx,%rdx,4), %rcx
movq 0x18(%rsp), %rdx
movslq (%rdx,%rax,4), %rax
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %r12
movq 0x30(%rsp), %rcx
movslq (%rcx,%rax,4), %r13
addq %r12, %r13
leaq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbp
cmpq %r13, %r12
jge 0x6def
movslq (%r14,%r12,4), %rax
movq 0xb8(%rbx), %rcx
movl 0xc8(%rbx), %edx
decl %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x6dea
movq 0x60(%rbx), %rdi
addq %rbp, %rdi
addl 0x2c(%rbx), %eax
movl %eax, 0x28(%rsp)
movq %r15, %rsi
callq 0x7dae
incq %r12
jmp 0x6db7
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %edx
movq 0x8(%rsp), %rsi
callq 0x3fee
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq