// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl 0x4c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x209a9
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movq 0x50(%rsp), %rcx
movl 0x34(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl (%rcx), %eax
jge 0x2099a
movq 0x1d68c(%rip), %rax     # 0x3dff8
movq (%rax), %rdi
leaq 0x15258(%rip), %rsi     # 0x35bce
movb $0x0, %al
callq 0x1140
movq 0x50(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
movl $0x8, %edx
leaq 0x13d(%rip), %rcx       # 0x20ad0
callq 0x1060
jmp 0x209a9
jmp 0x2099c
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x2092f
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x20a29
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movq 0x50(%rsp), %rax
movslq 0x24(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x8(%rax)
movq 0x50(%rsp), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x38(%rsp), %rsi
callq 0x9eb0
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
callq 0x2c520
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x209c4
movl 0x4c(%rsp), %edi
addl $0x1, %edi
movq 0x40(%rsp), %rsi
callq 0xb850
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x20aab
movq 0x50(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq (%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl 0xc(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq (%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
callq 0x20b10
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x20a47
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x2d3c0
movq 0x10(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)