// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdx, %rsi
callq 0x1830f
movq %rax, %r14
movq 0x10(%r14), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x33ce
testb %al, %al
jne 0x180e7
movslq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq $0x3, %rcx
jl 0x1813a
movl $0x2, %edx
movq (%rax,%rdx,8), %rsi
movq %rdx, %rdi
orq $0x1, %rdi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x18131
movq 0x18(%rsi), %r8
movl 0x18(%r8), %r8d
cmpq %r8, %rdi
jne 0x18118
incl 0x24(%rsi)
addq $0x2, %rdx
cmpq %rcx, %rdx
jb 0x1810d
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), %rcx
movq %rdx, 0x8(%rcx)
movl (%r14), %ebp
cmpl $0x3, %ebp
jl 0x182e0
movq %r15, 0x8(%rsp)
movq %r12, %r15
movl $0x2, %r13d
movq (%rax,%r13,8), %rcx
movl $0x0, 0x1c(%rcx)
movq 0x8(%rcx), %rsi
xorl %r12d, %r12d
testq %rsi, %rsi
je 0x181ed
movq 0x8(%rsi), %rdx
movq %rdx, 0x8(%rcx)
cmpl $0x0, 0x24(%rsi)
je 0x181cc
movq 0x10(%rsi), %rcx
movq 0x18(%rsi), %rdx
movl 0x18(%rcx), %ecx
cmpl 0x18(%rdx), %ecx
jge 0x181cc
movq %r12, 0x8(%rsi)
movq %rsi, %r12
jmp 0x181d9
movq 0x18(%rbx), %rdi
callq 0x14250
movq 0x10(%r14), %rax
movq (%rax,%r13,8), %rcx
movq 0x8(%rcx), %rsi
testq %rsi, %rsi
jne 0x181a5
movl (%r14), %ebp
movq (%rax,%r13,8), %rcx
movq %r12, 0x8(%rcx)
incq %r13
movslq %ebp, %rcx
cmpq %rcx, %r13
jl 0x1818e
cmpl $0x3, %ebp
movq %r15, %r12
jl 0x182e0
movl %ebp, %ecx
movl $0x2, %edx
movq (%rax,%rdx,8), %rsi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x18231
movl 0x24(%rsi), %edi
movq 0x10(%rsi), %r8
addl %edi, 0x1c(%r8)
movq 0x18(%rsi), %r8
subl %edi, 0x1c(%r8)
jmp 0x18213
incq %rdx
cmpq %rcx, %rdx
jne 0x1820f
movq $0x0, (%r12)
cmpl $0x3, %ebp
jl 0x182e8
movl $0x2, %edx
xorl %edi, %edi
movq (%rax,%rdx,8), %rsi
movslq 0x1c(%rsi), %rsi
testq %rsi, %rsi
jle 0x18265
addq %rsi, %rdi
movq %rdi, (%r12)
incq %rdx
cmpq %rdx, %rcx
jne 0x18251
shlq $0x3, %rdi
callq 0x1190
movq %rax, %r15
cmpl $0x3, %ebp
jl 0x182f2
xorl %r12d, %r12d
movl $0x2, %ecx
movq %r15, (%rsp)
movq 0x10(%r14), %rax
movq (%rax,%rcx,8), %r13
cmpl $0x0, 0x1c(%r13)
jle 0x182d6
movq %rcx, 0x10(%rsp)
movslq %r12d, %rax
leaq (%r15,%rax,8), %rbp
movq 0x8(%rsp), %r15
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x18414
movq %rax, (%rbp)
addq $0x8, %rbp
incl %r12d
cmpl $0x0, 0x1c(%r13)
jg 0x182aa
movl (%r14), %ebp
movq (%rsp), %r15
movq 0x10(%rsp), %rcx
addq $0x2, %rcx
cmpl %ecx, %ebp
jg 0x1828a
jmp 0x182f2
movq $0x0, (%r12)
xorl %edi, %edi
callq 0x1190
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14700
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq