// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rcx, %r14
movl %edx, 0x4(%rsp)
movl %esi, (%rsp)
movq %rdi, %r13
leaq 0x60(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq $0x0, 0x30(%rdi)
movslq 0x20(%rax), %r12
movl %r12d, 0x30(%rdi)
movaps (%rax), %xmm0
movups %xmm0, (%rdi)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rdi)
shlq $0x3, %r12
movq %r12, %rdi
callq 0x1190
movq %rax, 0x18(%r13)
movq %r12, %rdi
movq %rbx, %r12
callq 0x1190
movq %rax, 0x28(%r13)
cmpl $0x0, 0x30(%r13)
jle 0xf20f
xorl %ebx, %ebx
movq %r14, 0x8(%rsp)
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 %r12, %rsi
callq 0xf237
movq %r15, %rdi
movq %r14, %rsi
callq 0xea87
movq %rax, %rbp
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%rbp)
movq %r15, 0x20(%rsp)
jne 0xf128
movq %rbp, %rdi
movq %r12, %rsi
callq 0x8376
jmp 0xf166
movl (%rsp), %r14d
testl %r14d, %r14d
jle 0xf14d
xorl %r15d, %r15d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1ec39
movq %r15, 0x18(%rax)
movq %rax, %r15
decl %r14d
jne 0xf134
jmp 0xf14f
xorl %eax, %eax
cmpb $0x0, 0x4(%rsp)
movq 0x8(%rsp), %r14
je 0xf166
movq %rax, %rdi
movq %r12, %rsi
callq 0xee8a
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0xebbc
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 0xf1d8
leaq (%rax,%rbx,8), %r13
xorl %r15d, %r15d
movl $0x10, %edi
callq 0x1190
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r12, %rdi
xorl %esi, %esi
callq 0x1bd4a
movq %rax, (%r14)
addq $0x8, %r15
cmpq $0x0, (%r13)
cmoveq %r13, %r15
movq %r14, (%r15)
movq 0x18(%r12), %r12
movq %r14, %r15
testq %r12, %r12
jne 0xf19b
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %rsi
callq 0x14b19
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x14832
incq %rbx
movq 0x18(%rsp), %r13
movslq 0x30(%r13), %rax
cmpq %rax, %rbx
jl 0xf0e7
movq %r13, %rdi
callq 0xecdc
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