// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/cs_Outerplanar.c
// Function: _permutateBlock
struct ShallowGraph* __permutateBlock(struct ShallowGraph* cycle, struct ShallowGraphPool* sgp) {
	struct VertexList* start = cycle->edges;
	struct VertexList* end = assertLastPointer(cycle);
	/* best points to the edge before the starting edge of the lex smallest cycle */
	struct VertexList* best = cycle->edges;
	int bestOffset = 2;
	/* return */
	struct ShallowGraph* cString;
	struct ShallowGraph* secondPart = getShallowGraph(sgp);
	/* indices */
	struct VertexList* idx;
	int i;

	/* make actual cycle */
	end->next = start;

	/* give each vertex a number according to its position in cycle */
	for (idx=start->next, i=1; idx!=start; idx=idx->next, ++i) {
		idx->startPoint->d = i;
	}
	start->endPoint->d = 0;

	/* offset=3 as in the first step the permutation starting at edge after the second vertex
	 * in cycle is compared to the permutation starting after the first */
	for (idx = start->next, i=3; idx != start; idx=idx->next, i=(i+1)%(cycle->m + 1)) {
		best = __compareBlockRepresentations(best, idx, cycle->m, bestOffset, i);
		if (best == idx) {
			bestOffset = i;
		}
	}

	/* turn cycle s.t. the shallow graph is lex. smallest */
	cycle->edges = best->next;
	cycle->lastEdge = best;
	best->next = NULL;

	/* compute canonical string of the component */
	for (idx=cycle->edges; idx; idx=idx->next) {
		struct VertexList* e;

		int neighbors = 0;

		struct VertexList** narray1;

		/* count number of diagonals that go from the current vertex to a vertex with a higher
		 * index wrt the current permutation */
		for (e=idx->endPoint->neighborhood; e; e=e->next) {
			if (mod(e->startPoint->d - bestOffset, cycle->m + 1) < mod(e->endPoint->d - bestOffset, cycle->m + 1)) {
				++neighbors;
			}
		}

		/* special cases where current vertices have no or just one incident diagonal */
		if (neighbors == 0) {
			continue; /* the idx loop */
		}

		if (neighbors == 1) {
			/* add edge representation to secondPart. There may be more than one incident diagonals, but just one that
			 * satisfies startpoint < endpoint. This is the edge we are searching. */
			for (e=idx->endPoint->neighborhood; e; e=e->next) {
				if (mod(e->startPoint->d - bestOffset, cycle->m + 1) < mod(e->endPoint->d - bestOffset, cycle->m + 1)) {
					__appendDiagonal(secondPart,
							mod(e->startPoint->d - bestOffset, cycle->m + 1),
							mod(e->endPoint->d - bestOffset, cycle->m + 1),
							e->label,
							sgp->listPool);

					break; /* inner for, there is just one edge */
				}
			}
			continue; /* the idx loop */
		}

		/* otherwise: sort the edges according to their cycle indices modulo the permutation */
		narray1 = malloc(neighbors * sizeof(struct VertexList*));

		for (i=0, e=idx->endPoint->neighborhood; i<neighbors; e=e->next) {
			e->flag = mod(e->startPoint->d - bestOffset, cycle->m + 1);
			e->used = mod(e->endPoint->d - bestOffset, cycle->m + 1);
			if (e->flag < e->used) {
				narray1[i] = e;
				++i;
			}
		}

		qsort(narray1, neighbors, sizeof(struct VertexList*), __compareDiagonals);

		/* append string representation of diagonal */
		for (i=0; i<neighbors; ++i) {
			__appendDiagonal(secondPart, narray1[i]->flag, narray1[i]->used, narray1[i]->label, sgp->listPool);
		}

		/* garbage collection */
		free(narray1);
	}


	cString = canonicalStringOfCycle(cycle, sgp);

	//debug
	printCanonicalString(cString, stdout);
	printCanonicalString(secondPart, stdout);

