// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/outerplanar.c
// Function: createFancyBlockAndBridgeTree
struct BBTree* createFancyBlockAndBridgeTree(struct ShallowGraph* list, struct Graph *original, int** originalIDs, struct GraphPool* gp, struct ShallowGraphPool *sgp) {
	struct ShallowGraph* idx;
	struct ShallowGraph* tmp;
	struct Graph* bbTree = getGraph(gp);
	struct Graph* blocks = getGraph(gp);
	int blockNo = 0;
	int i;

	/* copy V(original) */
	setVertexNumber(bbTree, original->n);
	for (i=0; i<original->n; ++i) {
		bbTree->vertices[i] = shallowCopyVertex(original->vertices[i], gp->vertexPool);
	}

	/* copy all bridges to the new graph and delete them from list;
	 * count the number of blocks */
	for (idx=list; idx; idx=tmp) {

		tmp = idx->next;
		if (idx->m == 1) {
			struct VertexList* e = getVertexList(gp->listPool);

			/* add the edge to the bbTree */
			e->startPoint = bbTree->vertices[idx->edges->startPoint->number];
			e->endPoint = bbTree->vertices[idx->edges->endPoint->number];
			e->label = idx->edges->label;

			addEdge(bbTree->vertices[idx->edges->startPoint->number], e);
			addEdge(bbTree->vertices[idx->edges->endPoint->number], inverseEdge(e, gp->listPool));

			++bbTree->m;

			/* cut idx out of list */
			if (idx->prev) {
				idx->prev->next = tmp;
				if (tmp) {
					tmp->prev = idx->prev;
				}
			} else {
				list = tmp;
				if (tmp) {
					tmp->prev = NULL;
				}
			}

			/* dump idx */
			idx->next = NULL;
			dumpShallowGraph(sgp, idx);
		} else {
			/* we have found a block */
			++blockNo;
		}
	}

	/* add blocks */
	setVertexNumber(blocks, blockNo);
	for (i=0; i<blockNo; ++i) {
		blocks->vertices[i] = getVertex(gp->vertexPool);
		blocks->vertices[i]->number = - (i + 1);
	}

	for (i=0; i<bbTree->n; ++i) {
		if (bbTree->vertices[i]->neighborhood) {
			bbTree->vertices[i]->visited = -1;
		}
	}

	/* mark vertices that are in the block and bridge tree */
	i = 1; // component marker
	for (struct ShallowGraph* comp=list; comp!=NULL; comp=comp->next) {
		for (struct VertexList* e=comp->edges; e!=NULL; e=e->next) {
			struct Vertex* v = bbTree->vertices[e->startPoint->number];
			if (v->visited == 0) {
				v->visited = i;
			} else if (v->visited != i) {
				v->visited = -1;
			}
			v = bbTree->vertices[e->endPoint->number];
			if (v->visited == 0) {
				v->visited = i;
			} else if (v->visited != i) {
				v->visited = -1;
			}
		}
		++i;
	}

	/* add edges from block vertices to articulation vertices */
	i = 1; // component marker
	for (struct ShallowGraph* comp=list; comp!=NULL; comp=comp->next) {
		for (struct VertexList* e=comp->edges; e!=NULL; e=e->next) {
			struct Vertex* v = bbTree->vertices[e->startPoint->number];
			if ((v->visited == -1) && (v->lowPoint != i)) {
				v->lowPoint = i;
				struct Vertex* w = blocks->vertices[i-1];
				struct VertexList* f = getVertexList(gp->listPool);
				f->startPoint = v;
				f->endPoint = w;
				addEdge(v, f);
				f = getVertexList(gp->listPool);
				f->endPoint = v;
				f->startPoint = w;
				addEdge(w, f);
				++blocks->m;
			}
			v = bbTree->vertices[e->endPoint->number];
			if ((v->visited == -1) && (v->lowPoint != i)) {
				v->lowPoint = i;
				struct Vertex* w = blocks->vertices[i-1];
				struct VertexList* f = getVertexList(gp->listPool);
				f->startPoint = v;
				f->endPoint = w;
				addEdge(v, f);
				f = getVertexList(gp->listPool);
				f->endPoint = v;
				f->startPoint = w;
				addEdge(w, f);
				++blocks->m;
			}
		}
		++i;
	}

