// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/listSpanningTrees.c
// Function: _recK
struct ShallowGraph* __recK(int d, int* k, struct Graph* graph, struct Graph* partialTree, int* components, int n, struct ShallowGraphPool* sgp, struct GraphPool* gp) {

	struct VertexList* e;
	struct ShallowGraph* result1;
	struct ShallowGraph* result2;
	struct ShallowGraph* B;
	struct ShallowGraph* bridges;
	struct ShallowGraph* graphEdges = __getGraphAndNonGraphEdges(partialTree, getGraphEdges(graph, sgp), sgp);
	struct ShallowGraph* rest = graphEdges->next;

	if (rest->m == 0) {
		struct ShallowGraph* tree = getGraphEdges(partialTree, sgp);
		tree->next = tree->prev = tree;

		/* garbage collection */
		dumpShallowGraphCycle(sgp, graphEdges);

		/* count this spanning tree */
		*k -= 1;

		return tree;
	}
	/* get edge that will be included and excluded in this recursive step */
	e = popEdge(rest);

	/* add e to partialTree (already contained in graph) to find spanning trees containing e */
	addEdgeBetweenVertices(e->startPoint->number, e->endPoint->number, e->label, partialTree, gp);

	/* S1 */
	/* let B be the set of all edges (in graph) joining edges already connected in partialTree */
	B = __selectB(partialTree, rest, components, n, sgp);

	/* ensures, that adding an edge of graph to partialTree results in a tree in the recursive call */
	deleteEdges(graph, B, gp);

	result1 = __recK(d+1, k, graph, partialTree, components, n, sgp, gp);

	/* add edges to graph again */
	addEdges(graph, B, gp);

	/* preliminary garbage collection */
	dumpShallowGraphCycle(sgp, B);

	/* if we did find enough spanning trees, skip second part */
	if (*k <= 0) {
		return result1;
	}

	/* delete e from partialTree and graph to find spanning trees not containing e */
	deleteEdgeBetweenVertices(graph, e, gp);
	deleteEdgeBetweenVertices(partialTree, e, gp);

	/* S2 */
	bridges = __getNonTreeBridges(graph, partialTree, sgp);

	addEdges(partialTree, bridges, gp);
	result2 = __recK(d+1, k, graph, partialTree, components, n, sgp, gp);

	deleteEdges(partialTree, bridges, gp);

	/* At the end, spanningTree and graph need to be same as in the beginning. */
	addEdgeBetweenVertices(e->startPoint->number, e->endPoint->number, e->label, graph, gp);

	/* garbage collection */
	dumpVertexList(sgp->listPool, e);
	dumpShallowGraphCycle(sgp, bridges);
	dumpShallowGraphCycle(sgp, graphEdges);

	return addComponent(result1, result2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0x1c(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
movl %edi, 0xc(%rsp)
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %rbx
movq %rdx, %rdi
movq %rbx, %rsi
callq 0x6172
movq %r13, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x9cfe
movq %rax, %r14
movq 0x18(%rax), %rbp
cmpl $0x0, 0x10(%rbp)
je 0xa328
movq %r14, 0x50(%rsp)
movq %rbp, %rdi
callq 0x65fe
movq (%rax), %rdx
movq 0x10(%rax), %rcx
movl 0x18(%rcx), %edi
movq %rax, 0x40(%rsp)
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq %r13, %rcx
movq %r12, %r8
callq 0x6200
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %r14
movq 0x28(%rsp), %rbx
movq %rbx, %rdx
movq %r12, 0x20(%rsp)
movl 0x1c(%rsp), %r12d
movl %r12d, %ecx
movq %r14, %r8
callq 0x9c20
movq %rax, %rbp
movq %r15, %rdi
movq %rax, %rsi
movq 0x20(%rsp), %rdx
callq 0x5d7c
movl 0xc(%rsp), %edi
incl %edi
movl %edi, 0xc(%rsp)
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq %r13, 0x38(%rsp)
movq %r13, %rcx
movq %rbx, %r8
movq %r14, %rbx
movl %r12d, %r9d
movq 0x20(%rsp), %r12
pushq %r12
pushq %r14
callq 0xa11c
popq %rcx
popq %rdx
movq %rax, %r13
movq %r15, 0x48(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x6274
movq %r14, %rdi
movq %rbp, %rsi
callq 0x11888
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0xa350
movq 0x48(%rsp), %r15
movq %r15, %rdi
movq 0x40(%rsp), %r14
movq %r14, %rsi
movq %r12, %rdx
callq 0x5d1f
movq %r13, 0x30(%rsp)
movq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x5d1f
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x9da2
movq %rax, %rbp
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x6274
movl 0xc(%rsp), %edi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x28(%rsp), %r8
movl 0x1c(%rsp), %r9d
pushq %r12
pushq %rbx
callq 0xa11c
popq %rcx
popq %rdx
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x5d7c
movq (%r14), %rdx
movq 0x10(%r14), %rax
movl 0x18(%rax), %edi
movq 0x18(%r14), %rax
movl 0x18(%rax), %esi
movq %r15, %rcx
movq %r12, %r8
callq 0x6200
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x11364
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x11888
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
callq 0x11888
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x656a
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6172
movq %rax, %r13
movq %rax, 0x20(%rax)
movq %rax, 0x18(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11888
movq 0x10(%rsp), %rax
decl (%rax)
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq