// File: /workspace/github_c_makefile_star2_O1/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 0x99af
movq %rax, (%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x147d7
movq %rax, %r15
movl (%r12), %esi
decl %esi
movq %rax, %rdi
callq 0x7e30
movl (%r15), %eax
decl %eax
movl %eax, 0x4(%r15)
cmpl $0x0, (%r12)
jle 0x1db6a
xorl %r13d, %r13d
movq 0x18(%rsp), %rbx
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x7c33
cmpb $0x1, %al
jne 0x1db5a
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x7d23
movq %rax, 0x20(%rsp)
movslq (%r12), %rax
testq %rax, %rax
jle 0x1dafc
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %r13
je 0x1daf4
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 0x1dace
movq %r15, %rdi
movq %rbx, %rsi
callq 0x78fc
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1ae44
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14b19
movq 0x20(%rsp), %rsi
movq 0x10(%rsi), %rdi
callq 0x7cd0
cmpl $-0x1, %ebp
je 0x1db44
movq (%rsp), %rdi
movl %ebp, %esi
callq 0x9bf0
jmp 0x1db55
movq (%rsp), %rdi
callq 0x9b14
movq $0x0, (%rsp)
cmpl $-0x1, %ebp
je 0x1db6a
incq %r13
movslq (%r12), %rax
cmpq %rax, %r13
jl 0x1da90
movslq (%r12), %rax
testq %rax, %rax
jle 0x1db89
movq 0x10(%r12), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x1db7a
movslq (%r15), %rax
testq %rax, %rax
jle 0x1dba7
xorl %ecx, %ecx
movq 0x10(%r15), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1db93
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x14832
movq (%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop