// File: /workspace/github_c_makefile_star2_O1/pwelke[P]GraphMiningTools/hp_cactus.c
// Function: isWeaklyTraceableUnsafe
char isWeaklyTraceableUnsafe(struct Graph* g, struct ShallowGraphPool* sgp) {
	struct ShallowGraph* biconnectedComponents = listBiconnectedComponents(g, sgp);
	int* criticality = computeCriticality(biconnectedComponents, g->n);
	int v; 
	struct ShallowGraph* c;

	// test if every vertex has criticality at most 2
	for (v=0; v<g->n; ++v) {
		if (criticality[v] > 2) {
			free(criticality);
			dumpShallowGraphCycle(sgp, biconnectedComponents);
			return 0;
		}
	}

	// test if every biconnected component contains at most two critical vertices.
	for (c=biconnectedComponents; c!=NULL; c=c->next) {
		struct VertexList* e;
		int criticalVertexCount = 0;

		// TODO measure if the alg is faster with or without this line
		if (c->m == 1) continue;

		// init ->visited = 0
		for (e=c->edges; e!=NULL; e=e->next) {
			e->startPoint->visited = 0;
			e->endPoint->visited = 0;
		}
		// count critical vertices
		for (e=c->edges; e!=NULL; e=e->next) {
			criticalVertexCount += visit(e->startPoint, criticality);
			criticalVertexCount += visit(e->endPoint, criticality);
		}
		if (criticalVertexCount > 2) {
			free(criticality);
			dumpShallowGraphCycle(sgp, biconnectedComponents);
			return 0;
		 } else {
			/* this is where misclassification might occur.
			we would need to check, if there is a Hamiltonian path in the biconnected
			component starting at one critical vertex and stopping at the other, if 
			there is a Hamiltonian path starting at the single critical vertex, or if there 
			is no critical vertex, if the biconnected block is traceable in any way. */
		}
	}

	// otherwise, there might exist a Hamiltonian path
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r12
callq 0xb2bf
movq %rax, %r14
movl (%r12), %esi
movq %rax, %rdi
callq 0xb0ec
movq %rax, %r15
movslq (%r12), %rax
testq %rax, %rax
jle 0x94d1
xorl %ecx, %ecx
cmpl $0x3, (%r15,%rcx,4)
jge 0x95a9
incq %rcx
cmpq %rcx, %rax
jne 0x94be
movb $0x1, %bpl
testq %r14, %r14
je 0x95be
xorl %r12d, %r12d
movq %r14, %r13
movl $0x7, %eax
cmpl $0x1, 0x10(%r13)
je 0x9591
movq (%r13), %rax
testq %rax, %rax
je 0x9512
movq 0x10(%rax), %rcx
movl %r12d, 0x1c(%rcx)
movq 0x18(%rax), %rcx
movl %r12d, 0x1c(%rcx)
movq 0x8(%rax), %rax
jmp 0x94f7
movq (%r13), %rax
testq %rax, %rax
je 0x958f
xorl %ecx, %ecx
movq 0x10(%rax), %rdx
cmpl $0x0, 0x1c(%rdx)
jne 0x953e
movl $0x1, 0x1c(%rdx)
movslq 0x18(%rdx), %rsi
movl $0x1, %edx
cmpl $0x1, (%r15,%rsi,4)
jg 0x9540
xorl %edx, %edx
movq 0x18(%rax), %rsi
cmpl $0x0, 0x1c(%rsi)
jne 0x9561
movl $0x1, 0x1c(%rsi)
movslq 0x18(%rsi), %rdi
movl $0x1, %esi
cmpl $0x1, (%r15,%rdi,4)
jg 0x9563
xorl %esi, %esi
addl %edx, %ecx
addl %esi, %ecx
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x951d
cmpl $0x3, %ecx
jl 0x958f
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14b75
movl $0x1, %eax
jmp 0x9591
xorl %eax, %eax
cmpl $0x7, %eax
je 0x959a
testl %eax, %eax
jne 0x95bc
movq 0x18(%r13), %r13
testq %r13, %r13
jne 0x94e3
jmp 0x95be
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14b75
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq