// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x70(%rsp)
movq %r9, 0x68(%rsp)
movl $0x0, 0x50(%rsp)
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x10700
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0x10d30
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x5de0
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x11750
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0xbd60
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x58(%rsp)
jmp 0x5d9a
cmpq $0x0, 0x28(%rsp)
je 0x5e4a
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movq $0x0, 0x18(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x6a00
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
callq 0x2d520
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x54(%rsp)
jmp 0x5e52
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movq 0x68(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x5e96
movq 0x70(%rsp), %rax
cmpq $0x0, (%rax)
je 0x5e77
movq 0x70(%rsp), %rax
movq (%rax), %rdi
callq 0x1030
movl 0x54(%rsp), %edi
callq 0x2c430
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq %rcx, (%rax)
movl 0x54(%rsp), %ecx
movq 0x68(%rsp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x18(%rsp)
je 0x5f80
movq 0x78(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rax
movq (%rax), %rcx
movq 0x78(%rsp), %r9
movq 0x80(%rsp), %rax
movl $0x2, %edx
leaq 0x50(%rsp), %r8
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2c650
movq 0x70(%rsp), %rax
movq (%rax), %rdi
movslq 0x50(%rsp), %rsi
movl $0xc, %edx
leaq 0x26558(%rip), %rcx     # 0x2c450
callq 0x1060
movq 0x90(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x306e5(%rip), %rdi     # 0x365f4
movb $0x0, %al
callq 0x1090
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x50(%rsp), %eax
jge 0x5f70
movq 0x70(%rsp), %rax
movq (%rax), %rax
movslq 0x4c(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movq 0x70(%rsp), %rax
movq (%rax), %rax
movslq 0x4c(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edx
leaq 0x2f1d4(%rip), %rdi     # 0x35130
movb $0x0, %al
callq 0x1090
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x5f1e
leaq 0x2f13e(%rip), %rdi     # 0x350b5
movb $0x0, %al
callq 0x1090
jmp 0x5fa7
movq 0x90(%rsp), %rax
movl 0xc(%rax), %esi
leaq 0x30662(%rip), %rdi     # 0x365f4
movb $0x0, %al
callq 0x1090
leaq 0x2f115(%rip), %rdi     # 0x350b5
movb $0x0, %al
callq 0x1090
cmpq $0x0, 0x18(%rsp)
je 0x5fc1
movq 0x80(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2d3c0
movq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x5fff
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x1fb30
movq 0x60(%rsp), %rax
movq %rax, 0x58(%rsp)
jmp 0x5fcb
movq 0x80(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
xorl %eax, %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)