// File: /workspace/github_c_makefile_star2_O1/pwelke[P]GraphMiningTools/listSpanningTrees.c
// Function: _recCount
long int __recCount(long int d, struct Graph* graph, struct Graph* partialTree, int* components, int n, struct ShallowGraphPool* sgp, struct GraphPool* gp) {
	struct ShallowGraph* B;

	struct ShallowGraph* graphEdges = __getGraphAndNonGraphEdges(partialTree, getGraphEdges(graph, sgp), sgp);
	struct ShallowGraph* rest = graphEdges->next;

	if (rest->m == 0) {
		/* garbage collection */
		dumpShallowGraphCycle(sgp, graphEdges);
		return 1;
	}

	/* get edge that will be included and excluded in this __recursive step */
	struct VertexList* 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);

	long int result1 = __recCount(d, graph, partialTree, components, n, sgp, gp);

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

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

	/* at this point, graph and partialTree are as at the start of this call.
	If there are already too many spanning Trees found (indicated by return value -1)
	return at this point and prune the second __recursive call */
	if ((result1 == -1) || (result1 > d)) {
		/* garbage collection */
		dumpVertexList(sgp->listPool, e);
		dumpShallowGraphCycle(sgp, graphEdges);
		return -1;
	}

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

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

	addEdges(partialTree, bridges, gp);
	long int result2 = __recCount(d, 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);

	if ((result2 == -1) || (result2 > d)) {
		/* if there were too many spanning trees in the second __recursion... */ 
		return -1;
	} else {
		/* avoid overflow */
		if ((result1 > LONG_MAX / 2) || (result2 > LONG_MAX / 2)) {
			return -1;
		} else {
			return result1 + result2;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movl %r8d, %r15d
movq %rcx, 0x28(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
movq %rsi, %rdi
movq %r9, %rsi
callq 0x8376
movq %r13, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0xc3c7
movq 0x18(%rax), %r14
cmpl $0x0, 0x10(%r14)
je 0xcc5e
movq %rax, 0x20(%rsp)
movl %r15d, 0xc(%rsp)
movq 0x70(%rsp), %rbp
movq %r14, %rdi
callq 0x8891
movq (%rax), %rdx
movq 0x10(%rax), %rcx
movl 0x18(%rcx), %edi
movq %rax, 0x18(%rsp)
movq 0x18(%rax), %rax
movl 0x18(%rax), %esi
movq %r13, %rcx
movq %rbp, %r8
callq 0x8425
movq %r13, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rbp
movq %rbp, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0xc2e9
movq %rax, %r14
movq %r12, %rdi
movq %rax, %rsi
movq 0x70(%rsp), %r15
movq %r15, %rdx
callq 0x7f4e
movq %r15, (%rsp)
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movl 0xc(%rsp), %r8d
movq %rbx, %r9
callq 0xcb33
movq %rax, %rbp
movq %r12, %rdi
movq %r14, %rsi
movq 0x70(%rsp), %rdx
callq 0x84ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14b75
cmpq $-0x1, %rbp
setne %al
cmpq %r15, %rbp
setle %cl
testb %cl, %al
jne 0xcc73
movq 0x10(%rbx), %rdi
movq 0x18(%rsp), %rsi
callq 0x1438e
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x14b75
movq $-0x1, %rax
jmp 0xcd77
movq %rbx, %rdi
movq %rax, %rsi
callq 0x14b75
movl $0x1, %eax
jmp 0xcd77
movq %rbp, 0x30(%rsp)
movq %r12, %rdi
movq 0x18(%rsp), %rbp
movq %rbp, %rsi
movq 0x70(%rsp), %r15
movq %r15, %rdx
callq 0x7ef1
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x7ef1
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc467
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x84ba
movq %r15, (%rsp)
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x28(%rsp), %rcx
movl 0xc(%rsp), %r8d
movq %rbx, %r9
callq 0xcb33
movq %rax, %r15
movq %r13, %rdi
movq %r14, %rsi
movq 0x70(%rsp), %r13
movq %r13, %rdx
callq 0x7f4e
movq (%rbp), %rdx
movq 0x10(%rbp), %rax
movl 0x18(%rax), %edi
movq 0x18(%rbp), %rax
movl 0x18(%rax), %esi
movq %r12, %rcx
movq %r13, %r8
callq 0x8425
movq 0x10(%rbx), %rdi
movq %rbp, %rsi
callq 0x1438e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14b75
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x14b75
cmpq $-0x1, %r15
sete %al
cmpq 0x10(%rsp), %r15
setg %cl
orb %al, %cl
movq $-0x1, %rax
jne 0xcd77
movq 0x30(%rsp), %rsi
leaq (%r15,%rsi), %rax
movabsq $0x3fffffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFFFF
cmpq %rcx, %r15
movq $-0x1, %rdx
cmovgq %rdx, %rax
cmpq %rcx, %rsi
cmovgq %rdx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq