// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movl %esi, 0x9c(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq 0xa0(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0x60(%rsp), %rdi
callq 0x15fb0
movl $0x1, 0x5c(%rsp)
movslq 0x80(%rsp), %rdi
shlq $0x3, %rdi
callq 0x1170
movq %rax, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x18f40
movq 0x78(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x88(%rsp), %rsi
callq 0x17250
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x18ae0
movq %rax, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movq 0x38(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x18ed0
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x18ece
movq 0x38(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x32f00
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x18e85
jmp 0x18ee7
movq 0x38(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0xb530
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0xbcb0
movq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x88(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x1ff70
movq 0x90(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x18e16
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x18fde
movl $0x0, 0x18(%rsp)
movq 0x50(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x18f97
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x18f74
movl 0x5c(%rsp), %eax
imull 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x18fc4
movl 0xc(%rsp), %eax
cltd
idivl 0x18(%rsp)
cmpl 0x5c(%rsp), %eax
je 0x18fc4
movl $0x7fffffff, 0x5c(%rsp) # imm = 0x7FFFFFFF
jmp 0x18fde
movl 0xc(%rsp), %eax
movl %eax, 0x5c(%rsp)
jmp 0x18fce
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x18f48
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
cmpl 0x80(%rsp), %eax
jge 0x1901b
movq 0x88(%rsp), %rdi
movq 0x50(%rsp), %rax
movslq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x20000
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x18fe6
movq 0x50(%rsp), %rdi
callq 0x1030
movq 0x70(%rsp), %rdi
callq 0x1030
movq 0x68(%rsp), %rdi
callq 0x1030
movq 0x78(%rsp), %rdi
callq 0x1030
movl 0x5c(%rsp), %eax
addq $0xa8, %rsp
retq
nop