// File: /workspace/github_c_makefile_star2_O2/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 0x8ccd
movq %rax, %r15
movl (%r14), %r13d
xorl %eax, %eax
testl %r13d, %r13d
cmovlel %eax, %r13d
cmpq %rax, %r13
je 0xbee0
movq 0x10(%r14), %rcx
movq (%rcx,%rax,8), %rcx
orl $-0x1, 0x1c(%rcx)
orl $-0x1, 0x28(%rcx)
incq %rax
jmp 0xbec6
movq %r15, %rax
testq %rax, %rax
je 0xbf21
movq (%rax), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, 0x1c(%rcx)
movl 0x18(%rcx), %ecx
movl %ecx, 0x28(%rax)
movq %rax, %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0xbf1b
movq 0x10(%rdx), %rsi
movl %ecx, 0x28(%rsi)
movq 0x18(%rdx), %rsi
movl %ecx, 0x28(%rsi)
addq $0x8, %rdx
jmp 0xbeff
movq 0x18(%rax), %rax
jmp 0xbee3
andq $0x0, 0x20(%rbx)
movq %r14, (%rbx)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %r13
je 0xbf4b
movq 0x10(%r14), %rdx
movq (%rdx,%rax,8), %rdx
xorl %esi, %esi
cmpl $0x1, 0x1c(%rdx)
sete %sil
addl %esi, %ecx
incq %rax
jmp 0xbf2d
movl %ecx, 0x20(%rbx)
movl %ecx, %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %r12
movq %r12, %rdi
callq 0x1180
movq %rax, %rbp
movq %rax, 0x8(%rbx)
movq %r12, %rdi
callq 0x1180
movq %rbx, %rcx
movq %rbx, 0x8(%rsp)
movq %rax, %rbx
movq %rax, 0x10(%rcx)
movq %r12, %rdi
callq 0x1180
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %r12, 0x18(%rax)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %r13
je 0xbfd7
movq 0x10(%r14), %rsi
movq (%rsi,%rax,8), %rdx
cmpl $0x1, 0x1c(%rdx)
jne 0xbfd2
movslq 0x28(%rdx), %rdi
movq (%rsi,%rdi,8), %rdi
movl 0x18(%rdi), %r8d
xorl %esi, %esi
cmpl 0x18(%rdx), %r8d
je 0xbfc5
movl 0x20(%rdi), %esi
movl %esi, 0x1c(%rdx)
movslq %ecx, %rcx
movq %rdx, (%rbp,%rcx,8)
incl %ecx
incq %rax
jmp 0xbf9b
leaq 0x9f(%rip), %rcx        # 0xc07d
pushq $0x8
popq %rdx
movq %rbp, %rdi
movq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0x1080
xorl %eax, %eax
cmpq %rax, %r13
je 0xc01a
movq 0x10(%r14), %rcx
movq (%rbp,%rax,8), %rdx
movslq 0x28(%rdx), %rsi
movq (%rcx,%rsi,8), %rcx
andq $0x0, (%r12,%rax,8)
movq %rcx, (%rbx,%rax,8)
movl %eax, 0x1c(%rdx)
incq %rax
jmp 0xbff3
testq %r15, %r15
je 0xc026
movq 0x8(%rsp), %rax
jmp 0xc02f
xorl %edx, %edx
movq 0x8(%rsp), %rax
jmp 0xc038
movq 0x18(%r15), %rdx
andq $0x0, 0x18(%r15)
movq %r15, %rcx
testq %rcx, %rcx
je 0xc06e
movq %rdx, %r15
movq 0x10(%r14), %rsi
movslq 0x28(%rcx), %rdx
movq (%rsi,%rdx,8), %rdx
movslq 0x1c(%rdx), %rsi
movq (%r12,%rsi,8), %rdx
movq %rdx, 0x18(%rcx)
movq %rcx, (%r12,%rsi,8)
movl $0x0, %edx
movq %r15, %rcx
testq %r15, %r15
je 0xc03b
jmp 0xc02f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq