// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/poset_pathCover.c
// Function: getLongestPathInDAG
static int* getLongestPathInDAG(struct Vertex* v, struct Graph* poset, 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
	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->endPoint->visited == 0) && (e->endPoint->d == 0)) {
					e->endPoint->lowPoint = w->number;
					e->endPoint->d += 1;
					addToVertexQueue(e->endPoint, border, sgp);
				}
			}
		}
	}
	// here w stores the last visited pattern that, by construction, is on the highest level of the poset.
	// backtrack using the ->lowPoints from here.
	int pathLength = 2;
	int* path = NULL;
	for (struct Vertex* x=highestVertex; x->lowPoint!=-1; x=poset->vertices[x->lowPoint]) {
		++pathLength;
	}

	path = malloc(pathLength * sizeof(int));
	path[0] = pathLength;
	path[1] = v->number;

	pathLength -= 1;
	for (struct Vertex* x=highestVertex; x->lowPoint!=-1; x=poset->vertices[x->lowPoint]) {
		path[pathLength] = x->number;
		--pathLength;
	}

	return path;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x40(%rsp), %rdi
callq 0x1fe70
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x32870
movq 0x50(%rsp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq 0x50(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x328c0
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x27cc0
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movl 0x28(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x28(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x27ca5
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x27ca3
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x27c91
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x28(%rax)
jne 0x27c91
movq 0x28(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x20(%rax)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x32870
jmp 0x27c93
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x27c2d
jmp 0x27ca5
jmp 0x27ca7
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x328c0
movq %rax, 0x28(%rsp)
jmp 0x27bec
movl $0x2, 0x1c(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpl $-0x1, 0x20(%rax)
je 0x27d0e
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
jmp 0x27cdb
movslq 0x1c(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x10(%rsp)
movl 0x1c(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x1c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
cmpl $-0x1, 0x20(%rax)
je 0x27d94
movq (%rsp), %rax
movl 0x18(%rax), %edx
movq 0x10(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rsp), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
jmp 0x27d50
movq 0x10(%rsp), %rax
addq $0x58, %rsp
retq
nop