// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
movq 0x40(%rdi), %rax
movq 0x18(%rax), %r14
movq 0x20(%rax), %r12
movq 0xb0(%rdi), %rdi
movl 0x2c(%rbx), %esi
callq 0x4aba
movq %rax, %r11
movslq %ebp, %rbp
movl (%r14,%rbp,4), %edx
testl %edx, %edx
jle 0x787b
movq 0x50(%rbx), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
movslq (%r13,%rbp,4), %rsi
addq %rcx, %rsi
movslq (%r12,%rsi,4), %rsi
cmpl $-0x1, (%rax,%rsi,4)
je 0x782a
movslq %r15d, %r15
movl %ecx, (%r11,%r15,4)
incl %r15d
movl (%r14,%rbp,4), %edx
incq %rcx
cmpl %edx, %ecx
jl 0x780a
testl %r15d, %r15d
je 0x787b
movq 0x48(%rbx), %r8
movq 0x50(%rbx), %rax
movslq (%r13,%rbp,4), %rcx
movslq (%r11), %rsi
addq %rcx, %rsi
movslq (%r12,%rsi,4), %rcx
movslq (%rax,%rcx,4), %r9
movslq 0x2c(%rbx), %rdx
subq %rdx, %r9
movq 0x18(%r8), %rax
movslq (%rax,%rsi,4), %rsi
cmpl $0x1, %r15d
jne 0x78bb
movq 0x10(%r8), %rax
movq 0x18(%rsp), %rcx
movslq (%rcx,%r9,4), %rcx
addq %rsi, %rcx
movl (%rax,%rcx,4), %ebp
jmp 0x789b
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 0x4c64
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), %r14d
cmpl $0x77359401, %r14d      # imm = 0x77359401
jl 0x7901
movq 0xb8(%rbx), %rdi
movslq 0x34(%rbx), %rdx
shlq $0x2, %rdx
xorl %r14d, %r14d
movq %rsi, 0x10(%rsp)
xorl %esi, %esi
movq %r9, 0x8(%rsp)
callq 0x20e0
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rsi
movq 0x48(%rbx), %r8
leal 0x1(%r14), %edi
movl %edi, 0xc8(%rbx)
movq 0x18(%rbx), %rax
movq 0x38(%rax), %rax
movq %rax, 0x8(%rsp)
movslq %r9d, %rax
movq 0x8(%r8), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%r8), %rdx
movq 0x18(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
addq %rsi, %rcx
movq %rdx, 0x10(%rsp)
movslq (%rdx,%rcx,4), %rdx
testq %rdx, %rdx
jle 0x796e
movq 0x8(%rsp), %rsi
movq (%rsi,%rax,8), %r9
movq 0x20(%rsp), %rax
movslq (%rax,%rcx,4), %r10
addq %r10, %rdx
movq 0xb8(%rbx), %r11
movslq (%r9,%r10,4), %rax
movl %edi, (%r11,%rax,4)
incq %r10
cmpq %rdx, %r10
jl 0x795e
addl $0x2, %r14d
movl %r14d, 0xc8(%rbx)
leal -0x1(%r15), %eax
movq 0x50(%rbx), %rdx
movq 0x18(%r8), %r8
cmpl $0x2, %r15d
movl %eax, 0x2c(%rsp)
jle 0x7a39
movq 0xb8(%rbx), %r10
movl %eax, %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 (%rdx,%rax,4), %r9
movslq 0x2c(%rbx), %rax
subq %rax, %r9
movslq (%r8,%rcx,4), %rcx
movq 0x18(%rsp), %rax
movslq (%rax,%r9,4), %rax
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %rdi
testq %rdi, %rdi
jle 0x7a1f
movq 0x8(%rsp), %rcx
movq (%rcx,%r9,8), %r14
movq 0x20(%rsp), %rcx
movslq (%rcx,%rax,4), %r9
addq %r9, %rdi
movslq (%r14,%r9,4), %rax
movl (%r10,%rax,4), %ecx
movl 0xc8(%rbx), %esi
decl %esi
cmpl %esi, %ecx
jne 0x7a10
incl %ecx
movl %ecx, (%r10,%rax,4)
incq %r9
cmpq %rdi, %r9
jl 0x79f6
movl 0xc8(%rbx), %r14d
movl %r14d, %edi
leal 0x1(%rdi), %r14d
movl %r14d, 0xc8(%rbx)
incq %r15
cmpq %r11, %r15
jne 0x79a3
movslq (%r13,%rbp,4), %rax
movslq 0x2c(%rsp), %rcx
movq 0x30(%rsp), %r11
movslq (%r11,%rcx,4), %rcx
addq %rax, %rcx
movslq (%r12,%rcx,4), %rax
movslq (%rdx,%rax,4), %r9
movslq 0x2c(%rbx), %rdx
subq %rdx, %r9
movslq (%r8,%rcx,4), %rax
movq 0x18(%rsp), %rcx
movslq (%rcx,%r9,4), %rcx
addq %rax, %rcx
movq 0x10(%rsp), %rax
movslq (%rax,%rcx,4), %rsi
testq %rsi, %rsi
jle 0x7ab9
movq 0x8(%rsp), %rax
movq (%rax,%r9,8), %rax
movq 0x20(%rsp), %r8
movslq (%r8,%rcx,4), %rcx
addq %rcx, %rsi
movq 0xb8(%rbx), %r8
xorl %ebp, %ebp
movslq (%rax,%rcx,4), %r9
xorl %r10d, %r10d
cmpl %edi, (%r8,%r9,4)
sete %r10b
addl %r10d, %ebp
incq %rcx
cmpq %rsi, %rcx
jl 0x7a9a
jmp 0x789b
xorl %ebp, %ebp
jmp 0x789b