	cString->lastEdge->next = secondPart->edges;
	cString->lastEdge = secondPart->lastEdge;
	cString->m = cString->m + secondPart->m;
	pushEdge(cString, getInitialisatorEdge(sgp->listPool));
	appendEdge(cString, getTerminatorEdge(sgp->listPool));

	//debug
	fprintf(stdout, "something\n");
	printCanonicalString(cString, stdout);

	/* garbage collection */
	secondPart->edges = NULL;
	dumpShallowGraph(sgp, secondPart);

	return cString;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x90(%rsp), %rdi
callq 0xc000
movq %rax, 0x78(%rsp)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movl $0x2, 0x6c(%rsp)
movq 0x88(%rsp), %rdi
callq 0x1fe70
movq %rax, 0x58(%rsp)
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movl $0x1, 0x4c(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x80(%rsp), %rax
je 0x748a
movl 0x4c(%rsp), %ecx
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x28(%rax)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x7450
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x0, 0x28(%rax)
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movl $0x3, 0x4c(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x80(%rsp), %rax
je 0x752f
movq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %edx
movl 0x6c(%rsp), %ecx
movl 0x4c(%rsp), %r8d
callq 0x6b60
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x7501
movl 0x4c(%rsp), %eax
movl %eax, 0x6c(%rsp)
jmp 0x7503
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movq 0x90(%rsp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
movl %edx, 0x4c(%rsp)
jmp 0x74b6
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x90(%rsp), %rax
movq %rcx, (%rax)
movq 0x70(%rsp), %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x70(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
je 0x78a7
movl $0x0, 0x3c(%rsp)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x7610
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, 0x2c(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x75fe
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x7600
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x7597
cmpl $0x0, 0x3c(%rsp)
jne 0x761c
jmp 0x7894
cmpl $0x1, 0x3c(%rsp)
jne 0x772d
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x7728
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, 0x28(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, %ecx
movl 0x28(%rsp), %eax
cmpl %ecx, %eax
jge 0x7713
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, 0x24(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %esi
movl %eax, %edx
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %r8
callq 0x7250
jmp 0x7728
jmp 0x7715
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x7639
jmp 0x7894
movslq 0x3c(%rsp), %rdi
shlq $0x3, %rdi
callq 0x1170
movq %rax, 0x30(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x7807
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x24(%rax)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x28(%rax), %edi
subl 0x6c(%rsp), %edi
movq 0x90(%rsp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0xda70
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x40(%rsp), %rax
movl 0x24(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x77f2
movq 0x40(%rsp), %rdx
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x77f4
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x775a
movq 0x30(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
movl $0x8, %edx
leaq -0xd2d(%rip), %rcx      # 0x6af0
callq 0x1060
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x788a
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x24(%rax), %esi
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x20(%rax), %edx
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rcx
movq 0x88(%rsp), %rax
movq 0x10(%rax), %r8
callq 0x7250
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x782a
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x7571
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x6900
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0x366fb(%rip), %rax     # 0x3dfc8
movq (%rax), %rsi
callq 0x9130
movq 0x58(%rsp), %rdi
movq 0x366e7(%rip), %rax     # 0x3dfc8
movq (%rax), %rsi
callq 0x9130
movq 0x58(%rsp), %rax
movq (%rax), %rcx
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x60(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x58(%rsp), %rax
addl 0x10(%rax), %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x9000
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xb610
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x8fc0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0xbf70
movq 0x36649(%rip), %rax     # 0x3dfc8
movq (%rax), %rdi
leaq 0x2d7b4(%rip), %rsi     # 0x3513d
movb $0x0, %al
callq 0x1140
movq 0x60(%rsp), %rdi
movq 0x3662c(%rip), %rax     # 0x3dfc8
movq (%rax), %rsi
callq 0x9130
movq 0x58(%rsp), %rax
movq $0x0, (%rax)
movq 0x88(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1ff70
movq 0x60(%rsp), %rax
addq $0x98, %rsp
retq
nop