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

	struct BlockTree blockTree = getBlockTreeT(g, sgp);
	int numberOfConsideredSpanningTrees = 1;

	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);

	}

	for (int i=0; i<blockTree.nRoots; ++i) {
		int j=0;
		for (struct ShallowGraph* localTree=localSpanningTrees[i]; localTree!=NULL; localTree=localTree->next) {
			++j;
		}

		int tmp = numberOfConsideredSpanningTrees * j;
		if (j != 0 && tmp / j != numberOfConsideredSpanningTrees) {
			numberOfConsideredSpanningTrees = RAND_MAX;
			break;
		} else {
			numberOfConsideredSpanningTrees = tmp;
		}
	}

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

	return numberOfConsideredSpanningTrees;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r14
movq %rdx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %rsi
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x30(%rsp)
movq %rcx, %rdx
callq 0xe7b8
movslq 0x20(%rbx), %r13
leaq (,%r13,8), %rdi
callq 0x1190
movq %rax, %r15
movl $0x1, %ebp
testq %r13, %r13
jle 0x1047d
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq %r15, 0x28(%rsp)
movq 0x10(%rsp), %rbx
movq %r13, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq (%rax,%r12,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xf19b
movq %r15, 0x38(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x101c0
movq %rax, %r13
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%r13)
jne 0x103c1
movq %r13, %rdi
movq %r14, %rsi
callq 0x83ed
movq %rax, %r15
jmp 0x103e9
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
jle 0x103e6
xorl %ebp, %ebp
movq %r13, %rdi
movq %r14, %rsi
callq 0x1ea7d
movq %rax, %r15
movq %rbp, 0x18(%rax)
movq %rax, %rbp
decl %ebx
jne 0x103cb
jmp 0x103e9
xorl %r15d, %r15d
movq %r15, %rdi
movq 0x30(%rsp), %rsi
callq 0x87fa
movq 0x28(%rsp), %rax
movq %r15, (%rax,%r12,8)
movq %rax, %r15
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x149f4
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x14700
incq %r12
movq 0x20(%rsp), %r13
cmpq %r13, %r12
jne 0x10380
testl %r13d, %r13d
movl $0x1, %ebp
jle 0x1047d
xorl %eax, %eax
movq (%r15,%rax,8), %rdx
movl $0x0, %ecx
testq %rdx, %rdx
je 0x10457
xorl %ecx, %ecx
incl %ecx
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
jne 0x1044c
imull %ecx, %ebp
incq %rax
cmpq %r13, %rax
jne 0x1043c
testl %r13d, %r13d
jle 0x1047d
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rsi
movq %r14, %rdi
callq 0x14a56
incq %rbx
cmpq %rbx, %r13
jne 0x10469
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