// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/localEasySubtreeIsomorphism.c
// Function: getNumberOfNonisomorphicSpanningTreesObtainedByLocalEasySampling
int getNumberOfNonisomorphicSpanningTreesObtainedByLocalEasySampling(struct Graph* g, int k, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	struct BlockTree blockTree = getBlockTreeT(g, sgp);
	int numberOfNonisomorphicSpanningForestComponents = 0;

	struct ShallowGraph** localSpanningTrees = malloc(blockTree.nRoots * sizeof(struct Graph*));

	for (int v=0; v<blockTree.nRoots; ++v) {
		struct ShallowGraph* mergedEdges = mergeShallowGraphs(blockTree.vRootedBlocks[v], sgp);
		struct Graph* mergedGraph = blockConverterKeepIDs(mergedEdges, gp);

		struct ShallowGraph* shallowSpanningtrees = NULL;
		if (mergedGraph->m != mergedGraph->n-1) {
			// sample spanning trees according to parameter
			for (int i=0; i<k; ++i) {
				struct ShallowGraph* spt = randomSpanningTreeAsShallowGraph(mergedGraph, sgp);
				spt->next = shallowSpanningtrees;
				shallowSpanningtrees = spt;
			}

			/* Duplicate spanning trees are NOT filtered here.
			 * In contrast to normal spanning tree sampling, here we can only filter identical trees (seen as edge sets)
			 * and not trees up to isomorphism, as two isomorphic but different local spanning trees might result in different
			 * (and hence possibly nonisomorphic) global spanning trees, when combined. */
//			shallowSpanningtrees = filterDuplicateSpanningTrees(shallowSpanningtrees, sgp);

		} else {
			// if the mergedGraph is a tree, we use it directly
			shallowSpanningtrees = getGraphEdges(mergedGraph, sgp);
		}

		// make the shallowgraphs be subgraphs of g, not of mergedGraph
		rebaseShallowGraphsOnLowPoints(shallowSpanningtrees, g);

		localSpanningTrees[v] = shallowSpanningtrees;

		// garbage collection
		dumpShallowGraph(sgp, mergedEdges);
		dumpGraph(gp, mergedGraph);

	}

	struct Vertex* searchTree = getVertex(gp->vertexPool);

	struct ShallowGraph* combinations = spanningTreeCombinations(localSpanningTrees, 0, blockTree.nRoots, sgp);
	for (struct ShallowGraph* combination=popShallowGraph(&combinations); combination!=NULL; combination=popShallowGraph(&combinations)) {
		struct Graph* spForest = shallowGraphToGraph(combination, gp);
		addToSearchTree(searchTree, runForEachConnectedComponent(&xcanonicalStringOfTree, spForest, 0, 0, 0, gp, sgp), gp, sgp);
		dumpGraph(gp, spForest);
		dumpShallowGraph(sgp, combination);
	}

	numberOfNonisomorphicSpanningForestComponents = searchTree->d;

	//garbage collection
	dumpSearchTree(gp, searchTree);
	for (int v=0; v<blockTree.nRoots; ++v) {
		dumpShallowGraphCycle(sgp, localSpanningTrees[v]);
	}
	free(localSpanningTrees);
	free(blockTree.parents);
	free(blockTree.roots);
	free(blockTree.vRootedBlocks);

	return numberOfNonisomorphicSpanningForestComponents;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %rbx
movq %rdx, 0x8(%rsp)
movl %esi, %ebp
movq %rdi, %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x10(%rsp)
movq %rcx, %rdx
callq 0xbe98
movslq 0x20(%r14), %r13
movq %r13, %rdi
shlq $0x3, %rdi
callq 0x1180
movq %rax, 0x18(%rsp)
movq 0x18(%r14), %r12
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
movl %ebp, 0x24(%rsp)
testl %r13d, %r13d
movl $0x0, %eax
movq %r13, 0x30(%rsp)
cmovgl %r13d, %eax
movq %rax, 0x28(%rsp)
movq %r12, 0x38(%rsp)
cmpq 0x28(%rsp), %r15
je 0xd5b2
movq (%r12,%r15,8), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc7c2
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0xd6ca
movq %rax, %rbp
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%rbp)
jne 0xd555
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6172
movq %rax, %r13
jmp 0xd57c
movl 0x24(%rsp), %r12d
xorl %r13d, %r13d
subl $0x1, %r12d
jb 0xd577
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1bdd7
movq %r13, 0x18(%rax)
movq %rax, %r13
jmp 0xd55d
movq 0x38(%rsp), %r12
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x6529
movq 0x18(%rsp), %rax
movq %r13, (%rax,%r15,8)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1184e
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x1166e
incq %r15
jmp 0xd512
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x114a5
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
movq %rbx, %rcx
callq 0xd39e
movq %rax, %r14
testq %rax, %rax
je 0xd5ed
movq 0x18(%r14), %r15
andq $0x0, 0x18(%r14)
movq %r14, %rbp
testq %rbp, %rbp
je 0xd661
movq %r15, %r14
movq %rbp, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x5fe8
movq %rax, %r13
movq %rbx, (%rsp)
leaq 0x1fc(%rip), %rdi       # 0xd812
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x181c4
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x186c6
movq %r15, %rdi
movq %r13, %rsi
callq 0x1166e
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1184e
movl $0x0, %r15d
movq %r14, %rbp
testq %r14, %r14
je 0xd5f0
jmp 0xd5e4
movq 0x10(%rsp), %rsi
movl 0x28(%rsi), %ebp
movq 0x8(%rsp), %rdi
callq 0x18dcd
xorl %r14d, %r14d
cmpq %r14, 0x28(%rsp)
je 0xd693
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0x11888
incq %r14
jmp 0xd676
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x50(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq