// File: /workspace/github_c_makefile_star2_O1/pwelke[P]GraphMiningTools/localEasySubtreeIsomorphism.c
// Function: getBlockTreeT
struct BlockTree getBlockTreeT(struct Graph* g, struct ShallowGraphPool* sgp) {

	struct ShallowGraph* biconnectedComponents = listBiconnectedComponents(g, sgp);

	for (int v=0; v<g->n; ++v) {
		g->vertices[v]->visited = -1; // isRoot
		g->vertices[v]->d = -1; // parent root
	}

	/* we mark for each component the vertex with the lowest lowPoint.
	 * that is the root of the component.
	 *
	 * Due to the order in which listBiconnectedComponents() returns the bics,
	 * we obtain the right parent roots for the roots in this way. */

	for (struct ShallowGraph* bic=biconnectedComponents; bic!=NULL; bic=bic->next) {

		// listBiconnectedComponents returns bics where the first vertex in the first edge is the root of each bic
		struct Vertex* rootOfComponent = bic->edges->startPoint;

		// mark the root of this component as root.
		rootOfComponent->visited = 1;

		// store the root as information with each vertex and the component
		int rootId = rootOfComponent->number;
		bic->data = rootId;
		for (struct VertexList* e=bic->edges; e!=NULL; e=e->next) {
			e->startPoint->d = rootId;
			e->endPoint->d = rootId;
		}
	}

	// create output struct
	struct BlockTree blockTree = {0,0,0,0,0};
	blockTree.g = g;

	// count number of roots in g, init storage
	for (int v=0; v<g->n; ++v) {
		if (g->vertices[v]->visited == 1) {
			++blockTree.nRoots;
		}
	}
	blockTree.roots = malloc(blockTree.nRoots * sizeof(struct Vertex*));
	blockTree.parents = malloc(blockTree.nRoots * sizeof(struct Vertex*));
	blockTree.vRootedBlocks = malloc(blockTree.nRoots * sizeof(struct ShallowGraph*));

	// select and sort roots by lowpoint. this ensures bottom up traversal of the
	// blocktree if iterating through the array
	for (int v=0, r=0; v<g->n; ++v) {
		if (g->vertices[v]->visited == 1) {
			// set ->visited of each root to the lowpoint of its parent root
			// this way, we can order the roots in one block correctly using lowPointComparator
			g->vertices[v]->visited = g->vertices[g->vertices[v]->d]->lowPoint;
			// if v is its own parent, mark this with a special visited value
			if (g->vertices[g->vertices[v]->d]->number == g->vertices[v]->number) {
				g->vertices[v]->visited = 0;
			}
			blockTree.roots[r] = g->vertices[v];
			++r;
		}
	}
	qsort(blockTree.roots, blockTree.nRoots, sizeof(struct Vertex*), &lowPointComparator);

	// add parents of roots to array (after sorting the above, of course)
	// init vRootedBlocks to NULL
	// set root->visited to its position in roots (so that we can map the bics efficiently)
	for (int v=0; v<blockTree.nRoots; ++v) {
		blockTree.parents[v] = g->vertices[blockTree.roots[v]->d];
		blockTree.vRootedBlocks[v] = NULL;
		blockTree.roots[v]->visited = v;
	}

	// add blocks to respective roots
	for (struct ShallowGraph* bic=popShallowGraph(&biconnectedComponents); bic!=NULL; bic=popShallowGraph(&biconnectedComponents)) {
		int rootPositionInBlockTreeArrays = g->vertices[bic->data]->visited;
		bic->next = blockTree.vRootedBlocks[rootPositionInBlockTreeArrays];
		blockTree.vRootedBlocks[rootPositionInBlockTreeArrays] = bic;
	}

