// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/listComponents.c
// Function: partitionIntoForestAndCycles
struct Graph* partitionIntoForestAndCycles(struct ShallowGraph* list, struct Graph *original, struct GraphPool* gp, struct ShallowGraphPool *sgp) {

	struct Graph *forest = getGraph(gp);
	struct Graph *cycles = NULL;
	int i;
	int componentNumber = 0;

	/* create create empty forest with same vertex set as original */
	if (!(setVertexNumber(forest, original->n))) {
		printf("Error allocating vertex arrays for forest or cycles in graph %i\n", original->number);
		dumpGraph(gp, forest);
		dumpGraph(gp, cycles);
		return NULL;
	}

	for (i=0; i<original->n; ++i) {
		forest->vertices[i] = shallowCopyVertex(original->vertices[i], gp->vertexPool);
	}


	while (1) {
		if (list->m == 1) {
			/* add the edge contained in this graph to the forest */
			struct VertexList* rev;

			/* update start and endPoint to the new copies of these vertices */
			list->edges->startPoint = forest->vertices[list->edges->startPoint->number];
			list->edges->endPoint = forest->vertices[list->edges->endPoint->number];

			/* add edge to incidence list of its new startpoint */
			addEdge(list->edges->startPoint, list->edges);

			/* clone edge and reverse it */
			rev = shallowCopyEdge(list->edges, gp->listPool);
			rev->startPoint = list->edges->endPoint;
			rev->endPoint = list->edges->startPoint;
			addEdge(rev->startPoint, rev);

			/* pop edge */
			list->edges = NULL;

			/* update edge count of forest */
			forest->m += 1;

		} else {
			struct Graph* newCycle = getGraph(gp);

			/* TODO bad thing: o(n) for each biconnected component */
			setVertexNumber(newCycle, original->n);

			/* append the graph to the list of cycle unions, encode the biconnected component
			 * some edge belongs to in ->used */
			while (list->edges) {
				struct VertexList *rev; 
				struct VertexList *curr = list->edges;

				/* add vertices on the fly */
				if(newCycle->vertices[curr->startPoint->number] == NULL) {
					newCycle->vertices[curr->startPoint->number] = shallowCopyVertex(curr->startPoint, gp->vertexPool);
				}
				if(newCycle->vertices[curr->endPoint->number] == NULL) {
					newCycle->vertices[curr->endPoint->number] = shallowCopyVertex(curr->endPoint, gp->vertexPool);
				}

				/* update start and endPoint to the new copies of these vertices */
				curr->startPoint = newCycle->vertices[list->edges->startPoint->number];
				curr->endPoint = newCycle->vertices[list->edges->endPoint->number];

				/* pop curr (has to be done before appending it to its new list) */
				list->edges = curr->next;

				/* set indicator of biconnected component */
				curr->used = componentNumber;

				/* add edge to incidence list of its new startpoint */
				addEdge(curr->startPoint, curr);

				/* clone edge and reverse it */
				rev = shallowCopyEdge(curr, gp->listPool);
				rev->startPoint = curr->endPoint;
				rev->endPoint = curr->startPoint;
				addEdge(rev->startPoint, rev);

				/* update edge count of cycles */
				newCycle->m += 1;
			}
			++componentNumber;

			/* add the new cyclic component to the list of biconnected components */
			newCycle->next = cycles;
			cycles = newCycle;

		}

		/* breaking condition and iteration of list pointer, dumping of sucked out ShallowGraphs */
		if (list->next) {
			list = list->next;
			dumpShallowGraph(sgp, list->prev);
		} else {
			/* if there is no next element, the current element has to be dumped and the loop has to end */
			dumpShallowGraph(sgp, list);
			break;
		}
	}

	/* it may happen, that cycles == NULL, if the input graph is a forest, nevertheless
	 * forest != NULL in any case */
	forest->next = cycles;
	return forest;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, 0x28(%rsp)
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rax
movl (%rax), %esi
callq 0xaa00
cmpq $0x0, %rax
jne 0x10dc1
movq 0x50(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0x246f9(%rip), %rdi     # 0x35487
movb $0x0, %al
callq 0x1090
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1fb30
movq $0x0, 0x60(%rsp)
jmp 0x11147
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x10e18
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa3f0
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x10dc9
jmp 0x10e1a
movq 0x58(%rsp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x10f0b
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rdi
movq 0x58(%rsp), %rax
movq (%rax), %rsi
callq 0xa660
movq 0x58(%rsp), %rax
movq (%rax), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xa310
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0xa660
movq 0x58(%rsp), %rax
movq $0x0, (%rax)
movq 0x38(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x110ea
movq 0x48(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq 0x50(%rsp), %rax
movl (%rax), %esi
callq 0xaa00
movq 0x58(%rsp), %rax
cmpq $0x0, (%rax)
je 0x110c7
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x10f98
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa3f0
movq %rax, %rdx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x10fe9
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa3f0
movq %rax, %rdx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
movl 0x28(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0xa660
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xa310
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rsp), %rsi
callq 0xa660
movq 0x18(%rsp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x10f2b
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x11119
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rsi
callq 0x1ff70
jmp 0x1112a
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1ff70
jmp 0x1112f
jmp 0x10e1a
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x38(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)