// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rcx, 0x38(%rsp)
movq %rdx, 0x8(%rsp)
movl %esi, %ebp
movq %rdi, %r15
cmpl $0x2, %esi
pushq $0x1
popq %rax
cmovgel %esi, %eax
decl %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x11d1f
movq (%r15,%rcx,8), %rdx
movq 0x8(%r15,%rcx,8), %rsi
movl (%rdx), %edx
incq %rcx
cmpl (%rsi), %edx
jge 0x11cd7
movq 0x18303(%rip), %rax     # 0x29ff8
movq (%rax), %rcx
leaq 0xbe81(%rip), %rdi      # 0x1db80
pushq $0x45
popq %rsi
pushq $0x1
popq %rdx
callq 0x1210
movslq %ebp, %rsi
leaq 0x34d(%rip), %rcx       # 0x12061
pushq $0x8
popq %rdx
movq %r15, %rdi
callq 0x1080
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x114a5
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %r14
cmpq %rbx, 0x30(%rsp)
je 0x11d78
movq (%r15,%rbx,8), %rdi
incq %rbx
movl %ebx, 0x8(%rdi)
movq %r14, %rsi
callq 0x579f
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movq 0x8(%rsp), %rdx
movq %r14, %rcx
callq 0x186c6
jmp 0x11d48
incl %ebp
movl %ebp, %edi
movq 0x8(%rsp), %rsi
callq 0x630e
movq %rax, %r12
xorl %r14d, %r14d
movq %r15, 0x28(%rsp)
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %r13
cmpq 0x30(%rsp), %r14
je 0x12040
movq (%r15,%r14,8), %r15
movq 0x10(%r12), %rax
movq 0x8(%rax,%r14,8), %rax
incq %r14
movq %r15, (%rax)
cmpl $0x1, (%r15)
jne 0x11dfa
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x11307
movq 0x10(%r12), %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 0x5b2c
incl 0x4(%r12)
movq 0x28(%rsp), %r15
jmp 0x11d9b
movq %r14, 0x20(%rsp)
movq 0x8(%rsp), %rdi
callq 0x11619
movq %rax, %rbp
movl (%r15), %esi
decl %esi
movq %rax, %rdi
callq 0x5c80
movl (%rbp), %eax
decl %eax
movl %eax, 0x4(%rbp)
xorl %eax, %eax
callq 0x75db
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movslq (%r15), %rax
cmpq %rax, %r14
jge 0x11ef0
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rdi
callq 0x5a99
cmpb $0x1, %al
jne 0x11ee8
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x5b79
movq %rax, %r12
movl (%r15), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorl %edx, %edx
cmpq %rcx, %rax
je 0x11ea4
cmpq %rcx, %r14
je 0x11e9f
movq 0x10(%r15), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x10(%rbp), %rdi
movslq %edx, %rdx
movq %rsi, (%rdi,%rdx,8)
movq 0x10(%rbp), %rsi
movq (%rsi,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incl %edx
incq %rcx
jmp 0x11e75
movq %rbp, %rdi
movq %r13, %rsi
callq 0x579f
movq %rax, %rbx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x1860a
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x77ee
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1184e
movq 0x10(%r12), %rdi
movq %r12, %rsi
callq 0x5b2c
movq 0x40(%rsp), %r12
incq %r14
jmp 0x11e30
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x11f47
cmpl $-0x1, (%r14)
je 0x11f3e
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x11307
movq 0x10(%r12), %rcx
movslq (%r14), %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 0x5b2c
incl 0x4(%r12)
jmp 0x11f41
incq %rbx
addq $0x8, %r14
jmp 0x11ef7
movq 0x10(%rsp), %rax
cmpq 0x18(%rax), %rbx
je 0x11fc2
testq %rbx, %rbx
movl $0x0, %ebx
movq 0x20(%rsp), %r14
jne 0x12020
movl (%r15), %eax
testl %eax, %eax
cmovlel %ebx, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x11f84
movq 0x10(%r15), %rdx
movq (%rdx,%rcx,8), %rdx
movl %ecx, 0x18(%rdx)
incq %rcx
jmp 0x11f6f
movl (%rbp), %eax
testl %eax, %eax
cmovlel %ebx, %eax
xorl %ecx, %ecx
movq 0x28(%rsp), %r15
cmpq %rcx, %rax
je 0x11fa6
movq 0x10(%rbp), %rdx
andq $0x0, (%rdx,%rcx,8)
incq %rcx
jmp 0x11f93
movq 0x10(%rsp), %rdi
callq 0x772d
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x1166e
jmp 0x11d9b
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x11307
movq 0x10(%r12), %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 0x5b2c
incl 0x4(%r12)
movq 0x17ffc(%rip), %rax     # 0x29ff8
movq (%rax), %rdi
movl (%r15), %ecx
movl 0x8(%r15), %edx
leaq 0xbbf5(%rip), %rsi      # 0x1dc02
xorl %eax, %eax
callq 0x1150
xorl %ebx, %ebx
movq 0x20(%rsp), %r14
jmp 0x11f65
movq 0x17fd1(%rip), %rax     # 0x29ff8
movq (%rax), %rdi
movl (%r15), %edx
leaq 0xbbf9(%rip), %rsi      # 0x1dc2d
xorl %eax, %eax
callq 0x1150
jmp 0x11f65
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x18dcd
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq