// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/localEasiness.c
// Function: computeLocalEasinessExactly
long int* computeLocalEasinessExactly(struct ShallowGraph* biconnectedComponents, int n, long int maxBound, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	/* store for each vertex if the current bic.comp was already counted */
	int* occurrences = malloc(n * sizeof(int));
	/* store the cycle degrees of each vertex in g */
	long int* easiness = malloc(n * sizeof(long int));

	for (int v=0; v<n; ++v) {
		occurrences[v] = -1;
		easiness[v] = 1;
	}

	int compNumber = 0;
	for (struct ShallowGraph* comp = biconnectedComponents; comp!=NULL; comp=comp->next) {
		// if component is a bridge or singleton (I guess the latter cannot happen), then we do not need to process
		// spanning trees, as there is only one. This would not change the easiness of the contained vertices.
		if (comp->m <= 1) {
			continue;
		}

		// count spanning trees in component. This breaks and returns -1 if there are more than maxBound
		struct Graph* component = shallowGraphToGraph(comp, gp);
		long int nSpanningTrees = countSpanningTrees(component, maxBound, sgp, gp);
		dumpGraph(gp, component);

		for (struct VertexList* e=comp->edges; e!=NULL; e=e->next) {
			if (occurrences[e->startPoint->number] < compNumber) {
				occurrences[e->startPoint->number] = compNumber;
				if (nSpanningTrees != -1) {
					easiness[e->startPoint->number] *= nSpanningTrees;
				} else {
					easiness[e->startPoint->number] = 0;
				}
			}
			if (occurrences[e->endPoint->number] < compNumber) {
				occurrences[e->endPoint->number] = compNumber;
				if (nSpanningTrees != -1) {
					easiness[e->endPoint->number] *= nSpanningTrees;
				} else {
					easiness[e->endPoint->number] = 0;
				}
			}
		}
		++compNumber;
	}

	free(occurrences);
	return easiness;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, %r15
movslq %esi, %rbx
leaq (,%rbx,4), %rdi
callq 0x1180
movq %rax, %r13
leaq (,%rbx,8), %rdi
callq 0x1180
movq %rax, %rbp
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0xbc87
orl $-0x1, (%r13,%rax,4)
movq $0x1, (%rbp,%rax,8)
incq %rax
jmp 0xbc6e
xorl %r14d, %r14d
movq 0x10(%rsp), %r12
testq %r15, %r15
je 0xbd53
cmpl $0x2, 0x10(%r15)
jl 0xbd4a
movq %r15, %rdi
movq %r12, %rsi
callq 0x5fe8
movq %r15, 0x20(%rsp)
movq %rax, %r15
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rcx
callq 0xa69e
movq %rax, %rbx
movq %r12, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %r15
callq 0x1166e
movq %r15, %rax
movq (%rax), %rax
testq %rax, %rax
je 0xbd47
movq 0x10(%rax), %rcx
movslq 0x18(%rcx), %rcx
cmpl %r14d, (%r13,%rcx,4)
jge 0xbd15
movl %r14d, (%r13,%rcx,4)
cmpq $-0x1, %rbx
je 0xbd0e
movq (%rbp,%rcx,8), %rdx
imulq %rbx, %rdx
jmp 0xbd10
xorl %edx, %edx
movq %rdx, (%rbp,%rcx,8)
movq 0x18(%rax), %rcx
movslq 0x18(%rcx), %rcx
cmpl %r14d, (%r13,%rcx,4)
jge 0xbd41
movl %r14d, (%r13,%rcx,4)
cmpq $-0x1, %rbx
je 0xbd3a
movq (%rbp,%rcx,8), %rdx
imulq %rbx, %rdx
jmp 0xbd3c
xorl %edx, %edx
movq %rdx, (%rbp,%rcx,8)
addq $0x8, %rax
jmp 0xbce1
incl %r14d
movq 0x18(%r15), %r15
jmp 0xbc8f
movq %r13, %rdi
callq 0x1030
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq