// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/searchTree.c
// Function: mergeSearchTrees
void mergeSearchTrees(struct Vertex* globalTree, struct Vertex* localTree, int divisor, struct compInfo* results, int* pos, struct Vertex* trueRoot, int depth, struct GraphPool* p) {


	/* process current vertex */

	/* if some string ends here, write it to the output array and update data structure */
	if (localTree->visited) {
		if (globalTree->visited == 0) {
			++trueRoot->d;
		}

		/* add current number of elements (divided by divisor) to global number */
		globalTree->visited += localTree->visited / divisor;
		trueRoot->number += localTree->visited / divisor;

		/* if the current string has no global id yet, get the next one */
		if (globalTree->lowPoint == 0) {
			trueRoot->lowPoint++;
			globalTree->lowPoint = trueRoot->lowPoint;
		}

		/* if we have a results array, store the (id, count)-pair in the array */
		if (results) {

			results[*pos].id = globalTree->lowPoint;
			results[*pos].count = localTree->visited / divisor;
			results[*pos].depth = depth;
			*pos += 1;

		}

	}

	/* if the current vertex is no leaf, merge search trees recursively */
	if (localTree->neighborhood) {

		struct VertexList* locNb;

		/* TODO this is the ugliest, most inefficient stuff */

		/* process neighbors */
		for (locNb=localTree->neighborhood; locNb; locNb=locNb->next) {
			struct VertexList* globNb;
			char found = 0;

			for (globNb=globalTree->neighborhood; globNb; globNb=globNb->next) {

				/* if the next label is already in the tree, continue recursively */
				if (strcmp(globNb->label, locNb->label) == 0) {
					mergeSearchTrees(globNb->endPoint, locNb->endPoint, divisor, results, pos, trueRoot, depth+1, p);
					found = 1;
					break;
				}
			}

			if (!found) {

				/* we reach this point, iff locNb->label is not found in the labels of the global neigbors
				 * thus we have to add the edge and the vertex to the globalTree. This copying has to be a real
				 * copy, no shallow, as any label or vertex that the local tree refers to is dumped when
				 * processing of the current vertex is done.
				 */
				globNb = getVertexList(p->listPool);
				globNb->label = copyString(locNb->label);
				globNb->isStringMaster = 1;
				globNb->endPoint = getVertex(p->vertexPool);
				globNb->startPoint = globalTree;

				/* add this edge at the head of globalTree->neighborhood */
				globNb->next = globalTree->neighborhood;
				globalTree->neighborhood = globNb;

				/* recursive call to merge search trees from this point on */
				mergeSearchTrees(globNb->endPoint, locNb->endPoint, divisor, results, pos, trueRoot, depth+1, p);
			}
		}

		/* at this point, any subtrees (i.e. vertices) dangling at the localTree->neighborhood edges are dumped
		 * so dump the vertex list.
		 * TODO think about this. dumping of the search tree can be handled by dumpSearchTree with no
		 *  additional asymptotic expenses. */
	}
}

// Assembly:
subq $0x58, %rsp
movq 0x68(%rsp), %rax
movl 0x60(%rsp), %eax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq 0x48(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x2c774
movq 0x50(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x2c6a2
movq 0x28(%rsp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x48(%rsp), %rax
movl 0x1c(%rax), %eax
cltd
idivl 0x44(%rsp)
movl %eax, %ecx
movq 0x50(%rsp), %rax
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
movq 0x48(%rsp), %rax
movl 0x1c(%rax), %eax
cltd
idivl 0x44(%rsp)
movl %eax, %ecx
movq 0x28(%rsp), %rax
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
movq 0x50(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x2c6ff
movq 0x28(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq 0x28(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x20(%rax)
cmpq $0x0, 0x38(%rsp)
je 0x2c772
movq 0x50(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rdx
movslq (%rdx), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq 0x48(%rsp), %rax
movl 0x1c(%rax), %eax
cltd
idivl 0x44(%rsp)
movl %eax, %ecx
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rdx
movslq (%rdx), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl 0x60(%rsp), %ecx
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rdx
movslq (%rdx), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x2c774
movq 0x48(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2c90f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x2c90d
movb $0x0, 0x17(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x2c82d
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax), %rsi
callq 0x1120
cmpl $0x0, %eax
jne 0x2c81b
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x44(%rsp), %edx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movl 0x60(%rsp), %r10d
addl $0x1, %r10d
movq 0x68(%rsp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2c650
movb $0x1, 0x17(%rsp)
jmp 0x2c82d
jmp 0x2c81d
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x2c7b1
cmpb $0x0, 0x17(%rsp)
jne 0x2c8f8
movq 0x68(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x20090
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x50(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x44(%rsp), %edx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r9
movl 0x60(%rsp), %r10d
addl $0x1, %r10d
movq 0x68(%rsp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2c650
jmp 0x2c8fa
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x2c792
jmp 0x2c90f
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)