// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/lwmr_miningAndExtension.c
// Function: getNextLevelRooted
static struct SupportSet* _getNextLevelRooted(// input
		struct SupportSet* previousLevelSupportLists,
		struct Vertex* previousLevelSearchTree,
		struct Vertex* currentLevelFrequentPatterns, // used for avoiding duplicate evaluation of already identified frequent patterns
		size_t threshold,
		struct ShallowGraph* frequentEdges,
		// embedding operator function pointer,
		struct SubtreeIsoDataStore (*embeddingOperator)(struct SubtreeIsoDataStore, struct Graph*, double, struct GraphPool*, struct ShallowGraphPool*),
		double importance,
		char useAprioriPruning,
		// output
		struct Vertex** currentLevelSearchTree,
		FILE* logStream,
		// memory management
		struct GraphPool* gp,
		struct ShallowGraphPool* sgp) {
	assert(previousLevelSupportLists != NULL);
	assert(previousLevelSearchTree != NULL);
	assert(frequentEdges != NULL);

	struct SupportSet* currentLevelCandidateSupportSets;
	struct Graph* currentLevelCandidates;

	_extendPreviousLevelRooted(previousLevelSupportLists, previousLevelSearchTree, currentLevelFrequentPatterns, frequentEdges, threshold, useAprioriPruning, 
			&currentLevelCandidateSupportSets, &currentLevelCandidates, logStream,
			gp, sgp);

	//iterate over all patterns in candidateSupports
	struct SupportSet* actualSupportLists = NULL;
	struct SupportSet* actualSupportListsTail = NULL;
	struct SupportSet* candidateSupport = NULL;
	struct Graph* candidate = NULL;

	for (candidateSupport=currentLevelCandidateSupportSets, candidate=currentLevelCandidates; 
	     candidateSupport!=NULL; 
		 candidateSupport=candidateSupport->next, candidate=candidate->next) {

		struct SupportSet* currentActualSupport = getSupportSet();

		//iterate over all graphs in the support
		for (struct SupportSetElement* e=candidateSupport->first; e!=NULL; e=e->next) {
			// create actual support list for candidate pattern
			struct SubtreeIsoDataStore result = embeddingOperator(e->data, candidate, importance, gp, sgp);

			if (result.foundIso) {
				appendSupportSetData(currentActualSupport, result);
			} else {
				dumpNewCube(result.S, result.g->n);
			}
		}

		// filter out candidates with support < threshold
		if (currentActualSupport->size < threshold) {
			// mark h as infrequent
			candidate->activity = 0;
			dumpSupportSet(currentActualSupport);
		} else {
			// mark h as frequent
			candidate->activity = currentActualSupport->size;
			// add to output list, maintaining order. necessary
			if (actualSupportListsTail) {
				actualSupportListsTail->next = currentActualSupport;
			} else {
				actualSupportLists = currentActualSupport;		
			}
			actualSupportListsTail = currentActualSupport;
		}
	}

	// garbage collection
	if (useAprioriPruning) {
		// every candidate has its own candidate support set. dump all of them individually
		candidateSupport = currentLevelCandidateSupportSets;
		while (candidateSupport) {
			struct SupportSet* tmp = candidateSupport->next;
			candidateSupport->next = NULL;
			dumpSupportSetCopy(candidateSupport);
			candidateSupport = tmp;
		}
		fflush(stdout);
	} else {
		// all candidates share the same candidate support set. dump it and free the headers.
		if (currentLevelCandidateSupportSets) {
			candidateSupport = currentLevelCandidateSupportSets->next;
			dumpSupportSetCopy(currentLevelCandidateSupportSets);
			while(candidateSupport) {
				struct SupportSet* tmp = candidateSupport->next;
				free(candidateSupport);
				candidateSupport = tmp;
			}
		}
	}

	// add frequent extensions to current level search tree output, set their numbers correctly
	// dump those candidates that are not frequent
	// TODO we could save reevaluating seen patterns by storing them in this or another search tree
	int nAllFrequentExtensions = 0;
	candidate = currentLevelCandidates;
	while (candidate) {
		struct Graph* tmp = candidate->next;
		candidate->next = NULL;
		if (candidate->activity == 0) {
			dumpGraph(gp, candidate);
		} else {
			++nAllFrequentExtensions;
			struct ShallowGraph* cString = canonicalStringOfRootedTree(candidate->vertices[0], candidate->vertices[0], sgp);
			cString->data = candidate->activity;
			addMultiSetToSearchTree(*currentLevelSearchTree, cString, gp, sgp);
			candidate->number = (*currentLevelSearchTree)->lowPoint;
		}
		candidate = tmp;
	}
	fprintf(logStream, "frequent patterns: %i\n", nAllFrequentExtensions);

	return actualSupportLists;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xf8, %rsp
movq 0x130(%rsp), %rax
movq 0x128(%rsp), %rax
movq 0x120(%rsp), %rax
movq 0x118(%rsp), %rax
movb 0x110(%rsp), %al
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq %r8, 0xd0(%rsp)
movq %r9, 0xc8(%rsp)
movsd %xmm0, 0xc0(%rsp)
movq 0xf0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
movq 0xd0(%rsp), %rcx
movq 0xd8(%rsp), %r8
movb 0x110(%rsp), %r9b
movq 0x120(%rsp), %r11
movq 0x128(%rsp), %r10
movq 0x130(%rsp), %rax
leaq 0xb8(%rsp), %r14
leaq 0xb0(%rsp), %rbx
movsbl %r9b, %r9d
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x1ed10
movq $0x0, 0xa8(%rsp)
movq $0x0, 0xa0(%rsp)
movq $0x0, 0x98(%rsp)
movq $0x0, 0x90(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x98(%rsp)
je 0x1e722
movb $0x0, %al
callq 0x2fd20
movq %rax, 0x88(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x80(%rsp)
je 0x1e665
movq 0xc8(%rsp), %rax
movq 0x80(%rsp), %r8
movq 0x90(%rsp), %rsi
movsd 0xc0(%rsp), %xmm0
movq 0x128(%rsp), %rdx
movq 0x130(%rsp), %rcx
movq 0x20(%r8), %r9
movq %rsp, %rdi
movq %r9, 0x20(%rdi)
movups (%r8), %xmm1
movups 0x10(%r8), %xmm2
movups %xmm2, 0x10(%rdi)
movups %xmm1, (%rdi)
leaq 0x58(%rsp), %rdi
callq *%rax
cmpl $0x0, 0x78(%rsp)
je 0x1e639
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups 0x58(%rsp), %xmm0
movups 0x68(%rsp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x2fa10
jmp 0x1e64a
movq 0x70(%rsp), %rdi
movq 0x60(%rsp), %rax
movl (%rax), %esi
callq 0x22fa0
jmp 0x1e64c
movq 0x80(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x80(%rsp)
jmp 0x1e5a4
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0xd8(%rsp), %rax
jae 0x1e699
movq 0x90(%rsp), %rax
movl $0x0, 0xc(%rax)
movq 0x88(%rsp), %rdi
callq 0x2fde0
jmp 0x1e6f3
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movl %eax, %ecx
movq 0x90(%rsp), %rax
movl %ecx, 0xc(%rax)
cmpq $0x0, 0xa0(%rsp)
je 0x1e6d3
movq 0x88(%rsp), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1e6e3
movq 0x88(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x1e6f5
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x90(%rsp)
jmp 0x1e573
cmpb $0x0, 0x110(%rsp)
je 0x1e795
movq 0xb8(%rsp), %rax
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x98(%rsp)
je 0x1e784
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x98(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x98(%rsp), %rdi
callq 0x2fd70
movq 0x50(%rsp), %rax
movq %rax, 0x98(%rsp)
jmp 0x1e73c
movq 0x1f83d(%rip), %rax     # 0x3dfc8
movq (%rax), %rdi
callq 0x1180
jmp 0x1e7fd
cmpq $0x0, 0xb8(%rsp)
je 0x1e7fb
movq 0xb8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x98(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x2fd70
cmpq $0x0, 0x98(%rsp)
je 0x1e7f9
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x98(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movq %rax, 0x98(%rsp)
jmp 0x1e7c1
jmp 0x1e7fb
jmp 0x1e7fd
movl $0x0, 0x44(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x1e90b
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x90(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1e86d
movq 0x128(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x1fb30
jmp 0x1e8f9
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x130(%rsp), %rdx
callq 0x94c0
movq %rax, 0x30(%rsp)
movq 0x90(%rsp), %rax
movl 0xc(%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x118(%rsp), %rax
movq (%rax), %rdi
movq 0x30(%rsp), %rsi
movq 0x128(%rsp), %rdx
movq 0x130(%rsp), %rcx
callq 0x2c5b0
movq 0x118(%rsp), %rax
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq 0x90(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x1e815
movq 0x120(%rsp), %rdi
movl 0x44(%rsp), %edx
leaq 0x170a4(%rip), %rsi     # 0x359c2
movb $0x0, %al
callq 0x1140
movq 0xa8(%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r14
retq
nopl (%rax,%rax)