// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/poset_pathCover.c
// Function: getLongestPathInFlowInstance
static int* getLongestPathInFlowInstance(struct Vertex* v, struct Graph* flowInstance, struct ShallowGraphPool* sgp) {

	struct ShallowGraph* border = getShallowGraph(sgp);
	addToVertexQueue(v, border, sgp);
	v->lowPoint = -1;
	v->d = 1;

	// use ->lowPoint to store the a parent of w
	// for sake of simplicity we count the number of times a vertex is in the border and
	// at the end of this loop highestVertex stores the last visited pattern that,
	// by construction, is on the highest level of the poset.
	struct Vertex* highestVertex = v;
	for (struct Vertex* w=popFromVertexQueue(border, sgp); w!=NULL; w=popFromVertexQueue(border, sgp)) {
		highestVertex = w;
		w->d -= 1;
		if (w->d == 0) {
			for (struct VertexList* e=w->neighborhood; e!=NULL; e=e->next) {
				if ((e->flag > 0) && (e->endPoint->d == 0)) {
					e->endPoint->lowPoint = w->number;
					e->endPoint->d += 1;
					addToVertexQueue(e->endPoint, border, sgp);
				}
			}
		}
	}

	// remove path from graph by deleting flow on edges and fixing excess at start and endpoint of path
	for (struct Vertex* x=highestVertex; x->lowPoint!=-1; x=flowInstance->vertices[x->lowPoint]) {
		for (struct VertexList* e=flowInstance->vertices[x->lowPoint]->neighborhood; e!=NULL; e=e->next) {
			if (e->endPoint == x) {
				--e->flag;
				break; // ...looping over neighbors
			}
		}
	}
	--v->visited;
	++highestVertex->visited;

	// we want to obtain paths in the original poset we obtained flowInstance from.
	// Therefore we count only those vertices on the current path in flowinstance that have even ->number
	// and will store their ->numbers divided by two to obtain the vertex ids in the original poset.
	// This should work. TODO pathLength->arrayLength
	int arrayLength = 2;
	for (struct Vertex* x=highestVertex; x->lowPoint!=-1; x=flowInstance->vertices[x->lowPoint]) {
		if (x->number % 2 == 0) {
			++arrayLength;
		}
	}

	// alloc space for path and store vertex ids
	int* path = malloc(arrayLength * sizeof(int));
	path[0] = arrayLength;
	path[1] = v->number / 2;

	// to obtain a path in the original flowInstance, we keep only those vertices that have even ->number and convert them back
	// to original numbers by dividing by two.
	arrayLength -= 1;
	for (struct Vertex* x=highestVertex; arrayLength > 1; x=flowInstance->vertices[x->lowPoint]) {
		if (x->number % 2 == 0) {
			path[arrayLength] = x->number / 2;
			--arrayLength;
		}
	}

	return path;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x1fe70
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x32870
movq 0x60(%rsp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x60(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x328c0
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
je 0x26ebc
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
movl 0x28(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x26ea1
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x26e9f
movq 0x30(%rsp), %rax
cmpl $0x0, 0x24(%rax)
jle 0x26e8d
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x28(%rax)
jne 0x26e8d
movq 0x38(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x20(%rax)
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x32870
jmp 0x26e8f
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x26e2d
jmp 0x26ea1
jmp 0x26ea3
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x328c0
movq %rax, 0x38(%rsp)
jmp 0x26dec
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpl $-0x1, 0x20(%rax)
je 0x26f4c
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x26f2a
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x28(%rsp), %rax
jne 0x26f18
movq 0x20(%rsp), %rax
movl 0x24(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x24(%rax)
jmp 0x26f2a
jmp 0x26f1a
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x26ef0
jmp 0x26f2c
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
jmp 0x26ec6
movq 0x60(%rsp), %rax
movl 0x1c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x1c(%rax)
movq 0x40(%rsp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x1c(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $-0x1, 0x20(%rax)
je 0x26fc4
movq 0x10(%rsp), %rax
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x26fa5
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x26fa7
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x26f7a
movslq 0x1c(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x8(%rsp)
movl 0x1c(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0x60(%rsp), %rax
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x1c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
cmpl $0x1, 0x1c(%rsp)
jle 0x27071
movq (%rsp), %rax
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x27054
movq (%rsp), %rax
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
movq 0x8(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x27056
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
jmp 0x27010
movq 0x8(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax,%rax)