// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdx, %rsi
callq 0x152da
movq %rax, %r15
movq 0x10(%r15), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x1760
testb %al, %al
jne 0x1513f
movslq (%r15), %rax
pushq $0x2
popq %rcx
cmpq %rax, %rcx
jge 0x1518b
movq 0x10(%r15), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rcx, %rsi
orq $0x1, %rsi
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x15185
movq 0x18(%rdx), %rdi
movl 0x18(%rdi), %edi
cmpq %rdi, %rsi
jne 0x1516d
incl 0x24(%rdx)
addq $0x2, %rcx
jmp 0x15159
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), %rcx
andq $0x0, 0x8(%rcx)
pushq $0x2
popq %r13
movslq (%r15), %rcx
cmpq %rcx, %r13
jge 0x1522f
movq (%rax,%r13,8), %rcx
andl $0x0, 0x1c(%rcx)
xorl %ebp, %ebp
movq 0x8(%rcx), %rsi
testq %rsi, %rsi
je 0x15222
movq 0x8(%rsi), %rdx
movq %rdx, 0x8(%rcx)
cmpl $0x0, 0x24(%rsi)
je 0x1520f
movq 0x10(%rsi), %rcx
movq 0x18(%rsi), %rdx
movl 0x18(%rcx), %ecx
cmpl 0x18(%rdx), %ecx
jge 0x1520f
movq %rbp, 0x8(%rsi)
movq %rsi, %rbp
jmp 0x1521c
movq 0x18(%rbx), %rdi
callq 0x11364
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rcx
jmp 0x151df
movq (%rax,%r13,8), %rcx
movq %rbp, 0x8(%rcx)
incq %r13
jmp 0x151cd
pushq $0x2
popq %rdx
cmpq %rcx, %rdx
jge 0x1525e
movq (%rax,%rdx,8), %rsi
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x15259
movl 0x24(%rsi), %edi
movq 0x10(%rsi), %r8
addl %edi, 0x1c(%r8)
movq 0x18(%rsi), %r8
subl %edi, 0x1c(%r8)
jmp 0x1523b
incq %rdx
jmp 0x15232
movq %r15, %rdi
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 0x152bd
movq 0x10(%r15), %rax
movq %rcx, (%rsp)
movq (%rax,%rcx,8), %r13
movslq %ebp, %rbp
cmpl $0x0, 0x1c(%r13)
jle 0x152b3
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x15404
movq %rax, (%r12,%rbp,8)
incq %rbp
jmp 0x15295
movq (%rsp), %rcx
addq $0x2, %rcx
jmp 0x1527e
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