// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/minhashing.c
// Function: addEdgesFromSubtrees
static int addEdgesFromSubtrees(struct Graph* pattern, struct Vertex* searchtree, struct Graph* F, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	// singletons have the empty graph as ancestor
	if (pattern->n == 1) {
		struct VertexList* e = getVertexList(gp->listPool);
		e->startPoint = F->vertices[0];
		e->endPoint = F->vertices[pattern->number];
		addEdge(e->startPoint, e);
		F->m += 1;
		return 1;
	}

	int edgeCount = 0;
	// 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, pattern->n - 1);
	subgraph->m = subgraph->n - 1;

	struct IntSet* subgraphs = getIntSet();

	for (int v=0; v<pattern->n; ++v) {
		// if the removed vertex is a leaf, we test if the resulting subtree is contained in the lower level
		if (isLeaf(pattern->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(pattern->vertices[v]->neighborhood->endPoint, pattern->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<pattern->n; ++i) {
				if (i == v) {
					continue; // ...with next vertex vertices
				} else {
					subgraph->vertices[j] = pattern->vertices[i];
					subgraph->vertices[j]->number = j;
					++j;
				}
			}

			// compute canonical string of subtree and get its position in F
			struct ShallowGraph* subString = canonicalStringOfTree(subgraph, sgp);
			int graphID = getID(searchtree, subString);
			addIntSortedNoDuplicates(subgraphs, graphID);
			dumpShallowGraph(sgp, subString);

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

	// to filter out duplicates, we add the edges from a list just now.
	size_t missingSubgraphs = 0;
	for (struct IntElement* graphID=subgraphs->first; graphID!=NULL; graphID=graphID->next) {
		if (graphID->value != -1) {
			struct VertexList* e = getVertexList(gp->listPool);
			e->startPoint = F->vertices[graphID->value];
			e->endPoint = F->vertices[pattern->number];
			addEdge(e->startPoint, e);
			F->m += 1;
			++edgeCount;
		} else {
//			fprintf(stderr, "subtree not found in searchtree. this should not happen if you provided a pattern set that is closed wrt. subgraph iso.\n");
			++missingSubgraphs;
		}
	}

	if (missingSubgraphs == subgraphs->size) {
		struct VertexList* e = getVertexList(gp->listPool);
		e->startPoint = F->vertices[0];
		e->endPoint = F->vertices[pattern->number];
		addEdge(e->startPoint, e);
		F->m += 1;
		++edgeCount;
		fprintf(stderr, "found minimal pattern %i with %i vertices\n", pattern->number, pattern->n);
	} else {
		if (missingSubgraphs > 0) {
			fprintf(stderr, "pattern %i is not minimal, but not all subpatterns are present\n", pattern->n);
		}
	}

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

	return edgeCount;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movq 0x98(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x20bd4
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x70(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x70(%rsp), %rsi
callq 0xa660
movq 0x88(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl $0x1, 0xa4(%rsp)
jmp 0x21004
movl $0x0, 0x6c(%rsp)
movq 0x80(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0x98(%rsp), %rax
movl (%rax), %esi
subl $0x1, %esi
callq 0xaa00
movq 0x60(%rsp), %rax
movl (%rax), %ecx
subl $0x1, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0x4(%rax)
movb $0x0, %al
callq 0xdc80
movq %rax, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movq 0x98(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x20d93
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa490
movsbl %al, %eax
cmpl $0x1, %eax
jne 0x20d81
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdi
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0xa780
movq %rax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
movq 0x98(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x20d27
movl 0x40(%rsp), %eax
cmpl 0x54(%rsp), %eax
jne 0x20ccd
jmp 0x20d1a
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x44(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x44(%rsp), %ecx
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x44(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x18(%rax)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x20d1a
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x20cb1
movq 0x60(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x9eb0
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x2c350
movl %eax, 0x34(%rsp)
movq 0x58(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0xe0c0
movq 0x78(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1ff70
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rsi
callq 0xa660
jmp 0x20d83
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x20c2b
movq $0x0, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x20e73
movq 0x20(%rsp), %rax
cmpl $-0x1, (%rax)
je 0x20e50
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x18(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0xa660
movq 0x88(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x20e5e
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x20e60
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x20da9
movq 0x28(%rsp), %rax
movq 0x58(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x20f38
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rsp), %rsi
callq 0xa660
movq 0x88(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
movq 0x1d0e8(%rip), %rax     # 0x3dff8
movq (%rax), %rdi
movq 0x98(%rsp), %rax
movl 0x8(%rax), %edx
movq 0x98(%rsp), %rax
movl (%rax), %ecx
leaq 0x14d21(%rip), %rsi     # 0x35c50
movb $0x0, %al
callq 0x1140
jmp 0x20f64
cmpq $0x0, 0x28(%rsp)
jbe 0x20f62
movq 0x1d0b1(%rip), %rax     # 0x3dff8
movq (%rax), %rdi
movq 0x98(%rsp), %rax
movl (%rax), %edx
leaq 0x14d20(%rip), %rsi     # 0x35c7b
movb $0x0, %al
callq 0x1140
jmp 0x20f64
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x98(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x20fa5
movl 0xc(%rsp), %ecx
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x18(%rax)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x20f6c
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
movq 0x60(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x20fdd
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x8(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x20fad
movq 0x58(%rsp), %rdi
callq 0xde90
movq 0x80(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x1fb30
movl 0x6c(%rsp), %eax
movl %eax, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)