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

	struct Graph* flowInstance = createVertexCoverFlowInstanceOfPoset(g, gp);

	// find max number of s-t paths
	int nAugmentations = 0;
	while (augmentWithCapacity(flowInstance->vertices[0], flowInstance->vertices[1])) {
		++nAugmentations;
	}

	// 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 v=2; v<flowInstance->n; ++v) {
		struct VertexList* keep = NULL;
		flowInstance->vertices[v]->visited = 0;
		for (struct VertexList* e=flowInstance->vertices[v]->neighborhood; e!=NULL; e=flowInstance->vertices[v]->neighborhood) {
			flowInstance->vertices[v]->neighborhood = e->next;
			if ((e->flag != 0) && (e->startPoint->number < e->endPoint->number)) {
				e->next = keep;
				keep = e;
			} else {
				dumpVertexList(gp->listPool, e);
			}
		}
		flowInstance->vertices[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(%r15), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x3393
testb %al, %al
jne 0x18209
movslq (%r15), %rax
cmpq $0x3, %rax
jl 0x1825c
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 0x18253
movq 0x18(%rsi), %r8
movl 0x18(%r8), %r8d
cmpq %r8, %rdi
jne 0x1823a
incl 0x24(%rsi)
addq $0x2, %rdx
cmpq %rax, %rdx
jb 0x1822f
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 0x1831f
movl $0x2, %r13d
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rax
movl $0x0, 0x1c(%rax)
movq 0x8(%rax), %rsi
xorl %ebp, %ebp
testq %rsi, %rsi
je 0x18308
movq 0x8(%rsi), %rax
movq 0x10(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, 0x8(%rcx)
cmpl $0x0, 0x24(%rsi)
je 0x182f1
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
movl 0x18(%rax), %eax
cmpl 0x18(%rcx), %eax
jge 0x182f1
movq %rbp, 0x8(%rsi)
movq %rsi, %rbp
jmp 0x182fa
movq 0x18(%rbx), %rdi
callq 0x1438e
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x8(%rax), %rsi
jmp 0x182bd
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rax
movq %rbp, 0x8(%rax)
incq %r13
movslq (%r15), %rax
cmpq %rax, %r13
jl 0x182a8
cmpl $0x3, %eax
jl 0x1835a
movq 0x10(%r15), %rcx
movl %eax, %edx
movl $0x2, %esi
movq (%rcx,%rsi,8), %rdi
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x18352
movl 0x24(%rdi), %r8d
movq 0x10(%rdi), %r9
addl %r8d, 0x1c(%r9)
movq 0x18(%rdi), %r9
subl %r8d, 0x1c(%r9)
jmp 0x18333
incq %rsi
cmpq %rdx, %rsi
jne 0x1832f
movq $0x0, (%r12)
cmpl $0x3, %eax
jl 0x1838b
movq 0x10(%r15), %rcx
movl %eax, %eax
movl $0x2, %edx
movq (%rcx,%rdx,8), %rsi
movslq 0x1c(%rsi), %rsi
testq %rsi, %rsi
jle 0x18383
addq %rsi, (%r12)
incq %rdx
cmpq %rdx, %rax
jne 0x18372
movq %rbx, 0x10(%rsp)
movq (%r12), %rdi
shlq $0x3, %rdi
callq 0x1190
movq %rax, 0x8(%rsp)
cmpl $0x3, (%r15)
jl 0x183f2
xorl %ebp, %ebp
movl $0x2, %r12d
movq 0x10(%r15), %rax
movq (%rax,%r12,8), %r13
cmpl $0x0, 0x1c(%r13)
jle 0x183e9
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 0x183cb
addq $0x2, %r12
cmpl %r12d, (%r15)
jg 0x183b0
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