	/* remove vertices that do not belong to more than one biconnected component
	 * runtime O(n+m) */
	for (i=0; i<bbTree->n; ++i) {

		if (bbTree->vertices[i]->visited != -1) {
			/* check if to remove the vertex. if so, dump vertex and all edges dangling at it.
			* The corresponding entry in bbTree->vertices will be NULL */
			dumpVertexListRecursively(gp->listPool, bbTree->vertices[i]->neighborhood);
			dumpVertex(gp->vertexPool, bbTree->vertices[i]);
			bbTree->vertices[i] = NULL;
		}
	}

	return compressedBBTree(bbTree, blocks, list, originalIDs, gp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbp
movq %rcx, %rdi
callq 0x146a9
movq %rax, %r15
movq %r12, %rdi
callq 0x146a9
movq %rax, %r13
movl (%r14), %esi
movq %r15, %rdi
callq 0x7e6c
cmpl $0x0, (%r14)
jle 0x17a25
xorl %ebx, %ebx
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq 0x10(%r12), %rsi
callq 0x7c34
movq 0x10(%r15), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
movslq (%r14), %rax
cmpq %rax, %rbx
jl 0x17a00
testq %rbp, %rbp
movq %r13, 0x18(%rsp)
je 0x17b7c
xorl %r14d, %r14d
movq %rbp, %r13
movq 0x18(%r13), %rbx
cmpl $0x1, 0x10(%r13)
jne 0x17ae7
movq %r14, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0x18(%r12), %rdi
callq 0x141f1
movq %rax, %rbp
movq 0x10(%r15), %rax
movq (%r13), %rcx
movq 0x10(%rcx), %rdx
movslq 0x18(%rdx), %rdx
movq (%rax,%rdx,8), %rdx
movq %rdx, 0x10(%rbp)
movq 0x18(%rcx), %rdx
movslq 0x18(%rdx), %rdx
movq (%rax,%rdx,8), %rdx
movq %rdx, 0x18(%rbp)
movq (%rcx), %rdx
movq %rdx, (%rbp)
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq %rbp, %rsi
callq 0x7cfe
movq 0x10(%r15), %rax
movq (%r13), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %r14
movq 0x18(%r12), %rsi
movq %rbp, %rdi
callq 0x7c08
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cfe
incl 0x4(%r15)
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x17aec
movq %rbx, 0x18(%rax)
movq (%rsp), %rcx
movq %rcx, %rbp
jmp 0x17af9
incl %r14d
jmp 0x17b1f
movl $0x0, %eax
movq %rbx, %rcx
movl $0x0, %ebp
testq %rbx, %rbx
je 0x17b05
movq %rax, 0x20(%rbx)
movq %rcx, %rbp
movq $0x0, 0x18(%r13)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x149f4
movq 0x8(%rsp), %r14
movq %rbx, %r13
testq %rbx, %rbx
jne 0x17a39
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r14d, %esi
callq 0x7e6c
testl %r14d, %r14d
jle 0x17b88
movq %rbp, (%rsp)
movl %r14d, %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq 0x10(%r12), %rdi
callq 0x1447e
movq 0x10(%r13), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x10(%r13), %rax
movq (%rax,%r14,8), %rax
incq %r14
movl %ebp, 0x18(%rax)
decl %ebp
cmpq %r14, %rbx
jne 0x17b4f
movq (%rsp), %rbp
jmp 0x17b88
xorl %ebp, %ebp
movq %r13, %rdi
xorl %esi, %esi
callq 0x7e6c
movslq (%r15), %rax
testq %rax, %rax
jle 0x17bb0
movq 0x10(%r15), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
cmpq $0x0, 0x8(%rsi)
je 0x17ba8
movl $0xffffffff, 0x1c(%rsi) # imm = 0xFFFFFFFF
incq %rdx
cmpq %rdx, %rax
jne 0x17b96
testq %rbp, %rbp
je 0x17d64
movq %r12, 0x8(%rsp)
movl $0x1, %eax
movq %rbp, (%rsp)
movq (%rbp), %rdx
testq %rdx, %rdx
je 0x17c2b
movq 0x10(%r15), %rsi
movq 0x10(%rdx), %rdi
movslq 0x18(%rdi), %rdi
movq (%rsi,%rdi,8), %rdi
movl 0x1c(%rdi), %r9d
movl %eax, %r8d
testl %r9d, %r9d
je 0x17bf7
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl %eax, %r9d
je 0x17bfb
movl %r8d, 0x1c(%rdi)
movq 0x18(%rdx), %rdi
movslq 0x18(%rdi), %rdi
movq (%rsi,%rdi,8), %rdi
movl 0x1c(%rdi), %r9d
movl %eax, %r8d
testl %r9d, %r9d
je 0x17c1e
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl %eax, %r9d
je 0x17c22
movl %r8d, 0x1c(%rdi)
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
jne 0x17bd4
incl %eax
movq 0x18(%rbp), %rbp
testq %rbp, %rbp
jne 0x17bc7
movl $0x1, %ebp
movq (%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rax), %rbx
testq %rbx, %rbx
je 0x17d43
movq 0x10(%r15), %rax
movq 0x10(%rbx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %r14
cmpl $-0x1, 0x1c(%r14)
jne 0x17cc9
movl 0x20(%r14), %ecx
cmpq %rcx, %rbp
je 0x17cc9
movl %ebp, 0x20(%r14)
movq 0x10(%r13), %rax
movq -0x8(%rax,%rbp,8), %r13
movq 0x8(%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x141f1
movq %r14, 0x10(%rax)
movq %r13, 0x18(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cfe
movq 0x18(%r12), %rdi
callq 0x141f1
movq %r14, 0x18(%rax)
movq %r13, 0x10(%rax)
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %rax, %rsi
callq 0x7cfe
incl 0x4(%r13)
movq 0x10(%r15), %rax
movq 0x18(%rbx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %r14
cmpl $-0x1, 0x1c(%r14)
jne 0x17d3a
movl 0x20(%r14), %eax
cmpq %rax, %rbp
je 0x17d3a
movl %ebp, 0x20(%r14)
movq 0x10(%r13), %rax
movq -0x8(%rax,%rbp,8), %r13
movq 0x8(%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x141f1
movq %r14, 0x10(%rax)
movq %r13, 0x18(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cfe
movq 0x18(%r12), %rdi
callq 0x141f1
movq %r14, 0x18(%rax)
movq %r13, 0x10(%rax)
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %rax, %rsi
callq 0x7cfe
incl 0x4(%r13)
movq 0x8(%rbx), %rbx
jmp 0x17c47
incq %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0x17c3f
movl (%r15), %eax
movq 0x8(%rsp), %r12
movq (%rsp), %rbp
testl %eax, %eax
jle 0x17db2
xorl %ebx, %ebx
movq 0x10(%r15), %rcx
movq (%rcx,%rbx,8), %rcx
cmpl $-0x1, 0x1c(%rcx)
je 0x17da7
movq 0x18(%r12), %rdi
movq 0x8(%rcx), %rsi
callq 0x1427a
movq 0x10(%r12), %rdi
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rsi
callq 0x144f0
movq 0x10(%r15), %rax
movq $0x0, (%rax,%rbx,8)
movl (%r15), %eax
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x17d6a
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq %r12, %r8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17954
nop