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

	int32_t w = 0;
	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;
	
	//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
	if( numMapped == 0 ) {
		w = (coloring->cellSize[ coloring->color[ coloring->inv[aVertex] ] ] >> 1);
	}
	else {
		adjCand = mapping[ dagArr[ adjPos1[aVertex] + mappedParent[0] ] ] - n;
		ci = cs->dagColorIndex[ adjPos1[aVertex] + mappedParent[0] ];

		if( numMapped == 1 ) {
			w = cs->S[ adjPos2[adjCand] + ci ];
		}
		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];
			int32_t p = cs->P[ adjPos2[adjCand] + ci ];
			int32_t 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
			w = 0;
			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 )
					++w;
			}
		} //else of (if numMapped == 1)
	} //else of (if numMapped == 0)

	global_memory->returnLLArray(mappedParent, n);

	return w;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rcx
movq 0x40(%rax), %r12
movq 0x40(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rdi), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r13
movq 0xb0(%rdi), %rdi
movl 0x2c(%rbx), %esi
callq 0x3f1a
movq %rax, %r11
movslq %ebp, %rbp
movq 0x50(%rbx), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpl (%r14,%rbp,4), %ecx
jge 0x67cd
movslq (%r12,%rbp,4), %rdx
addq %rcx, %rdx
movslq (%r13,%rdx,4), %rdx
cmpl $-0x1, (%rax,%rdx,4)
je 0x67c8
movslq %r15d, %rdx
movl %ecx, (%r11,%rdx,4)
incl %r15d
incq %rcx
jmp 0x67a6
testl %r15d, %r15d
je 0x6813
movslq (%r12,%rbp,4), %rcx
movslq (%r11), %rsi
addq %rcx, %rsi
movslq (%r13,%rsi,4), %rcx
movslq (%rax,%rcx,4), %r14
movslq 0x2c(%rbx), %rdx
subq %rdx, %r14
movq 0x48(%rbx), %rcx
movq 0x18(%rcx), %rax
movslq (%rax,%rsi,4), %r10
cmpl $0x1, %r15d
jne 0x6853
movq 0x10(%rcx), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
addq %r10, %rcx
movl (%rax,%rcx,4), %ebp
jmp 0x6833
movq 0x20(%rbx), %rax
movq 0x20(%rax), %rcx
movq 0x8(%rax), %rdx
movq 0x18(%rax), %rax
movslq (%rax,%rbp,4), %rax
movslq (%rdx,%rax,4), %rax
movl (%rcx,%rax,4), %ebp
sarl %ebp
movl 0x2c(%rbx), %edx
movq 0xb0(%rbx), %rdi
movq %r11, %rsi
callq 0x3fee
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r11, 0x30(%rsp)
movl 0xc8(%rbx), %eax
cmpl $0x77359401, %eax       # imm = 0x77359401
jl 0x688b
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
movq %r10, 0x8(%rsp)
callq 0x2100
movq 0x8(%rsp), %r10
xorl %eax, %eax
movq 0x48(%rbx), %rcx
movq %rax, 0x28(%rsp)
leal 0x1(%rax), %r8d
movl %r8d, 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0xb8(%rbx), %rdx
movq 0x38(%rax), %rdi
movslq %r14d, %rax
movq (%rdi,%rax,8), %r9
movq 0x8(%rcx), %rsi
movq %rcx, 0x8(%rsp)
movq 0x10(%rcx), %r11
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
addq %r10, %rax
movq %rsi, 0x20(%rsp)
movslq (%rsi,%rax,4), %r10
movq %r11, 0x18(%rsp)
movslq (%r11,%rax,4), %r11
addq %r10, %r11
cmpq %r11, %r10
jge 0x68f1
movslq (%r9,%r10,4), %rax
movl %r8d, (%rdx,%rax,4)
incq %r10
jmp 0x68df
movq 0x28(%rsp), %rax
addl $0x2, %eax
movl %eax, 0xc8(%rbx)
decl %r15d
movq 0x50(%rbx), %r9
movslq %r15d, %rdx
pushq $0x1
popq %r10
cmpq %rdx, %r10
movq 0x30(%rsp), %r11
jge 0x69ac
movslq (%r12,%rbp,4), %rax
movslq (%r11,%r10,4), %rcx
addq %rax, %rcx
movslq (%r13,%rcx,4), %rax
movslq (%r9,%rax,4), %rax
movslq 0x2c(%rbx), %r8
subq %r8, %rax
movq (%rdi,%rax,8), %r8
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %r11
movslq (%r11,%rcx,4), %rcx
movq 0x10(%rsp), %rsi
movslq (%rsi,%rax,4), %rax
addq %rcx, %rax
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %r11
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %r14
addq %r11, %r14
movq 0xb8(%rbx), %r15
cmpq %r14, %r11
jge 0x6993
movslq (%r8,%r11,4), %rax
movl (%r15,%rax,4), %ecx
movl 0xc8(%rbx), %esi
decl %esi
cmpl %esi, %ecx
jne 0x698e
incl %ecx
movl %ecx, (%r15,%rax,4)
incq %r11
jmp 0x696f
movl 0xc8(%rbx), %r8d
leal 0x1(%r8), %eax
movl %eax, 0xc8(%rbx)
incq %r10
jmp 0x690d
movslq (%r12,%rbp,4), %rax
movslq (%r11,%rdx,4), %rcx
addq %rax, %rcx
movslq (%r13,%rcx,4), %rax
movq 0x50(%rbx), %rdx
movq 0xb8(%rbx), %r9
movslq (%rdx,%rax,4), %rax
movslq 0x2c(%rbx), %rdx
subq %rdx, %rax
movq (%rdi,%rax,8), %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %rsi
movslq (%rsi,%rcx,4), %rcx
movq 0x10(%rsp), %rsi
movslq (%rsi,%rax,4), %rsi
addq %rcx, %rsi
movq 0x20(%rsp), %rax
movslq (%rax,%rsi,4), %rax
movq 0x18(%rsp), %rcx
movslq (%rcx,%rsi,4), %rcx
addq %rax, %rcx
xorl %ebp, %ebp
cmpq %rcx, %rax
jge 0x6833
movslq (%rdi,%rax,4), %rsi
xorl %r10d, %r10d
cmpl %r8d, (%r9,%rsi,4)
sete %r10b
addl %r10d, %ebp
incq %rax
jmp 0x6a06