	return blockTree;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
callq 0xb2bf
movq %r14, %r8
movq %rax, %r14
movslq (%r8), %r15
testq %r15, %r15
jle 0xe8a6
movq 0x10(%r8), %rax
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%rax,%rcx,8), %rsi
movl %edx, 0x1c(%rsi)
movl %edx, 0x28(%rsi)
incq %rcx
cmpq %rcx, %r15
jne 0xe894
testq %r14, %r14
je 0xe8e7
movq %r14, %rax
movq (%rax), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, 0x1c(%rcx)
movl 0x18(%rcx), %ecx
movl %ecx, 0x28(%rax)
movq (%rax), %rdx
testq %rdx, %rdx
je 0xe8de
movq 0x10(%rdx), %rsi
movl %ecx, 0x28(%rsi)
movq 0x18(%rdx), %rsi
movl %ecx, 0x28(%rsi)
movq 0x8(%rdx), %rdx
jmp 0xe8c5
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0xe8ae
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movups %xmm0, 0x10(%rbx)
movq $0x0, 0x20(%rbx)
movq %r8, (%rbx)
testl %r15d, %r15d
jle 0xe925
movq 0x10(%r8), %rcx
movl 0x20(%rbx), %eax
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
xorl %edi, %edi
cmpl $0x1, 0x1c(%rsi)
sete %dil
addl %edi, %eax
incq %rdx
cmpq %rdx, %r15
jne 0xe90a
movl %eax, 0x20(%rbx)
movslq 0x20(%rbx), %r13
leaq (,%r13,8), %r12
movq %r12, %rdi
movq %r8, 0x8(%rsp)
callq 0x1190
movq %rax, %rbp
movq %rax, 0x8(%rbx)
movq %r12, %rdi
callq 0x1190
movq %rbx, %rcx
movq %rbx, 0x10(%rsp)
movq %rax, %rbx
movq %rax, 0x10(%rcx)
movq %r12, %rdi
callq 0x1190
movq 0x8(%rsp), %r9
movq %rax, %r12
movq 0x10(%rsp), %rax
movq %r12, 0x18(%rax)
testl %r15d, %r15d
jle 0xe9be
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x10(%r9), %rdi
movq (%rdi,%rcx,8), %rsi
cmpl $0x1, 0x1c(%rsi)
jne 0xe9b6
movslq 0x28(%rsi), %r8
movq (%rdi,%r8,8), %rdi
movl 0x20(%rdi), %r8d
movl %r8d, 0x1c(%rsi)
movl 0x18(%rdi), %edi
cmpl 0x18(%rsi), %edi
cmovel %eax, %r8d
movl %r8d, 0x1c(%rsi)
movslq %edx, %rdx
movq %rsi, (%rbp,%rdx,8)
incl %edx
incq %rcx
cmpq %rcx, %r15
jne 0xe980
leaq 0xac(%rip), %rcx        # 0xea71
movl $0x8, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1080
movq 0x8(%rsp), %rdi
testl %r13d, %r13d
jle 0xea09
movq 0x10(%rdi), %rax
xorl %ecx, %ecx
movq (%rbp,%rcx,8), %rdx
movslq 0x28(%rdx), %rsi
movq (%rax,%rsi,8), %rsi
movq %rsi, (%rbx,%rcx,8)
movq $0x0, (%r12,%rcx,8)
movl %ecx, 0x1c(%rdx)
incq %rcx
cmpq %rcx, %r13
jne 0xe9e5
movq %r14, %r8
testq %r14, %r14
je 0xea1d
movq 0x18(%r14), %r8
movq $0x0, 0x18(%r14)
testq %r14, %r14
movq 0x10(%rsp), %rax
je 0xea62
movq 0x10(%rdi), %rcx
movq %r8, %rdx
movslq 0x28(%r14), %rsi
movq (%rcx,%rsi,8), %rsi
movslq 0x1c(%rsi), %rsi
movq (%r12,%rsi,8), %rdi
movq %rdi, 0x18(%r14)
movq %r14, (%r12,%rsi,8)
testq %r8, %r8
je 0xea57
movq 0x18(%r8), %rdx
movq $0x0, 0x18(%r8)
movq %r8, %r14
testq %r8, %r8
movq %rdx, %r8
jne 0xea2e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq