// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/outerplanar.c
// Function: createBlockAndBridgeTree
struct BBTree* createBlockAndBridgeTree(struct ShallowGraph* list, struct Graph *original, 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);
	}

	/* check for outerplanarity of all blocks */
	for (idx=list, i=0; idx; idx=idx->next, ++i) {
		struct ShallowGraph* cString = canonicalStringOfOuterplanarGraph(idx, sgp, gp);
		/* if the current component is not outerplanar,
		 * dump stuff and return NULL
		 * TODO */
		if (cString) {
			blocks->vertices[i]->label = canonicalStringToChar(cString);
			blocks->vertices[i]->isStringMaster = 1;
			dumpShallowGraph(sgp, cString);
		} else {

			/* garbage collection */
			dumpGraph(gp, blocks);
			dumpGraph(gp, bbTree);
			dumpShallowGraphCycle(sgp, list);

			return NULL;
		}
	}

	/* add edges connecting blocks and contained vertices */
	for (idx=list, i=0; idx; idx=idx->next, ++i) {
		struct VertexList* e;
		for (e=idx->edges; e; e=e->next) {

			/* edge  (startPoint, block) if it isn't already there.
			 *
			 * Reason: Each Vertex in a block occurs at least twice below (as
			 * it is on at least one cycle), but we want just one edge connecting
			 * it to the block vertex
			 *
			 * The edge isnt already there, if there is no edge at all OR the endpoint
			 * of the previous edge is the block vertex of the current block */
			if ((bbTree->vertices[e->startPoint->number]->neighborhood == NULL)
					|| (bbTree->vertices[e->startPoint->number]->neighborhood->endPoint != blocks->vertices[i])) {

				struct VertexList* f = getContainmentEdge(gp->listPool);
				f->startPoint = bbTree->vertices[e->startPoint->number];
				f->endPoint = blocks->vertices[i];
				addEdge(bbTree->vertices[e->startPoint->number], f);
				/* addEdge(blocks->vertices[i], inverseEdge(f, gp->listPool));
				 * ... is not done as there is the possibility that we have to remove
				 * the vertex startPoint if it is contained in only one block and no bridge */
			}


			/* edge (endPoint, block) if ...*/
			if ((bbTree->vertices[e->endPoint->number]->neighborhood == NULL)
					|| (bbTree->vertices[e->endPoint->number]->neighborhood->endPoint != blocks->vertices[i])) {
				struct VertexList* f = getContainmentEdge(gp->listPool);
				f->startPoint = bbTree->vertices[e->endPoint->number];
				f->endPoint = blocks->vertices[i];
				addEdge(bbTree->vertices[e->endPoint->number], f);
				/* addEdge(blocks->vertices[i], inverseEdge(f, gp->listPool));
				 * as above	*/
			}

		}
	}

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

		if (bbTree->vertices[i]->neighborhood) {
			int firstNo = bbTree->vertices[i]->neighborhood->endPoint->number;

			/* if vertex belongs to just one comp but this is a bridge, keep the vertex */
			if (firstNo >= 0) {
				continue;
			}

			/* if vertex belongs to more than one comp keep it */
			for (e=bbTree->vertices[i]->neighborhood; e; e=e->next) {
				if (e->endPoint->number != firstNo) {
					removeVertex = 0;
					break;
				}
			}
		} else {
			/* this part only occurs, if there are isolated vertices in original.
			 * However, by definition an outerplanar graph does not have to be connected
			 * so we keep the vertex and obtain a block and bridge forest
			 */
			removeVertex = 0;
		}


		/* 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 */
		if (removeVertex) {
			struct VertexList* f;
			struct VertexList* tmp2;
			for (f=bbTree->vertices[i]->neighborhood; f; f=tmp2) {
				tmp2 = f->next;
				dumpVertexList(gp->listPool, f);
			}
			dumpVertex(gp->vertexPool, bbTree->vertices[i]);
			bbTree->vertices[i] = NULL;
		}
	}

	/* add reverse edges of the edges connecting a vertex in tree to a block */
	for (i=0; i<bbTree->n; ++i) {
		if (bbTree->vertices[i]) {
			struct VertexList* e;
			for (e=bbTree->vertices[i]->neighborhood; e; e=e->next) {
				if (e->endPoint->number < 0) {
					addEdge(e->endPoint, inverseEdge(e, gp->listPool));
				}
			}
		}
	}

	return createBBTree(bbTree, blocks, list, NULL, gp);
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movq 0x98(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x78(%rsp)
movq 0x98(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movq 0x78(%rsp), %rdi
movq 0xa0(%rsp), %rax
movl (%rax), %esi
callq 0xaa00
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movq 0xa0(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x24f77
movq 0xa0(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa3f0
movq %rax, %rdx
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x24f1f
movq 0xa8(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x2517c
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x2515a
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1f310
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x88(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq 0x60(%rsp), %rax
movq %rcx, (%rax)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x60(%rsp), %rsi
callq 0xa660
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rdi
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xa370
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0xa660
movq 0x78(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq 0x88(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x25106
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %rax
movq 0x20(%rax), %rax
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x80(%rsp)
je 0x25104
movq 0x88(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x20(%rax)
jmp 0x25133
movq 0x80(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0x80(%rsp)
je 0x25131
movq 0x80(%rsp), %rax
movq $0x0, 0x20(%rax)
jmp 0x25133
movq 0x88(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x1ff70
jmp 0x25165
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x25167
movq 0x80(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x24f87
movq 0x70(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0xaa00
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x251ef
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, %rdx
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x68(%rsp), %eax
addl $0x1, %eax
xorl %ecx, %ecx
subl %eax, %ecx
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x18(%rax)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x25192
movq 0xa8(%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x68(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x252ff
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
callq 0x8ee0
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x2528f
movq 0x58(%rsp), %rdi
callq 0x9040
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x24(%rax)
movq 0x90(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1ff70
jmp 0x252d9
movq 0x98(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x1fb30
movq 0x98(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1fb30
movq 0x90(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x20000
movq $0x0, 0xb0(%rsp)
jmp 0x2575f
jmp 0x252db
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x88(%rsp)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x25207
movq 0xa8(%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x68(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x2551b
movq 0x88(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
je 0x254f5
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x8(%rax)
je 0x25399
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq 0x70(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x68(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x25411
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x24e50
movq %rax, 0x48(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x48(%rsp), %rsi
callq 0xa660
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x8(%rax)
je 0x25468
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq 0x70(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x68(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
je 0x254e0
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x24e50
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x40(%rsp), %rsi
callq 0xa660
jmp 0x254e2
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x25336
jmp 0x254f7
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x88(%rsp)
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x25317
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movq 0x78(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x2567d
movb $0x1, 0x37(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x8(%rax)
je 0x255cf
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
jl 0x2557f
jmp 0x2566d
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
je 0x255cd
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %eax
cmpl 0x30(%rsp), %eax
je 0x255bb
movb $0x0, 0x37(%rsp)
jmp 0x255cd
jmp 0x255bd
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x2559a
jmp 0x255d4
movb $0x0, 0x37(%rsp)
cmpb $0x0, 0x37(%rsp)
je 0x2566b
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x25632
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x1f410
movq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x255fa
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1f810
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x2566d
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x25523
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movq 0x78(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x25734
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x25722
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x68(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x25720
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x18(%rax)
jge 0x2570e
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xa370
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xa660
jmp 0x25710
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x256c6
jmp 0x25722
jmp 0x25724
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x25685
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq 0x98(%rsp), %r8
xorl %eax, %eax
movl %eax, %ecx
callq 0x24c20
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
addq $0xb8, %rsp
retq
nop