// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/poset_pathCover.c
// Function: getPathCoverOfPoset
int** getPathCoverOfPoset(struct Graph* g, size_t* nPaths, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	struct Graph* flowInstance = createVertexCoverFlowInstanceOfPoset(g, gp);
	pushRelabelMaxFlow(flowInstance, flowInstance->vertices[0], flowInstance->vertices[1], sgp);

	// add one flow value to those edges that correspond to vertices
	for (int v=2; v<flowInstance->n; v+=2) {
		for (struct VertexList* e=flowInstance->vertices[v]->neighborhood; e!=NULL; e=e->next) {
			if (e->endPoint->number == v+1) {
				e->flag += 1;
				break; // iterating over the neighbors
			}
		}
	}

	// remove all edges that have 0 flow, all residual edges (assumed to go from larger vertex id to smaller),
	// and all edges containing s and t
	// init ->visited of vertices
	dumpVertexList(gp->listPool, flowInstance->vertices[0]->neighborhood);
	dumpVertexList(gp->listPool, flowInstance->vertices[1]->neighborhood);
	flowInstance->vertices[0]->neighborhood = NULL;
	flowInstance->vertices[1]->neighborhood = NULL;

	for (int vi=2; vi<flowInstance->n; ++vi) {
		struct Vertex* v = flowInstance->vertices[vi];
		struct VertexList* keep = NULL;
		v->visited = 0;
		v->d = 0;
		for (struct VertexList* e=v->neighborhood; e!=NULL; e=v->neighborhood) {
			v->neighborhood = e->next;
			if ((e->flag != 0) && (e->startPoint->number < e->endPoint->number)) {
				e->next = keep;
				keep = e;
			} else {
				dumpVertexList(gp->listPool, e);
			}
		}
		v->neighborhood = keep;
	}

	// store outflow - inflow in v->visited
	for (int v=2; v<flowInstance->n; ++v) {
		for (struct VertexList* e=flowInstance->vertices[v]->neighborhood; e!=NULL; e=e->next) {
			e->startPoint->visited += e->flag;
			e->endPoint->visited -= e->flag;
		}
	}

	// get minimum number of paths that cover all vertices
	countPossiblePaths(flowInstance, nPaths);

	// find paths from sources to sinks and store them in output
	int** paths = malloc(*nPaths * sizeof(int*));
	int i = 0;
	for (int v=2; v<flowInstance->n; v += 2) {
		struct Vertex* vertex = flowInstance->vertices[v];
		while (vertex->visited > 0) {
			paths[i] = getLongestPathInFlowInstance(vertex, flowInstance, sgp);
			++i;
		}
	}

	dumpGraph(gp, flowInstance);
	return paths;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, (%rsp)
movq %rdx, %rsi
callq 0x152da
movq %rax, %r15
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1476
movslq (%r15), %rax
pushq $0x2
popq %rcx
cmpq %rax, %rcx
jge 0x155be
movq 0x10(%r15), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rcx, %rsi
orq $0x1, %rsi
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x155b8
movq 0x18(%rdx), %rdi
movl 0x18(%rdi), %edi
cmpq %rdi, %rsi
jne 0x155a0
incl 0x24(%rdx)
addq $0x2, %rcx
jmp 0x1558c
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x11364
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x11364
movq 0x10(%r15), %rax
movq (%rax), %rcx
andq $0x0, 0x8(%rcx)
movq 0x8(%rax), %rax
andq $0x0, 0x8(%rax)
pushq $0x2
popq %r13
movslq (%r15), %rax
cmpq %rax, %r13
jge 0x1565f
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rbp
andl $0x0, 0x1c(%rbp)
andl $0x0, 0x28(%rbp)
xorl %r12d, %r12d
movq 0x8(%rbp), %rsi
testq %rsi, %rsi
je 0x15656
movq 0x8(%rsi), %rax
movq %rax, 0x8(%rbp)
cmpl $0x0, 0x24(%rsi)
je 0x15642
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
movl 0x18(%rax), %eax
cmpl 0x18(%rcx), %eax
jl 0x1564d
movq 0x18(%rbx), %rdi
callq 0x11364
jmp 0x1561b
movq %r12, 0x8(%rsi)
movq %rsi, %r12
jmp 0x1561b
movq %r12, 0x8(%rbp)
incq %r13
jmp 0x15600
pushq $0x2
popq %rcx
cmpq %rax, %rcx
jge 0x15690
movq 0x10(%r15), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x1568b
movl 0x24(%rdx), %esi
movq 0x10(%rdx), %rdi
addl %esi, 0x1c(%rdi)
movq 0x18(%rdx), %rdi
subl %esi, 0x1c(%rdi)
jmp 0x1566f
incq %rcx
jmp 0x15662
movq %r15, %rdi
movq (%rsp), %r12
movq %r12, %rsi
callq 0x153d6
movq (%r12), %rdi
shlq $0x3, %rdi
callq 0x1180
movq %rax, %r12
pushq $0x2
popq %rcx
xorl %ebp, %ebp
movslq (%r15), %rax
cmpq %rax, %rcx
jge 0x156f3
movq 0x10(%r15), %rax
movq %rcx, (%rsp)
movq (%rax,%rcx,8), %r13
movslq %ebp, %rbp
cmpl $0x0, 0x1c(%r13)
jle 0x156e9
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x15404
movq %rax, (%r12,%rbp,8)
incq %rbp
jmp 0x156cb
movq (%rsp), %rcx
addq $0x2, %rcx
jmp 0x156b4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1166e
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq