// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rcx, %rbx
movq %rdx, %r12
movl %esi, 0x1c(%rsp)
movq %rdi, %rsi
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x28(%rsp)
movq %rcx, %rdx
callq 0xe85c
movslq 0x20(%r14), %r13
leaq (,%r13,8), %rdi
callq 0x1190
testq %r13, %r13
movq %rax, 0x20(%rsp)
movq %r12, 0x10(%rsp)
jle 0x10172
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xf237
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x10297
movq %rax, %rbp
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%rbp)
jne 0x10100
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x8376
movq %rax, %r12
jmp 0x1012c
movl 0x1c(%rsp), %r15d
testl %r15d, %r15d
jle 0x10129
xorl %r13d, %r13d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1ec39
movq %rax, %r12
movq %r13, 0x18(%rax)
movq %rax, %r13
decl %r15d
jne 0x1010d
jmp 0x1012c
xorl %r12d, %r12d
movq %r12, %rdi
movq 0x28(%rsp), %rsi
callq 0x877e
movq 0x20(%rsp), %r15
movq %r12, (%r15,%r14,8)
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x14b19
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x14832
incq %r14
movslq 0x50(%rsp), %r13
cmpq %r13, %r14
jl 0x100c0
jmp 0x10175
movq %rax, %r15
movq 0x10(%r12), %rdi
callq 0x145b2
movq %rax, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl %r13d, %edx
movq %rbx, %rcx
callq 0xff6a
movq %rax, %r13
movq %rax, %r14
testq %rax, %rax
je 0x101ab
movq 0x18(%r13), %r14
movq $0x0, 0x18(%r13)
testq %r13, %r13
je 0x10228
movq %r14, %r12
movq 0x10(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x81e0
movq %rax, %rbp
movq %rbx, (%rsp)
leaq 0x207(%rip), %rdi       # 0x103d8
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x1a9ac
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1af0f
movq %r15, %rdi
movq %rbp, %rsi
callq 0x14832
movq %rbx, %rdi
movq %r13, %rsi
callq 0x14b19
testq %r14, %r14
je 0x1021d
movq 0x18(%r14), %r12
movq $0x0, 0x18(%r14)
movq %r14, %r13
testq %r14, %r14
movq %r12, %r14
jne 0x101b8
movq 0x8(%rsp), %rsi
movl 0x28(%rsi), %ebp
movq 0x10(%rsp), %rdi
callq 0x1b644
movslq 0x50(%rsp), %r14
testq %r14, %r14
movq 0x20(%rsp), %r12
jle 0x10260
xorl %r15d, %r15d
movq (%r12,%r15,8), %rsi
movq %rbx, %rdi
callq 0x14b75
incq %r15
cmpq %r15, %r14
jne 0x1024c
movq %r12, %rdi
callq 0x1030
movq 0x40(%rsp), %rdi
callq 0x1030
movq 0x38(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rdi
callq 0x1030
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq