// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/cs_Outerplanar.c
// Function: canonicalStringOfOuterplanarBlock
struct ShallowGraph* canonicalStringOfOuterplanarBlock(struct ShallowGraph* hamiltonianCycle, struct ShallowGraph* diagonals, struct ShallowGraphPool* sgp) {
	struct VertexList* idx;
	struct ShallowGraph* result1;
	struct ShallowGraph* result2;
	struct ShallowGraph* inverse = inverseCycle(hamiltonianCycle, sgp);

	/* special case. if block is a cycle, return the canonical string of that cycle */
	if (diagonals->m == 0) {
		dumpShallowGraph(sgp, diagonals);
		dumpShallowGraph(sgp, inverse);
		return getCyclePatterns(hamiltonianCycle, sgp);
	}

	/* add diagonals to the graph underlying the shallowgraphs */
	for (idx=diagonals->edges; idx; idx=idx->next) {
		struct VertexList* e = shallowCopyEdge(idx, sgp->listPool);
		e->next = idx->startPoint->neighborhood;
		idx->startPoint->neighborhood = e;

		e = inverseEdge(idx, sgp->listPool);
		e->next = idx->endPoint->neighborhood;
		idx->endPoint->neighborhood = e;
	}

	/* now find the permutation and orientation of the hamiltonian cycle that results in the lex.
	 * smallest string */

	result1 = __permutateBlock(hamiltonianCycle, sgp);

	//debug
	printCanonicalString(result1, stdout);

	result2 = __permutateBlock(inverse, sgp);

	//debug
	printCanonicalString(result2, stderr);

	/* garbage collection */
	dumpShallowGraph(sgp, inverse);
	dumpShallowGraph(sgp, hamiltonianCycle);
	dumpShallowGraph(sgp, diagonals);

	/* compare cStrings and return the better one */
	if (compareVertexLists(result1->edges, result2->edges) < 0) {
		dumpShallowGraph(sgp, result2);
		return result1;
	} else {
		dumpShallowGraph(sgp, result1);
		return result2;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, %rsi
callq 0x666c
movq %rax, %r12
cmpl $0x0, 0x10(%r15)
je 0x4712
movq %r15, %r13
movq (%r13), %r13
testq %r13, %r13
je 0x4690
movq 0x10(%rbx), %rsi
movq %r13, %rdi
callq 0x5a28
movq 0x10(%r13), %rcx
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq %rax, 0x8(%rcx)
movq 0x10(%rbx), %rsi
movq %r13, %rdi
callq 0x5a44
movq 0x18(%r13), %rcx
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq %rax, 0x8(%rcx)
addq $0x8, %r13
jmp 0x4649
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42ec
movq %rax, %r13
movq 0x25923(%rip), %rax     # 0x29fc8
movq (%rax), %rsi
movq %r13, %rdi
callq 0x5041
movq %r12, %rdi
movq %rbx, %rsi
callq 0x42ec
movq %rax, %rbp
movq 0x25933(%rip), %rax     # 0x29ff8
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x5041
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1184e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1184e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1184e
movq (%r13), %rdi
movq (%rbp), %rsi
callq 0x3b3d
movq %rbx, %rdi
testl %eax, %eax
js 0x4741
movq %r13, %rsi
callq 0x1184e
movq %rbp, %r13
jmp 0x4749
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1184e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1184e
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3de7
movq %rbp, %rsi
callq 0x1184e
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq