// File: /workspace/github_c_makefile_star2_O1/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 0x147d7
movq %rax, %r15
movq %r12, %rdi
callq 0x147d7
movq %rax, %r13
movl (%r14), %esi
movq %r15, %rdi
callq 0x7e30
cmpl $0x0, (%r14)
jle 0x17b63
xorl %ebx, %ebx
movq 0x10(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq 0x10(%r12), %rsi
callq 0x7c08
movq 0x10(%r15), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
movslq (%r14), %rax
cmpq %rax, %rbx
jl 0x17b3e
movq %r13, 0x18(%rsp)
xorl %r14d, %r14d
testq %rbp, %rbp
je 0x17c69
movq %rbp, %r13
movq 0x18(%r13), %rbx
cmpl $0x1, 0x10(%r13)
jne 0x17c25
movq %r14, 0x8(%rsp)
movq %rbp, (%rsp)
movq 0x18(%r12), %rdi
callq 0x1432b
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 0x7cd0
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 0x7bdc
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cd0
incl 0x4(%r15)
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x17c2a
movq %rbx, 0x18(%rax)
movq (%rsp), %rcx
movq %rcx, %rbp
jmp 0x17c37
incl %r14d
jmp 0x17c5d
movl $0x0, %eax
movq %rbx, %rcx
movl $0x0, %ebp
testq %rbx, %rbx
je 0x17c43
movq %rax, 0x20(%rbx)
movq %rcx, %rbp
movq $0x0, 0x18(%r13)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x14b19
movq 0x8(%rsp), %r14
movq %rbx, %r13
testq %rbx, %rbx
jne 0x17b77
movq %rbp, (%rsp)
movq 0x18(%rsp), %r13
movq %r13, %rdi
movl %r14d, %esi
callq 0x7e30
testl %r14d, %r14d
jle 0x17cb4
movl %r14d, %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq 0x10(%r12), %rdi
callq 0x145b2
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 0x17c8d
movslq (%r15), %rax
testq %rax, %rax
movq (%rsp), %rdi
jle 0x17ce0
movq 0x10(%r15), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
cmpq $0x0, 0x8(%rsi)
je 0x17cd8
movl $0xffffffff, 0x1c(%rsi) # imm = 0xFFFFFFFF
incq %rdx
cmpq %rdx, %rax
jne 0x17cc6
movq %r12, 0x8(%rsp)
testq %rdi, %rdi
je 0x17e87
movl $0x1, %eax
movq (%rsp), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x17d5a
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 0x17d26
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl %eax, %r9d
je 0x17d2a
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 0x17d4d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl %eax, %r9d
je 0x17d51
movl %r8d, 0x1c(%rdi)
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
jne 0x17d03
incl %eax
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
jne 0x17cf7
movl $0x1, %ebp
movq (%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rax), %rbx
testq %rbx, %rbx
je 0x17e72
movq 0x10(%r15), %rax
movq 0x10(%rbx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %r14
cmpl $-0x1, 0x1c(%r14)
jne 0x17df4
movl 0x20(%r14), %eax
cmpq %rax, %rbp
je 0x17df4
movl %ebp, 0x20(%r14)
movq 0x10(%r13), %rax
movq -0x8(%rax,%rbp,8), %r13
movq 0x8(%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x1432b
movq %r14, 0x10(%rax)
movq %r13, 0x18(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cd0
movq 0x18(%r12), %rdi
callq 0x1432b
movq %r14, 0x18(%rax)
movq %r13, 0x10(%rax)
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %rax, %rsi
callq 0x7cd0
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 0x17e69
movl 0x20(%r14), %eax
cmpq %rax, %rbp
je 0x17e69
movl %ebp, 0x20(%r14)
movq 0x10(%r13), %rax
movq -0x8(%rax,%rbp,8), %r13
movq 0x8(%rsp), %r12
movq 0x18(%r12), %rdi
callq 0x1432b
movq %r14, 0x10(%rax)
movq %r13, 0x18(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x7cd0
movq 0x18(%r12), %rdi
callq 0x1432b
movq %r14, 0x18(%rax)
movq %r13, 0x10(%rax)
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %rax, %rsi
callq 0x7cd0
incl 0x4(%r13)
movq 0x8(%rbx), %rbx
jmp 0x17d76
incq %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0x17d6e
cmpl $0x0, (%r15)
movq 0x8(%rsp), %r14
movq (%rsp), %r12
jle 0x17edb
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpl $-0x1, 0x1c(%rax)
je 0x17ed0
movq 0x18(%r14), %rdi
movq 0x8(%rax), %rsi
callq 0x143b8
movq 0x10(%r14), %rdi
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rsi
callq 0x14628
movq 0x10(%r15), %rax
movq $0x0, (%rax,%rbx,8)
incq %rbx
movslq (%r15), %rax
cmpq %rax, %rbx
jl 0x17e98
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
movq %r14, %r8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17a92
nop