// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/minhashing.c
// Function: buildTreePosetFromGraphDB
struct Graph* buildTreePosetFromGraphDB(struct Graph** db, int nGraphs, struct GraphPool* gp, struct ShallowGraphPool* sgp) {

	// if patterns are not ordered by number of vertices, sort db array accordingly before adding edges
	for (int i=0; i<nGraphs-1; ++i) {
		if (db[i]->n < db[i+1]->n) {
			fprintf(stderr, "reordering patterns by number of vertices.\nThis changes pattern ids!\n");
			qsort(db, nGraphs, sizeof(struct Graph*), &graphIdCmp);
			break;
		}
	}

	// add strings to a search tree with correct numbers
	struct Vertex* searchTree = getVertex(gp->vertexPool);
	for (int i=0; i<nGraphs; ++i) {
		db[i]->number = i + 1; // we assign new ids that match the position in our poset graph
		struct ShallowGraph* string = canonicalStringOfTree(db[i], sgp);
		addToSearchTree(searchTree, string, gp, sgp);
	}

	// create graph with vertices corresponding to strings.
	struct Graph* F = createGraph(nGraphs + 1, gp);
	for (int i=0; i<nGraphs; ++i) {
		struct Graph* g = db[i];
		F->vertices[i+1]->label = (char*)g; // misuse of char* pointer
		addEdgesFromSubtrees(g, searchTree, F, gp, sgp);
	}

	dumpSearchTree(gp, searchTree);
	return F;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r14
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r12
cmpl $0x2, %esi
movl $0x1, %eax
cmovgel %esi, %eax
decl %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x14f60
movq (%r12,%rcx,8), %rdx
movq 0x8(%r12,%rcx,8), %rsi
movl (%rdx), %edx
incq %rcx
cmpl (%rsi), %edx
jge 0x14f3f
movl %ebp, %edi
movq %r12, %rsi
callq 0x1d7a
movq 0x10(%r13), %rdi
callq 0x1447e
movq %rax, %r15
testl %ebp, %ebp
jle 0x1525a
movq %rbp, (%rsp)
movl %ebp, %ebx
movq %r15, %rbp
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
incq %r15
movl %r15d, 0x8(%rdi)
movq %r14, %rsi
callq 0x7938
movq %rbp, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x1ae1e
cmpq %r15, %rbx
jne 0x14f80
movq %r14, 0x50(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbp, 0x8(%rsp)
movq (%rsp), %rbx
leal 0x1(%rbx), %edi
movq %r13, %rsi
callq 0x85e3
testl %ebx, %ebx
jle 0x15268
leaq 0x10(%rax), %rbp
leaq 0x18(%r13), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
addq $0x4, %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movq %r13, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movq %rbp, 0x48(%rsp)
movq 0x50(%rsp), %r14
movq (%r12,%rcx,8), %r15
movq (%rbp), %rax
movq %rcx, 0x40(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %r15, (%rax)
cmpl $0x1, (%r15)
jne 0x15053
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x141f1
movq (%rbp), %rcx
movq (%rcx), %rdi
movq %rdi, 0x10(%rax)
movslq 0x8(%r15), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x18(%rax)
movq %rax, %rsi
callq 0x7cfe
movq 0x10(%rsp), %rax
incl (%rax)
jmp 0x1521f
movq %r13, %rdi
callq 0x146a9
movq %rax, %r12
movl (%r15), %esi
decl %esi
movq %rax, %rdi
callq 0x7e6c
movl (%r12), %eax
decl %eax
movl %eax, 0x4(%r12)
xorl %eax, %eax
callq 0x99c3
movq %rax, (%rsp)
cmpl $0x0, (%r15)
jle 0x15147
xorl %r13d, %r13d
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rdi
callq 0x7c5f
cmpb $0x1, %al
jne 0x15138
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x7d4b
movq %rax, %rbx
movslq (%r15), %rax
testq %rax, %rax
jle 0x150f6
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %r13
je 0x150ee
movq 0x10(%r15), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x10(%r12), %rdi
movslq %edx, %rdx
movq %rsi, (%rdi,%rdx,8)
movq 0x10(%r12), %rsi
movq (%rsi,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incl %edx
incq %rcx
cmpq %rcx, %rax
jne 0x150c7
movq %r12, %rdi
movq %r14, %rsi
callq 0x7938
movq %rax, %rbp
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x1ad58
movq (%rsp), %rdi
movl %eax, %esi
callq 0x9c0c
movq %r14, %rdi
movq %rbp, %rsi
callq 0x149f4
movq 0x10(%rbx), %rdi
movq %rbx, %rsi
callq 0x7cfe
movq 0x48(%rsp), %rbp
incq %r13
movslq (%r15), %rax
cmpq %rax, %r13
jl 0x1508e
movq (%rsp), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x151bd
xorl %r13d, %r13d
cmpl $-0x1, (%rbx)
je 0x15194
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x141f1
movq (%rbp), %rcx
movslq (%rbx), %rdx
movq (%rcx,%rdx,8), %rdi
movq %rdi, 0x10(%rax)
movslq 0x8(%r15), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x18(%rax)
movq %rax, %rsi
callq 0x7cfe
movq 0x10(%rsp), %rax
incl (%rax)
jmp 0x15197
incq %r13
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x15156
movq (%rsp), %rax
cmpq 0x18(%rax), %r13
je 0x15239
testq %r13, %r13
je 0x151c4
movq %r15, %rdi
callq 0x1db9
jmp 0x151c4
cmpq $0x0, 0x18(%rax)
je 0x15239
movslq (%r15), %rax
testq %rax, %rax
jle 0x151e1
movq 0x10(%r15), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x151d2
movslq (%r12), %rax
testq %rax, %rax
movq 0x30(%rsp), %r13
jle 0x15206
xorl %ecx, %ecx
movq 0x10(%r12), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x151f1
movq (%rsp), %rdi
callq 0x9b28
movq %r13, %rdi
movq %r12, %rsi
callq 0x14700
movq 0x28(%rsp), %r12
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %rcx
incq %rcx
cmpq 0x38(%rsp), %rcx
jne 0x15000
jmp 0x15253
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %rcx
callq 0x1dd6
jmp 0x151c4
movq 0x20(%rsp), %rbx
jmp 0x15270
incl %ebp
movl %ebp, %edi
movq %r13, %rsi
callq 0x85e3
jmp 0x1526d
movq 0x8(%rsp), %r15
movq %rax, %rbx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1b546
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq