// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdx, %rsi
callq 0x1830f
movq %rax, %r14
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r14, %rdi
movq %r15, %rcx
callq 0x3099
movslq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq $0x3, %rcx
jl 0x185fe
movl $0x2, %edx
movq (%rax,%rdx,8), %rsi
movq %rdx, %rdi
orq $0x1, %rdi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x185f5
movq 0x18(%rsi), %r8
movl 0x18(%r8), %r8d
cmpq %r8, %rdi
jne 0x185dc
incl 0x24(%rsi)
addq $0x2, %rdx
cmpq %rcx, %rdx
jb 0x185d1
movq %r15, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x14250
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x14250
movq 0x10(%r14), %rax
movq (%rax), %rcx
xorl %edx, %edx
movq %rdx, 0x8(%rcx)
movq 0x8(%rax), %rax
movq %rdx, 0x8(%rax)
movl (%r14), %ebp
cmpl $0x3, %ebp
jl 0x187ac
movq %r12, (%rsp)
movl $0x2, %r12d
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %r15
xorl %eax, %eax
movl %eax, 0x1c(%r15)
movl %eax, 0x28(%r15)
movq 0x8(%r15), %rsi
xorl %r13d, %r13d
testq %rsi, %rsi
je 0x186b0
movq 0x8(%rsi), %rax
movq %rax, 0x8(%r15)
cmpl $0x0, 0x24(%rsi)
je 0x18698
movq 0x10(%rsi), %rcx
movq 0x18(%rsi), %rdx
movl 0x18(%rcx), %ecx
cmpl 0x18(%rdx), %ecx
jge 0x18698
movq %r13, 0x8(%rsi)
movq %rsi, %r13
jmp 0x186a5
movq 0x18(%rbx), %rdi
callq 0x14250
movq 0x8(%r15), %rax
movq %rax, %rsi
testq %rax, %rax
jne 0x18671
movl (%r14), %ebp
movq %r13, 0x8(%r15)
incq %r12
movslq %ebp, %rax
cmpq %rax, %r12
jl 0x18653
cmpl $0x3, %ebp
movq (%rsp), %r12
jl 0x187ac
movq 0x10(%r14), %rcx
movl %ebp, %eax
movl $0x2, %edx
movq (%rcx,%rdx,8), %rsi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x186f9
movl 0x24(%rsi), %edi
movq 0x10(%rsi), %r8
addl %edi, 0x1c(%r8)
movq 0x18(%rsi), %r8
subl %edi, 0x1c(%r8)
jmp 0x186db
incq %rdx
cmpq %rax, %rdx
jne 0x186d7
movq $0x0, (%r12)
cmpl $0x3, %ebp
jl 0x187b4
movq 0x10(%r14), %rcx
movl $0x2, %edx
xorl %edi, %edi
movq (%rcx,%rdx,8), %rsi
movslq 0x1c(%rsi), %rsi
testq %rsi, %rsi
jle 0x18731
addq %rsi, %rdi
movq %rdi, (%r12)
incq %rdx
cmpq %rdx, %rax
jne 0x1871d
shlq $0x3, %rdi
callq 0x1190
movq %rax, %r12
cmpl $0x3, %ebp
jl 0x187be
xorl %r15d, %r15d
movl $0x2, %ecx
movq %r12, 0x8(%rsp)
movq 0x10(%r14), %rax
movq (%rax,%rcx,8), %r13
cmpl $0x0, 0x1c(%r13)
jle 0x187a2
movq %rcx, (%rsp)
movslq %r15d, %rax
leaq (%r12,%rax,8), %rbp
movq 0x10(%rsp), %r12
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x18414
movq %rax, (%rbp)
addq $0x8, %rbp
incl %r15d
cmpl $0x0, 0x1c(%r13)
jg 0x18776
movl (%r14), %ebp
movq 0x8(%rsp), %r12
movq (%rsp), %rcx
addq $0x2, %rcx
cmpl %ecx, %ebp
jg 0x18757
jmp 0x187be
movq $0x0, (%r12)
xorl %edi, %edi
callq 0x1190
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14700
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq