// File: /workspace/github_c_makefile_star2_O1/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 $0xc8, %rsp
movsd %xmm0, 0x98(%rsp)
movq %r9, 0x90(%rsp)
movq %r8, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %rdx, %r14
movq %rsi, 0x78(%rsp)
movq %rdi, %r12
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x145b2
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
testq %r12, %r12
je 0x13c5a
movq $0x0, 0x28(%rsp)
xorl %r15d, %r15d
movl $0x0, 0x34(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movq %r12, 0x80(%rsp)
movq %r14, 0x58(%rsp)
movq %r12, 0x60(%rsp)
movq (%r12), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x88(%rsp)
movq 0x70(%rsp), %rsi
movq 0x118(%rsp), %rdx
callq 0x1dbc8
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x864a
movq %rax, %r12
testq %rax, %rax
je 0x13c45
movq %rbx, 0x38(%rsp)
movq 0x10(%r12), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x120(%rsp), %rdx
callq 0x732c
movq %rax, %rbx
testq %r14, %r14
je 0x13adf
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1adff
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
addl %r13d, 0x4c(%rsp)
jmp 0x13ae2
xorl %r13d, %r13d
movq 0x50(%rsp), %r14
movl 0x28(%r14), %ebp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rcx
callq 0x1af0f
movl 0x28(%r14), %eax
cmpb $0x0, 0x100(%rsp)
je 0x13b23
cmpl %eax, %ebp
sete %al
orb %al, %r13b
je 0x13b50
xorl %r13d, %r13d
jmp 0x13b74
cmpl %eax, %ebp
setge %al
orb %al, %r13b
je 0x13c02
movq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x14832
movq 0x38(%rsp), %rbx
movq 0x28(%rsp), %r12
jmp 0x13c26
incl 0x34(%rsp)
movq %r12, %rdi
movq 0x78(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rcx
callq 0x1dc46
movq %rax, %r13
movq 0x58(%rsp), %r14
testq %r13, %r13
je 0x13bcd
incl 0x48(%rsp)
movq 0x88(%rsp), %rax
movl 0x8(%rax), %edx
movq %r13, %rdi
movq 0x80(%rsp), %rsi
callq 0x12c18
movq %rax, %rbx
movq %r13, %rdi
callq 0x9b14
movq 0x68(%rsp), %rax
cmpq %rax, 0x18(%rbx)
jae 0x13be9
movq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x14832
movq %rbx, %rdi
callq 0x1cfb1
jmp 0x13bdd
movq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x14832
movq 0x38(%rsp), %rbx
movq 0x28(%rsp), %r12
jmp 0x13c2b
incl 0x44(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x18(%r12)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x13c2b
incl 0x34(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x18(%r12)
movq 0x60(%rsp), %rdi
callq 0x1d29d
movq %rax, %rbx
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rbx)
movq 0x58(%rsp), %r14
leaq 0xa0(%rsp), %rdi
callq 0x864a
movq %r12, 0x28(%rsp)
incl %r15d
jmp 0x13a93
movq 0x60(%rsp), %r12
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x13a57
jmp 0x13c86
movq $0x0, 0x28(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x34(%rsp)
xorl %r15d, %r15d
movq 0x118(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x1b644
movl 0x34(%rsp), %ecx
movl %ecx, %r8d
subl 0x4c(%rsp), %r8d
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
leaq 0xcdae(%rip), %rsi      # 0x20a60
movq 0x110(%rsp), %rdi
movl %r15d, %edx
movl 0x48(%rsp), %r9d
xorl %eax, %eax
callq 0x1160
testq %rbx, %rbx
movq %rbx, 0x38(%rsp)
je 0x13df0
leaq 0xa0(%rsp), %r15
movq $0x0, 0x50(%rsp)
xorl %r14d, %r14d
movq %rbx, %r13
movq 0x28(%rsp), %r12
xorl %eax, %eax
callq 0x1cf87
movq %rax, %rbp
movq (%r13), %rbx
testq %rbx, %rbx
je 0x13da3
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movsd 0x98(%rsp), %xmm0
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rcx
callq *0x90(%rsp)
cmpl $0x0, 0xc0(%rsp)
je 0x13d83
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0xa0(%rsp), %xmm0
movups 0xb0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x1cd7a
jmp 0x13d9a
movq 0xa8(%rsp), %rax
movq 0xb8(%rsp), %rdi
movl (%rax), %esi
callq 0x1631f
movq 0x28(%rbx), %rbx
jmp 0x13d01
movq 0x18(%rbp), %rax
cmpq 0x68(%rsp), %rax
jae 0x13dc1
movl $0x0, 0xc(%r12)
movq %rbp, %rdi
callq 0x1cff7
jmp 0x13ddc
movl %eax, 0xc(%r12)
testq %r14, %r14
je 0x13dd4
movq %rbp, 0x10(%r14)
movq %rbp, %r14
jmp 0x13ddc
movq %rbp, %r14
movq %rbp, 0x50(%rsp)
movq 0x18(%r12), %r12
movq 0x10(%r13), %r13
testq %r13, %r13
jne 0x13cf3
jmp 0x13df9
movq $0x0, 0x50(%rsp)
cmpb $0x0, 0x100(%rsp)
je 0x13ec9
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r12
je 0x13e2f
movq 0x10(%rdi), %rbx
movq $0x0, 0x10(%rdi)
callq 0x1cfb1
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x13e16
movq 0x19192(%rip), %rax     # 0x2cfc8
movq (%rax), %rdi
callq 0x11a0
testq %r12, %r12
je 0x13f07
movq 0x108(%rsp), %rbx
xorl %ebp, %ebp
movq 0x18(%r12), %r14
movq $0x0, 0x18(%r12)
cmpl $0x0, 0xc(%r12)
je 0x13eaf
incl %ebp
movq 0x10(%r12), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x120(%rsp), %r15
movq %r15, %rdx
callq 0x732c
movl 0xc(%r12), %ecx
movl %ecx, 0x28(%rax)
movq (%rbx), %rdi
movq %rax, %rsi
movq 0x118(%rsp), %rdx
movq %r15, %rcx
callq 0x1af75
movq (%rbx), %rax
movl 0x20(%rax), %eax
movl %eax, 0x8(%r12)
jmp 0x13ebf
movq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x14832
movq %r14, %r12
testq %r14, %r14
jne 0x13e51
jmp 0x13f09
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r12
je 0x13e3e
movq 0x10(%rdi), %r15
callq 0x1cfb1
testq %r15, %r15
je 0x13e3e
movq 0x10(%r15), %rbx
movq %r15, %rdi
callq 0x1030
movq %rbx, %r15
testq %rbx, %rbx
jne 0x13eee
jmp 0x13e3e
xorl %ebp, %ebp
leaq 0xca9a(%rip), %rsi      # 0x209aa
movq 0x110(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1160
movq 0x50(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq