// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/localEasySubtreeIsomorphism.c
// Function: getSampledSpanningtreeTree
struct SpanningtreeTree getSampledSpanningtreeTree(struct BlockTree blockTree, int spanningTreesPerBlock, char removeDuplicates, struct GraphPool* gp, struct ShallowGraphPool* sgp) {
	struct SpanningtreeTree sptTree = {0,0,0,0,0,0,0};
	sptTree.g = blockTree.g;
	sptTree.nRoots = blockTree.nRoots;
	sptTree.roots = blockTree.roots;
	sptTree.parents = blockTree.parents;
	sptTree.localSpanningTrees = malloc(sptTree.nRoots * sizeof(struct Graph*));
	sptTree.localPostorders = malloc(sptTree.nRoots * sizeof(struct PostorderList*));

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

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

			/* Duplicate spanning trees are 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. */
			if (removeDuplicates) {
				shallowSpanningtrees = filterDuplicateSpanningTrees(shallowSpanningtrees, sgp);
			}
		} else {
			// if the mergedGraph is a tree, we use it directly
			shallowSpanningtrees = getGraphEdges(mergedGraph, sgp);
		}
		sptTree.localSpanningTrees[v] = spanningTreeConverter(shallowSpanningtrees, mergedGraph, gp, sgp);

		sptTree.localPostorders[v] = NULL;
		struct PostorderList* tail = NULL;
		for (struct Graph* localSpanningTree=sptTree.localSpanningTrees[v]; localSpanningTree!=NULL; localSpanningTree=localSpanningTree->next) {
			struct PostorderList* tmp = __getPOL();
			tmp->postorder = getPostorder(localSpanningTree, 0);
			if (sptTree.localPostorders[v] == NULL) {
				sptTree.localPostorders[v] = tail = tmp;
			} else {
				// append at the end of the list
				tail->next = tmp;
				tail = tmp;
			}
		}

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

	initCharacteristicsArrayForLocalEasy(&sptTree);

	//garbage collection
	free(blockTree.vRootedBlocks);

	return sptTree;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rcx, %r15
movl %edx, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, %r13
leaq 0x60(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movq $0x0, 0x30(%rdi)
movslq 0x20(%rax), %rbx
movl %ebx, 0x30(%rdi)
movaps (%rax), %xmm0
movups %xmm0, (%rdi)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rdi)
leaq (,%rbx,8), %r12
movq %r12, %rdi
callq 0x1190
movq %rax, 0x18(%r13)
movq %r12, %rdi
movq %r15, %r12
callq 0x1190
movq %rax, 0x28(%r13)
testq %rbx, %rbx
jle 0xf173
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
leaq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%rbx,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xf19b
movq %r15, %rdi
movq %r12, %rsi
callq 0xe9d1
movq %rax, %rbp
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%rbp)
movq %rbx, (%rsp)
movq %r15, 0x20(%rsp)
jne 0xf08d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x83ed
jmp 0xf0c8
movl 0x8(%rsp), %ebx
testl %ebx, %ebx
jle 0xf0b0
xorl %r15d, %r15d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1ea7d
movq %r15, 0x18(%rax)
movq %rax, %r15
decl %ebx
jne 0xf098
jmp 0xf0b2
xorl %eax, %eax
cmpb $0x0, 0xc(%rsp)
je 0xf0c4
movq %rax, %rdi
movq %r14, %rsi
callq 0xee4d
movq (%rsp), %rbx
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0xeb0d
movq 0x18(%r13), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x28(%r13), %rax
movq $0x0, (%rax,%rbx,8)
movq (%rcx,%rbx,8), %r12
testq %r12, %r12
je 0xf13d
movq (%rsp), %rcx
leaq (%rax,%rcx,8), %r13
xorl %r15d, %r15d
movl $0x1, %edi
movl $0x10, %esi
callq 0x1120
movq %rax, %rbx
movq %r12, %rdi
xorl %esi, %esi
callq 0x1bc66
movq %rax, (%rbx)
addq $0x8, %r15
cmpq $0x0, (%r13)
cmoveq %r13, %r15
movq %rbx, (%r15)
movq 0x18(%r12), %r12
movq %rbx, %r15
testq %r12, %r12
jne 0xf101
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x149f4
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x14700
movq (%rsp), %rbx
incq %rbx
movq 0x18(%rsp), %r13
movslq 0x30(%r13), %rax
cmpq %rax, %rbx
jl 0xf048
movq %r13, %rdi
callq 0xec1e
leaq 0x60(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1030
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq