// File: /workspace/github_c_makefile_star2_O1/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, %r12
movl %esi, %ebx
movq %rdi, %r13
cmpl $0x2, %esi
movl $0x1, %eax
cmovgel %esi, %eax
decl %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x1508b
movq (%r13,%rcx,8), %rdx
movq 0x8(%r13,%rcx,8), %rsi
movl (%rdx), %edx
incq %rcx
cmpl (%rsi), %edx
jge 0x15069
movl %ebx, %edi
movq %r13, %rsi
callq 0x1dda
movq 0x10(%r12), %rdi
callq 0x145b2
movq %rax, %rbp
movl %ebx, %r15d
movq %rbx, (%rsp)
testl %ebx, %ebx
jle 0x150ce
xorl %ebx, %ebx
movq (%r13,%rbx,8), %rdi
incq %rbx
movl %ebx, 0x8(%rdi)
movq %r14, %rsi
callq 0x78fc
movq %rbp, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x1af0f
cmpq %rbx, %r15
jne 0x150a5
movq %r15, 0x10(%rsp)
movq (%rsp), %rbx
leal 0x1(%rbx), %edi
movq %r12, %rsi
callq 0x8565
movq %rax, 0x8(%rsp)
testl %ebx, %ebx
jle 0x15373
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x18(%r12), %rcx
movq %rcx, 0x30(%rsp)
addq $0x4, %rax
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
movq %r12, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq %r13, 0x38(%rsp)
movq %rbp, 0x20(%rsp)
movq (%r13,%rcx,8), %r15
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x40(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %r15, (%rax)
cmpl $0x1, (%r15)
jne 0x1517c
movq 0x18(%r12), %rdi
callq 0x1432b
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %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 0x7cd0
incl 0x4(%rbx)
jmp 0x15332
movq %r12, %rdi
callq 0x147d7
movq %rax, %rbp
movl (%r15), %esi
decl %esi
movq %rax, %rdi
callq 0x7e30
movl (%rbp), %eax
decl %eax
movl %eax, 0x4(%rbp)
xorl %eax, %eax
callq 0x99af
movq %rax, (%rsp)
cmpl $0x0, (%r15)
jle 0x15270
xorl %r14d, %r14d
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rdi
callq 0x7c33
cmpb $0x1, %al
jne 0x15261
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rsi
movq 0x8(%rsi), %rax
movq 0x18(%rax), %rdi
callq 0x7d23
movq %rax, %rbx
movslq (%r15), %rax
testq %rax, %rax
jle 0x1521a
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %r14
je 0x15212
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
cmpq %rcx, %rax
jne 0x151ed
movq %rbp, %rdi
movq 0x48(%rsp), %r13
movq %r13, %rsi
callq 0x78fc
movq %rax, %r12
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x1ae44
movq (%rsp), %rdi
movl %eax, %esi
callq 0x9bf0
movq %r13, %rdi
movq %r12, %rsi
callq 0x14b19
movq 0x10(%rbx), %rdi
movq %rbx, %rsi
callq 0x7cd0
movq 0x50(%rsp), %r12
incq %r14
movslq (%r15), %rax
cmpq %rax, %r14
jl 0x151b4
movq (%rsp), %rax
movq (%rax), %r14
xorl %ebx, %ebx
testq %r14, %r14
je 0x152c5
cmpl $-0x1, (%r14)
je 0x152bc
movq 0x18(%r12), %rdi
callq 0x1432b
movq 0x8(%rsp), %r13
movq 0x10(%r13), %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 0x7cd0
incl 0x4(%r13)
jmp 0x152bf
incq %rbx
movq 0x8(%r14), %r14
jmp 0x15279
movq (%rsp), %rax
cmpq 0x18(%rax), %rbx
je 0x1534a
testq %rbx, %rbx
jne 0x15366
movslq (%r15), %rax
testq %rax, %rax
jle 0x152f5
movq 0x10(%r15), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl %edx, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x152e6
movslq (%rbp), %rax
testq %rax, %rax
jle 0x15314
xorl %ecx, %ecx
movq 0x10(%rbp), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x15300
movq (%rsp), %rdi
callq 0x9b14
movq %r12, %rdi
movq %rbp, %rsi
callq 0x14832
movq 0x38(%rsp), %r13
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
incq %rcx
cmpq %rax, %rcx
jne 0x15126
jmp 0x15373
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
callq 0x1e36
jmp 0x152d8
movq %r15, %rdi
callq 0x1e19
jmp 0x152d8
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1b644
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq