// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x60(%rax), %rdi
movslq -0xc(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x10980
movq -0x80(%rbp), %rax
movq 0x10(%rax), %rcx
movq 0x40(%rcx), %rcx
movq %rcx, -0x20(%rbp)
movq 0x18(%rax), %rcx
movq 0x40(%rcx), %rcx
movq %rcx, -0x28(%rbp)
movq 0x40(%rax), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x30(%rbp)
movq 0x40(%rax), %rcx
movq 0x20(%rcx), %rcx
movq %rcx, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq 0xb0(%rax), %rdi
movl 0x2c(%rax), %esi
callq 0x77d0
movq %rax, -0x58(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x30(%rbp), %rcx
movslq -0xc(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xed16
movq -0x80(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rdx
movslq -0xc(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x10(%rbp), %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0xed09
movl -0x10(%rbp), %edx
movq -0x58(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xed0b
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xecbb
cmpl $0x0, -0x4c(%rbp)
jne 0xedbd
movq -0x80(%rbp), %rdx
movq 0x20(%rdx), %rax
movq 0x8(%rax), %rax
movq 0x20(%rdx), %rcx
movq 0x18(%rcx), %rcx
movslq -0xc(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl (%rax,%rcx,4), %eax
sarl %eax
movl %eax, -0x3c(%rbp)
movq 0x20(%rdx), %rax
movq 0x20(%rax), %rax
movq 0x20(%rdx), %rcx
movq 0x8(%rcx), %rcx
movq 0x20(%rdx), %rdx
movq 0x18(%rdx), %rdx
movslq -0xc(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
sarl %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0xedb8
movq -0x80(%rbp), %rax
movq 0x60(%rax), %rdi
movslq -0xc(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdi
movq 0x48(%rax), %rax
movq (%rax), %rsi
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x10d30
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xed76
jmp 0xf222
movq -0x80(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rsi
movslq -0xc(%rbp), %rdi
movl (%rsi,%rdi,4), %esi
movq -0x58(%rbp), %rdi
addl (%rdi), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
subl 0x2c(%rax), %ecx
movl %ecx, -0x14(%rbp)
movq 0x48(%rax), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movslq -0xc(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq -0x58(%rbp), %rdx
addl (%rdx), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x4c(%rbp)
jne 0xeebc
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rcx
movq 0x38(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x48(%rbp)
movq 0x48(%rax), %rcx
movq 0x8(%rcx), %rcx
movq -0x28(%rbp), %rdx
movslq -0x14(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x18(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0xeeb7
movq -0x80(%rbp), %rcx
movq 0x60(%rcx), %rdi
movslq -0xc(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x48(%rbp), %rax
movslq -0x10(%rbp), %rdx
movl (%rax,%rdx,4), %eax
addl 0x2c(%rcx), %eax
movl %eax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rsi
callq 0x10dc0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xee72
jmp 0xf220
movq -0x80(%rbp), %rax
cmpl $0x77359400, 0xc8(%rax) # imm = 0x77359400
jle 0xeef4
movq -0x80(%rbp), %rax
movq 0xb8(%rax), %rdi
movslq 0x34(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3110
movq -0x80(%rbp), %rax
movl $0x0, 0xc8(%rax)
movq -0x80(%rbp), %rax
movl 0xc8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc8(%rax)
movq 0x18(%rax), %rcx
movq 0x38(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x70(%rbp)
movq 0x48(%rax), %rcx
movq 0x8(%rcx), %rcx
movq -0x28(%rbp), %rdx
movslq -0x14(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x18(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0xef97
movq -0x80(%rbp), %rax
movl 0xc8(%rax), %edx
movq 0xb8(%rax), %rax
movq -0x70(%rbp), %rcx
movslq -0x10(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xef5f
movq -0x80(%rbp), %rax
movl 0xc8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc8(%rax)
movl $0x1, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xf0f4
movq -0x80(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rsi
movslq -0xc(%rbp), %rdi
movl (%rsi,%rdi,4), %esi
movq -0x58(%rbp), %rdi
movslq -0x60(%rbp), %r8
addl (%rdi,%r8,4), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
subl 0x2c(%rax), %ecx
movl %ecx, -0x14(%rbp)
movq 0x18(%rax), %rcx
movq 0x38(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x70(%rbp)
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rcx
movq -0x20(%rbp), %rdx
movslq -0xc(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
movq -0x58(%rbp), %rsi
movslq -0x60(%rbp), %rdi
addl (%rsi,%rdi,4), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x18(%rbp)
movq 0x48(%rax), %rcx
movq 0x8(%rcx), %rcx
movq -0x28(%rbp), %rdx
movslq -0x14(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x18(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0xf0d3
movq -0x80(%rbp), %rcx
movq -0x70(%rbp), %rax
movslq -0x10(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movl %eax, -0x64(%rbp)
movq 0xb8(%rcx), %rax
movslq -0x64(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movl 0xc8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf0c6
movq -0x80(%rbp), %rax
movq 0xb8(%rax), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0xf0c8
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xf074
movq -0x80(%rbp), %rax
movl 0xc8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc8(%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xefb1
movq -0x80(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rsi
movslq -0xc(%rbp), %rdi
movl (%rsi,%rdi,4), %esi
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %r8d
subl $0x1, %r8d
movslq %r8d, %r8
addl (%rdi,%r8,4), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
subl 0x2c(%rax), %ecx
movl %ecx, -0x14(%rbp)
movq 0x18(%rax), %rcx
movq 0x38(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x70(%rbp)
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rcx
movq -0x20(%rbp), %rdx
movslq -0xc(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
movq -0x58(%rbp), %rsi
movl -0x4c(%rbp), %edi
subl $0x1, %edi
movslq %edi, %rdi
addl (%rsi,%rdi,4), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x18(%rbp)
movq 0x48(%rax), %rcx
movq 0x8(%rcx), %rcx
movq -0x28(%rbp), %rdx
movslq -0x14(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x18(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jge 0xf21e
movq -0x80(%rbp), %rcx
movq -0x70(%rbp), %rax
movslq -0x10(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movl %eax, -0x64(%rbp)
movq 0xb8(%rcx), %rax
movslq -0x64(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movl 0xc8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf211
movq -0x80(%rbp), %rcx
movq 0x60(%rcx), %rdi
movslq -0xc(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl -0x64(%rbp), %eax
addl 0x2c(%rcx), %eax
movl %eax, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0x10dc0
jmp 0xf213
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xf1b2
jmp 0xf220
jmp 0xf222
movq -0x80(%rbp), %rax
movq 0xb0(%rax), %rdi
movq -0x58(%rbp), %rsi
movl 0x2c(%rax), %edx
callq 0x7a30
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)