// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm0, 0x88(%rsp)
movq %r9, 0x80(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, %rbx
movq %rsi, 0x78(%rsp)
movq %rdi, %r14
movq 0x108(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x114a5
movq %rax, %rbp
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq %r14, 0x68(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x40(%rsp)
xorl %r12d, %r12d
movq %rbx, 0x38(%rsp)
testq %r14, %r14
je 0x10d52
movq %r14, 0x58(%rsp)
movq (%r14), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x70(%rsp)
movq 0x60(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x1af14
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x6404
movq %rax, %r15
testq %r15, %r15
je 0x10d44
movq 0x10(%r15), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x110(%rsp), %rdx
callq 0x5258
movq %rax, %r14
testq %rbx, %rbx
je 0x10bed
movq %rbx, %rdi
movq %r14, %rsi
callq 0x185c7
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
addl %r13d, 0x4c(%rsp)
jmp 0x10bf0
xorl %r13d, %r13d
movl 0x28(%rbp), %ebx
movq %rbp, %rdi
movq %r14, %rsi
movq 0x108(%rsp), %rdx
movq 0x110(%rsp), %rcx
callq 0x186c6
movl 0x28(%rbp), %eax
cmpb $0x0, 0xf0(%rsp)
je 0x10c2f
cmpl %eax, %ebx
sete %al
orb %al, %r13b
je 0x10c52
movq 0x38(%rsp), %rbx
jmp 0x10cc9
cmpl %eax, %ebx
setge %al
orb %al, %r13b
je 0x10cdb
movq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
jmp 0x10d05
incl 0x40(%rsp)
movq %r15, %rdi
movq 0x78(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq 0x110(%rsp), %rcx
callq 0x1af87
testq %rax, %rax
movq 0x38(%rsp), %rbx
je 0x10cc9
movq %rax, %r13
incl 0x48(%rsp)
movq 0x70(%rsp), %rax
movl 0x8(%rax), %edx
movq %r13, %rdi
movq 0x68(%rsp), %rsi
callq 0xfdec
movq %rax, %r14
movq %r13, %rdi
callq 0x772d
movq 0x50(%rsp), %rax
cmpq %rax, 0x18(%r14)
jae 0x10d0c
movq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
movq %r14, %rdi
callq 0x1a402
jmp 0x10d2c
movq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
jmp 0x10d2c
incl 0x40(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x58(%rsp), %rdi
callq 0x1a665
movq 0x28(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movq 0x38(%rsp), %rbx
jmp 0x10d2c
incl 0x44(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r14)
movq %r14, 0x28(%rsp)
movq %r15, 0x30(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x6404
movq %rax, %r15
incl %r12d
jmp 0x10baa
movq 0x58(%rsp), %r14
movq 0x10(%r14), %r14
jmp 0x10b66
movq 0x108(%rsp), %rdi
movq %rbp, %rsi
callq 0x18dcd
movl 0x40(%rsp), %ecx
movl %ecx, %r8d
subl 0x4c(%rsp), %r8d
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
leaq 0xccaf(%rip), %rsi      # 0x1da2b
movq 0x100(%rsp), %rdi
movl %r12d, %edx
movl 0x48(%rsp), %r9d
xorl %eax, %eax
callq 0x1150
leaq 0x90(%rsp), %r15
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %rbx
xorl %ebp, %ebp
movq $0x0, 0x38(%rsp)
testq %rbx, %rbx
je 0x10eb1
xorl %eax, %eax
callq 0x1a3dc
movq %rax, %r13
movq %rbx, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x10e6d
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movsd 0x88(%rsp), %xmm0
movq 0x108(%rsp), %rdx
movq 0x110(%rsp), %rcx
callq *0x80(%rsp)
cmpl $0x0, 0xb0(%rsp)
je 0x10e4d
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x90(%rsp), %xmm0
movups 0xa0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
callq 0x1a223
jmp 0x10e64
movq 0x98(%rsp), %rax
movq 0xa8(%rsp), %rdi
movl (%rax), %esi
callq 0x133ca
addq $0x28, %r14
jmp 0x10dc6
movq 0x18(%r13), %rax
cmpq 0x50(%rsp), %rax
jae 0x10e88
andl $0x0, 0xc(%r12)
movq %r13, %rdi
callq 0x1a448
jmp 0x10ea3
movl %eax, 0xc(%r12)
testq %rbp, %rbp
je 0x10e9b
movq %r13, 0x10(%rbp)
movq %r13, %rbp
jmp 0x10ea3
movq %r13, %rbp
movq %r13, 0x38(%rsp)
movq 0x18(%r12), %r12
movq 0x10(%rbx), %rbx
jmp 0x10db0
cmpb $0x0, 0xf0(%rsp)
je 0x10fa1
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x10ee1
movq 0x10(%rdi), %rbx
andq $0x0, 0x10(%rdi)
callq 0x1a402
movq %rbx, %rdi
jmp 0x10ec9
movq 0x190e0(%rip), %rax     # 0x29fc8
movq (%rax), %rdi
callq 0x1190
xorl %ebp, %ebp
testq %r12, %r12
je 0x10f72
movq 0x18(%r12), %rbx
andq $0x0, 0x18(%r12)
cmpl $0x0, 0xc(%r12)
jne 0x10f1f
movq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x1166e
movq %rbx, %r12
jmp 0x10ef2
incl %ebp
movq 0x10(%r12), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x110(%rsp), %r14
movq %r14, %rdx
callq 0x5258
movl 0xc(%r12), %ecx
movl %ecx, 0x28(%rax)
movq 0xf8(%rsp), %r15
movq (%r15), %rdi
movq %rax, %rsi
movq 0x108(%rsp), %rdx
movq %r14, %rcx
callq 0x1871e
movq (%r15), %rax
movl 0x20(%rax), %eax
movl %eax, 0x8(%r12)
movq %rbx, %r12
jmp 0x10ef2
leaq 0xc9fc(%rip), %rsi      # 0x1d975
movq 0x100(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1150
movq 0x38(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %r12
je 0x10ef0
movq 0x10(%rdi), %r14
callq 0x1a402
testq %r14, %r14
je 0x10ef0
movq 0x10(%r14), %rbx
movq %r14, %rdi
callq 0x1030
movq %rbx, %r14
jmp 0x10fbd