// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/cpk.c
// Function: CyclicPatternKernel_onlyCycles
int CyclicPatternKernel_onlyCycles(struct Graph *g, struct ShallowGraphPool *sgp, struct GraphPool *gp, struct Vertex* globalPatternSet, struct compInfo** results, int* resSize) {
	struct Graph* tmp;
	struct Graph* idx;
	int numCycles;
	int pos = 0;
	int i;

	/* find biconnected Components */
	struct ShallowGraph* h = listBiconnectedComponents(g, sgp);
	struct Graph* forest = partitionIntoForestAndCycles(h, g, gp, sgp);
	/* TODO refactor */
	struct Graph* biconnectedComponents = forest->next;

	/* list all cycles */
	struct ShallowGraph* simpleCycles = NULL;
	struct ShallowGraph* cyclePatterns = NULL;
	struct Vertex* cyclePatternSearchTree = NULL;

	for (idx=biconnectedComponents; idx; idx=idx->next) {
		simpleCycles = addComponent(simpleCycles, listCycles(idx, sgp));
	}

	/* if cycles were found, compute canonical strings */
	if (simpleCycles) {
		/* transform cycle of shallow graphs to a list */
		simpleCycles->prev->next = NULL;
		simpleCycles->prev = NULL;

		cyclePatterns = getCyclePatterns(simpleCycles, sgp);
		cyclePatternSearchTree = buildSearchTree(cyclePatterns, gp, sgp);

		numCycles = cyclePatternSearchTree->number;
	} else {
		numCycles = 0;
	}

	if (numCycles > *resSize) {
		if (*results) {
			free(*results);
		}

		*results = getResultVector(numCycles);
		*resSize = numCycles;
	}


	

	/* add elements to global search trees to obtain mapping from strings to integers */
	if (cyclePatternSearchTree) {
		mergeSearchTrees(globalPatternSet, cyclePatternSearchTree, 2, *results, &pos, globalPatternSet, 0, gp);
		
		/* sort the output elements by increasing id */
		qsort(*results, pos, sizeof(struct compInfo), &compInfoComparison);
		
		/* "all" output the feature vector for the current graph in the format specified
		 * by SVMlight g->activity is assumed to be either 0, 1 or -1 to be compliant with
		 * the specs of SVMlight.
		 */

		/* print the id and label of the graph */
		printf("%i", g->activity);

		/* print key:value pairs */
		for (i=0; i<pos; ++i) {
			printf(" %i:%i", (*results)[i].id, (*results)[i].count);
		}
		printf("\n");
	} else {
		/* print only label */
		printf("%i", g->activity);
		printf("\n");
	}

	/* garbage collection */

	/* dump cycles, if any
	 * TODO may be moved upwards directly after finding simple cycles */
	if (cyclePatternSearchTree) {
		dumpSearchTree(gp, cyclePatternSearchTree);
	}

	/* dump biconnected components list */
	for (idx=biconnectedComponents; idx; idx=tmp) {
		tmp = idx->next;
		dumpGraph(gp, idx);
	}

	dumpGraph(gp, forest);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r15
movq %rcx, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
movl $0x0, 0x4(%rsp)
callq 0xb23b
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0xb57c
movq %rax, 0x20(%rsp)
movq 0x18(%rax), %r12
testq %r12, %r12
je 0x580d
movq %r15, 0x10(%rsp)
xorl %ebp, %ebp
movq %r12, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xbb0d
movq %rbp, %rdi
movq %rax, %rsi
callq 0x883e
movq %rax, %rbp
movq 0x18(%r15), %r15
testq %r15, %r15
jne 0x57b7
testq %rbp, %rbp
je 0x5814
movq 0x20(%rbp), %rax
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
movq %rcx, 0x20(%rbp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x5de1
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1b614
movq %rax, %r14
movl 0x18(%rax), %ebp
jmp 0x5819
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x581e
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rax
cmpl (%rax), %ebp
jle 0x5845
movq (%r15), %rdi
testq %rdi, %rdi
je 0x5834
callq 0x1030
movl %ebp, %edi
callq 0x1ada1
movq %rax, (%r15)
movq 0x8(%rsp), %rax
movl %ebp, (%rax)
testq %r14, %r14
je 0x58fc
movq (%r15), %rcx
leaq 0x4(%rsp), %rbp
movq 0x18(%rsp), %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
movl $0x2, %edx
movq %rbp, %r8
movq %rdi, %r9
pushq %rbx
pushq $0x0
callq 0x1aefc
addq $0x10, %rsp
movq (%r15), %rdi
movslq (%rbp), %rsi
leaq 0x15529(%rip), %rcx     # 0x1adb1
movl $0xc, %edx
callq 0x1080
movl 0xc(%r13), %esi
leaq 0x1bd0d(%rip), %rdi     # 0x215aa
xorl %eax, %eax
callq 0x10b0
cmpl $0x0, (%rbp)
jle 0x58e3
movq %r15, %r14
movl $0x4, %r15d
leaq 0x1a81e(%rip), %r13     # 0x200d8
xorl %ebp, %ebp
movq (%r14), %rax
movl -0x4(%rax,%r15), %esi
movl (%rax,%r15), %edx
movq %r13, %rdi
xorl %eax, %eax
callq 0x10b0
incq %rbp
movslq 0x4(%rsp), %rax
addq $0xc, %r15
cmpq %rax, %rbp
jl 0x58bc
movl $0xa, %edi
callq 0x1040
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x1b546
jmp 0x5918
movl 0xc(%r13), %esi
leaq 0x1bca3(%rip), %rdi     # 0x215aa
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
testq %r12, %r12
je 0x5935
movq 0x18(%r12), %r14
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14700
movq %r14, %r12
testq %r14, %r14
jne 0x591d
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x14700
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq