// File: /workspace/github_c_makefile_star2_O2/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 %r13d, %r13d
xorl %eax, %eax
callq 0x75db
movq %rax, (%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x11619
movq %rax, %r15
movl (%r12), %esi
decl %esi
movq %rax, %rdi
callq 0x5c80
movl (%r15), %eax
decl %eax
movl %eax, 0x4(%r15)
movq 0x18(%rsp), %rbx
movslq (%r12), %rax
cmpq %rax, %r13
jge 0x1aeb8
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x5a99
cmpb $0x1, %al
jne 0x1ae9b
movq 0x10(%r12), %rax
movq (%rax,%r13,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x5b79
movq %rax, 0x20(%rsp)
movl (%r12), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorl %edx, %edx
cmpq %rcx, %rax
je 0x1ae52
cmpq %rcx, %r13
je 0x1ae4d
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
jmp 0x1ae22
movq %r15, %rdi
movq %rbx, %rsi
callq 0x579f
movq %rax, %rbp
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1860a
movl %eax, %r14d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1184e
movq 0x20(%rsp), %rsi
movq 0x10(%rsi), %rdi
callq 0x5b2c
cmpl $-0x1, %r14d
je 0x1aea3
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x77ee
incq %r13
jmp 0x1add7
movq (%rsp), %rdi
callq 0x772d
movl (%r12), %eax
movq $0x0, (%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x1aed5
movq 0x10(%r12), %rdx
movq (%rdx,%rcx,8), %rdx
movl %ecx, 0x18(%rdx)
incq %rcx
jmp 0x1aebf
movl (%r15), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x1aef2
movq 0x10(%r15), %rdx
andq $0x0, (%rdx,%rcx,8)
incq %rcx
jmp 0x1aedf
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
movq (%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop