// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdx, %rsi
callq 0x18413
movq %rax, %r15
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0x30e9
movslq (%r15), %rax
cmpq $0x3, %rax
jl 0x186fc
movq 0x10(%r15), %rcx
movl $0x2, %edx
movq (%rcx,%rdx,8), %rsi
movq %rdx, %rdi
orq $0x1, %rdi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x186f3
movq 0x18(%rsi), %r8
movl 0x18(%r8), %r8d
cmpq %r8, %rdi
jne 0x186da
incl 0x24(%rsi)
addq $0x2, %rdx
cmpq %rax, %rdx
jb 0x186cf
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1438e
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1438e
movq 0x10(%r15), %rax
movq (%rax), %rcx
xorl %edx, %edx
movq %rdx, 0x8(%rcx)
movq 0x8(%rax), %rax
movq %rdx, 0x8(%rax)
movl (%r15), %eax
cmpl $0x3, %eax
jl 0x187ba
movq %r12, 0x8(%rsp)
movl $0x2, %ebp
movq 0x10(%r15), %rax
movq (%rax,%rbp,8), %r12
xorl %eax, %eax
movl %eax, 0x1c(%r12)
movl %eax, 0x28(%r12)
movq 0x8(%r12), %rsi
xorl %r13d, %r13d
testq %rsi, %rsi
je 0x187a5
movq 0x8(%rsi), %rax
movq %rax, 0x8(%r12)
cmpl $0x0, 0x24(%rsi)
je 0x18795
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
movl 0x18(%rax), %eax
cmpl 0x18(%rcx), %eax
jge 0x18795
movq %r13, 0x8(%rsi)
movq %rsi, %r13
jmp 0x1879e
movq 0x18(%rbx), %rdi
callq 0x1438e
movq 0x8(%r12), %rsi
jmp 0x18768
movq %r13, 0x8(%r12)
incq %rbp
movslq (%r15), %rax
cmpq %rax, %rbp
jl 0x1874c
movq 0x8(%rsp), %r12
cmpl $0x3, %eax
jl 0x187f5
movq 0x10(%r15), %rcx
movl %eax, %edx
movl $0x2, %esi
movq (%rcx,%rsi,8), %rdi
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x187ed
movl 0x24(%rdi), %r8d
movq 0x10(%rdi), %r9
addl %r8d, 0x1c(%r9)
movq 0x18(%rdi), %r9
subl %r8d, 0x1c(%r9)
jmp 0x187ce
incq %rsi
cmpq %rdx, %rsi
jne 0x187ca
movq $0x0, (%r12)
cmpl $0x3, %eax
jl 0x18826
movq 0x10(%r15), %rcx
movl %eax, %eax
movl $0x2, %edx
movq (%rcx,%rdx,8), %rsi
movslq 0x1c(%rsi), %rsi
testq %rsi, %rsi
jle 0x1881e
addq %rsi, (%r12)
incq %rdx
cmpq %rdx, %rax
jne 0x1880d
movq %rbx, 0x10(%rsp)
movq (%r12), %rdi
shlq $0x3, %rdi
callq 0x1190
movq %rax, 0x8(%rsp)
cmpl $0x3, (%r15)
jl 0x1888d
xorl %ebp, %ebp
movl $0x2, %r12d
movq 0x10(%r15), %rax
movq (%rax,%r12,8), %r13
cmpl $0x0, 0x1c(%r13)
jle 0x18884
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x18518
movq %rax, (%rbx)
addq $0x8, %rbx
incl %ebp
cmpl $0x0, 0x1c(%r13)
jg 0x18866
addq $0x2, %r12
cmpl %r12d, (%r15)
jg 0x1884b
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x14832
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq