// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/treeEnumeration.c
// Function: aprioriCheckExtensionReturnList
struct IntSet* aprioriCheckExtensionReturnList(struct Graph* extension, struct Vertex* lowerLevel, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	// returning NULL will indicate that apriori property does not hold for current
	struct IntSet* aprioriTreesOfExtension = getIntSet();

	// create graph that will hold subgraphs of size n-1 (this assumes that all extension trees have the same size)
	struct Graph* subgraph = getGraph(gp);
	setVertexNumber(subgraph, extension->n - 1);
	subgraph->m = subgraph->n - 1;

	for (int v=0; v<extension->n; ++v) {
		// if the removed vertex is a leaf, we test if the resulting subtree is contained in the lower level
		if (isLeaf(extension->vertices[v]) == 1) {
			// we invalidate current by removing the edge to v from its neighbor, which makes subgraph a valid tree
			struct VertexList* edge = snatchEdge(extension->vertices[v]->neighborhood->endPoint, extension->vertices[v]);
			// now copy pointers of all vertices \neq v to subgraph, this results in a tree of size current->n - 1
			int j = 0;
			for (int i=0; i<extension->n; ++i) {
				if (i == v) {
					continue; // ...with next vertex vertices
				} else {
					subgraph->vertices[j] = extension->vertices[i];
					subgraph->vertices[j]->number = j;
					++j;
				}
			}

			// test apriori property
			struct ShallowGraph* subString = canonicalStringOfTree(subgraph, sgp);
			int aprioriTreeID = getID(lowerLevel, subString);
			dumpShallowGraph(sgp, subString);

			// restore law and order in current (and invalidate subgraph)
			addEdge(edge->startPoint, edge);

			if (aprioriTreeID == -1) {
				dumpIntSet(aprioriTreesOfExtension);
				aprioriTreesOfExtension = NULL;
				break; // looping through the vertices of current and continue with next refinement
			} else {
				addIntSortedNoDuplicates(aprioriTreesOfExtension, aprioriTreeID);
			}
		}
	}

	// clean up
	for (int v=0; v<extension->n; ++v) {
		extension->vertices[v]->number = v;
	}
	// garbage collection
	for (int v=0; v<subgraph->n; ++v) {
		subgraph->vertices[v] = NULL;
	}
	dumpGraph(gp, subgraph);

	if (aprioriTreesOfExtension != NULL) {
		assert(isSortedUniqueIntSet(aprioriTreesOfExtension));
		return aprioriTreesOfExtension;
	} else {
		return NULL;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
xorl %eax, %eax
callq 0x99c3
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x146a9
movq %rax, %r15
movl (%r12), %esi
decl %esi
movq %rax, %rdi
callq 0x7e6c
movl (%r15), %eax
decl %eax
movl %eax, 0x4(%r15)
cmpl $0x0, (%r12)
jle 0x1da3a
movq %rbx, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x18(%rsp), %rbx
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x7c5f
cmpb $0x1, %al
jne 0x1d9f2
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x7d4b
movq %rax, 0x20(%rsp)
movslq (%r12), %rax
testq %rax, %rax
jle 0x1d9a9
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %r13
je 0x1d9a1
movq 0x10(%r12), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x10(%r15), %rdi
movslq %edx, %rdx
movq %rsi, (%rdi,%rdx,8)
movq 0x10(%r15), %rsi
movq (%rsi,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incl %edx
incq %rcx
cmpq %rcx, %rax
jne 0x1d97b
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7938
movq %rax, %rbp
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1ad58
movl %eax, %r14d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x149f4
movq 0x20(%rsp), %rsi
movq 0x10(%rsi), %rdi
callq 0x7cfe
cmpl $-0x1, %r14d
je 0x1da04
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x9c0c
incq %r13
movslq (%r12), %rax
cmpq %rax, %r13
jl 0x1d93d
jmp 0x1da19
movq (%rsp), %rdi
callq 0x9b28
movl (%r12), %eax
movq $0x0, (%rsp)
testl %eax, %eax
movq 0x8(%rsp), %rbx
jle 0x1da3a
movq 0x10(%r12), %rcx
movl %eax, %eax
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x1da2b
movslq (%r15), %rax
testq %rax, %rax
jle 0x1da58
xorl %ecx, %ecx
movq 0x10(%r15), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1da44
movq %rbx, %rdi
movq %r15, %rsi
callq 0x14700
movq (%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop