// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movl %esi, 0x14(%rsp)
movq %rdi, %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x38(%rsp)
movq %rcx, %rdx
callq 0xe7b8
movslq 0x20(%r14), %r12
leaq (,%r12,8), %rdi
callq 0x1190
movq %rax, %r15
testq %r12, %r12
movq %rax, 0x18(%rsp)
jle 0x100c7
movq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
movq %r12, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xf19b
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x101c0
movq %rax, %r13
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%r13)
jne 0x10055
movq %r13, %rdi
movq %rbx, %rsi
callq 0x83ed
movq %rax, %r15
jmp 0x10080
movl 0x14(%rsp), %r12d
testl %r12d, %r12d
jle 0x1007d
xorl %ebp, %ebp
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1ea7d
movq %rax, %r15
movq %rbp, 0x18(%rax)
movq %rax, %rbp
decl %r12d
jne 0x10061
jmp 0x10080
xorl %r15d, %r15d
movq %r15, %rdi
movq 0x38(%rsp), %rsi
callq 0x87fa
movq 0x18(%rsp), %rax
movq %r15, (%rax,%r14,8)
movq %rax, %r15
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x149f4
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x14700
incq %r14
movq 0x30(%rsp), %r12
cmpq %r12, %r14
jne 0x10014
movq 0x10(%rbp), %rdi
callq 0x1447e
movq %rax, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl %r12d, %edx
movq %rbx, %rcx
callq 0xfeac
movq %rbp, %r13
testq %rax, %rax
je 0x10158
movq %rax, %rbp
movq 0x18(%rbp), %r14
movq $0x0, 0x18(%rbp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x8250
movq %rax, %r15
movq %rbx, (%rsp)
leaq 0x1f3(%rip), %rdi       # 0x10308
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x1a8de
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1ae1e
movq %r13, %rdi
movq %r15, %rsi
callq 0x14700
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x149f4
movq %r14, %rbp
testq %r14, %r14
jne 0x100f0
movq 0x8(%rsp), %rsi
movl 0x28(%rsi), %ebp
movq %r13, %rdi
callq 0x1b546
testl %r12d, %r12d
movq 0x18(%rsp), %r15
jle 0x10189
xorl %r14d, %r14d
movq (%r15,%r14,8), %rsi
movq %rbx, %rdi
callq 0x14a56
incq %r14
cmpq %r14, %r12
jne 0x10175
movq %r15, %rdi
callq 0x1030
movq 0x50(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rdi
callq 0x1030
movq 0x58(%rsp), %rdi
callq 0x1030
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq