// File: /workspace/github_c_makefile_star2_O2/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, (%rsp)
movl %edx, 0xc(%rsp)
movl %esi, %ebx
movq %rdi, %r13
leaq 0x60(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
andq $0x0, 0x30(%rdi)
movslq 0x20(%rax), %r15
movl %r15d, 0x30(%rdi)
movaps (%rax), %xmm0
movups %xmm0, (%rdi)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rdi)
movq %r15, %r12
shlq $0x3, %r12
movq %r12, %rdi
callq 0x1180
movq %rax, 0x18(%r13)
movq %r12, %rdi
callq 0x1180
movq %rax, 0x28(%r13)
xorl %ecx, %ecx
testl %ebx, %ebx
cmovlel %ecx, %ebx
movl %ebx, 0x8(%rsp)
movq %r13, 0x18(%rsp)
movslq %r15d, %rax
cmpq %rax, %rcx
jge 0xc79a
leaq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc7c2
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0xc093
movq %rax, %rbp
movl (%rax), %eax
decl %eax
cmpl %eax, 0x4(%rbp)
jne 0xc6cc
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6172
jmp 0xc6fe
movl 0x8(%rsp), %ebx
xorl %r12d, %r12d
subl $0x1, %ebx
jb 0xc6ec
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1bdd7
movq %r12, 0x18(%rax)
movq %rax, %r12
jmp 0xc6d3
cmpb $0x0, 0xc(%rsp)
je 0xc701
movq %r12, %rdi
movq %r14, %rsi
callq 0xc483
movq %rax, %r12
movq %r12, %rdi
movq %rbp, %rsi
movq (%rsp), %rdx
movq %r14, %rcx
callq 0xc1cf
movq 0x18(%r13), %rcx
movq 0x10(%rsp), %rdx
leaq (%rcx,%rdx,8), %r12
movq %rax, (%r12)
movq 0x28(%r13), %rax
leaq (%rax,%rdx,8), %r13
andq $0x0, (%r13)
xorl %r15d, %r15d
movq (%r12), %r12
testq %r12, %r12
je 0xc76b
callq 0xde1a
movq %rax, %rbx
movq %r12, %rdi
xorl %esi, %esi
callq 0x1945b
movq %rax, (%rbx)
addq $0x8, %r15
cmpq $0x0, (%r13)
cmoveq %r13, %r15
movq %rbx, (%r15)
addq $0x18, %r12
movq %rbx, %r15
jmp 0xc734
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x1184e
movq (%rsp), %rdi
movq %rbp, %rsi
callq 0x1166e
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %r13
movl 0x30(%r13), %r15d
jmp 0xc679
movq %r13, %rdi
callq 0xc2f0
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