// File: /workspace/github_cpp_makefile_star2_O1/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), %r13
movq 0x40(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rdi), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r12
movq 0xb0(%rdi), %rdi
movl 0x2c(%rbx), %esi
callq 0x4b34
movq %rax, %r10
movslq %ebp, %rbp
cmpl $0x0, (%r14,%rbp,4)
jle 0x7938
movq 0x50(%rbx), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
movslq (%r13,%rbp,4), %rdx
addq %rcx, %rdx
movslq (%r12,%rdx,4), %rdx
cmpl $-0x1, (%rax,%rdx,4)
je 0x792d
movslq %r15d, %r15
movl %ecx, (%r10,%r15,4)
incl %r15d
incq %rcx
cmpl (%r14,%rbp,4), %ecx
jl 0x7911
jmp 0x793b
xorl %r15d, %r15d
testl %r15d, %r15d
je 0x7988
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rcx
movslq (%r13,%rbp,4), %rdx
movslq (%r10), %rsi
addq %rdx, %rsi
movslq (%r12,%rsi,4), %rdx
movslq (%rcx,%rdx,4), %r14
movslq 0x2c(%rbx), %rcx
subq %rcx, %r14
movq 0x18(%rax), %rcx
movslq (%rcx,%rsi,4), %rsi
cmpl $0x1, %r15d
jne 0x79aa
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
addq %rsi, %rcx
movl (%rax,%rcx,4), %ebp
jmp 0x7baf
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
jmp 0x7baf
movq %r10, 0x30(%rsp)
cmpl $0x77359401, 0xc8(%rbx) # imm = 0x77359401
jl 0x79e5
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
movq %rsi, 0x8(%rsp)
xorl %esi, %esi
callq 0x20e0
movq 0x8(%rsp), %rsi
movl $0x0, 0xc8(%rbx)
incl 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0x48(%rbx), %rdx
movq 0x38(%rax), %rax
movq %rax, 0x20(%rsp)
movslq %r14d, %rax
movq 0x8(%rdx), %rcx
movq %rcx, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x10(%rdx), %rdx
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
addq %rsi, %rcx
movq %rdx, 0x8(%rsp)
movslq (%rdx,%rcx,4), %rsi
testq %rsi, %rsi
jle 0x7a5d
movq 0x20(%rsp), %rdx
movq (%rdx,%rax,8), %rdi
movq 0x18(%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 0x7a47
incl 0xc8(%rbx)
leal -0x1(%r15), %eax
movl %eax, 0x4(%rsp)
cmpl $0x3, %r15d
jl 0x7b1b
movq 0x50(%rbx), %r8
movq 0xb8(%rbx), %r9
movq 0x28(%rsp), %rax
movq 0x18(%rax), %r10
movl 0x4(%rsp), %r11d
movl $0x1, %r15d
movslq (%r13,%rbp,4), %rax
movq 0x30(%rsp), %rcx
movslq (%rcx,%r15,4), %rcx
addq %rax, %rcx
movslq (%r12,%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 0x7b09
movq 0x20(%rsp), %rcx
movq (%rcx,%rsi,8), %rdi
movq 0x18(%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 0x7b01
incl %ecx
movl %ecx, (%r9,%rax,4)
incq %rsi
cmpq %r14, %rsi
jl 0x7ae7
incl 0xc8(%rbx)
incq %r15
cmpq %r11, %r15
jne 0x7a94
movq 0x50(%rbx), %rax
movslq (%r13,%rbp,4), %rcx
movslq 0x4(%rsp), %rdx
movq 0x30(%rsp), %r10
movslq (%r10,%rdx,4), %rdx
addq %rcx, %rdx
movslq (%r12,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rsi
movslq 0x2c(%rbx), %rax
subq %rax, %rsi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movslq (%rax,%rdx,4), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rsi,4), %rcx
addq %rax, %rcx
movq 0x8(%rsp), %rax
movslq (%rax,%rcx,4), %rdx
testq %rdx, %rdx
jle 0x7bad
movq 0x20(%rsp), %rax
movq (%rax,%rsi,8), %rax
movq 0x18(%rsp), %rsi
movslq (%rsi,%rcx,4), %rcx
addq %rcx, %rdx
movq 0xb8(%rbx), %rsi
movl 0xc8(%rbx), %edi
decl %edi
xorl %ebp, %ebp
movslq (%rax,%rcx,4), %r8
xorl %r9d, %r9d
cmpl %edi, (%rsi,%r8,4)
sete %r9b
addl %r9d, %ebp
incq %rcx
cmpq %rdx, %rcx
jl 0x7b91
jmp 0x7baf
xorl %ebp, %ebp
movq 0xb0(%rbx), %rdi
movl 0x2c(%rbx), %edx
movq %r10, %rsi
callq 0x4cf0
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq