// File: /workspace/github_c_makefile_star2_O3/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, 0x60(%rsp)
movq %rdx, %r13
movq %rsi, 0x88(%rsp)
movq %rdi, %r14
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1447e
movq %rax, %rbx
testq %r14, %r14
je 0x13b08
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x44(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movq %r14, 0x78(%rsp)
movq %r13, 0x38(%rsp)
movq %r14, 0x68(%rsp)
movq (%r14), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x80(%rsp)
movq 0x70(%rsp), %rsi
movq 0x118(%rsp), %rdx
callq 0x1da78
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x86c8
movq %rax, %r15
testq %rax, %rax
je 0x13af4
movq 0x10(%r15), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x120(%rsp), %rdx
callq 0x736c
movq %rax, %r14
testq %r13, %r13
je 0x139bc
movq %r13, %rdi
movq %r14, %rsi
callq 0x1ad18
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
addl %r13d, 0x5c(%rsp)
jmp 0x139bf
xorl %r13d, %r13d
movl 0x28(%rbx), %ebp
movq %rbx, %rdi
movq %r14, %rsi
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rcx
callq 0x1ae1e
movl 0x28(%rbx), %eax
cmpb $0x0, 0x100(%rsp)
je 0x13a74
cmpl %eax, %ebp
sete %al
orb %al, %r13b
jne 0x13a7e
incl 0x44(%rsp)
movq %r15, %rdi
movq 0x88(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rcx
callq 0x1dafe
testq %rax, %rax
je 0x13a7e
movq %rax, %r13
incl 0x58(%rsp)
movq 0x80(%rsp), %rax
movl 0x8(%rax), %edx
movq %r13, %rdi
movq 0x78(%rsp), %rsi
callq 0x12ae8
movq %rax, %r14
movq %r13, %rdi
callq 0x9b28
movq 0x60(%rsp), %rax
cmpq %rax, 0x18(%r14)
jae 0x13ab7
movq 0x118(%rsp), %rdi
movq %r15, %rsi
callq 0x14700
movq %r14, %rdi
callq 0x1ce4c
jmp 0x13ad7
cmpl %eax, %ebp
setge %al
orb %al, %r13b
je 0x13a90
movq 0x118(%rsp), %rdi
movq %r15, %rsi
callq 0x14700
jmp 0x13ad7
incl 0x44(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x68(%rsp), %rdi
callq 0x1d136
movq 0x48(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x48(%rsp)
jmp 0x13ad2
incl 0x54(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%r15)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%r14)
movq %r14, 0x48(%rsp)
movq %r15, 0x30(%rsp)
movq 0x38(%rsp), %r13
leaq 0xa0(%rsp), %rdi
callq 0x86c8
movq %rax, %r15
incl %r12d
jmp 0x13979
movq 0x68(%rsp), %r14
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x1393b
jmp 0x13b3d
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x44(%rsp)
xorl %r12d, %r12d
movq 0x118(%rsp), %rdi
movq %rbx, %rsi
callq 0x1b546
movl 0x44(%rsp), %ecx
movl %ecx, %r8d
subl 0x5c(%rsp), %r8d
movl 0x54(%rsp), %eax
movl %eax, (%rsp)
leaq 0xcef9(%rip), %rsi      # 0x20a60
movq 0x110(%rsp), %rdi
movl %r12d, %edx
movl 0x58(%rsp), %r9d
xorl %eax, %eax
callq 0x1160
movq 0x48(%rsp), %r14
testq %r14, %r14
je 0x13cd6
leaq 0xa0(%rsp), %r15
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
movq 0x30(%rsp), %r12
xorl %eax, %eax
callq 0x1ce22
movq %rax, %r13
movq (%r14), %rbx
testq %rbx, %rbx
je 0x13c53
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 0x13c33
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0xa0(%rsp), %xmm0
movups 0xb0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
callq 0x1cc1f
jmp 0x13c4a
movq 0xa8(%rsp), %rax
movq 0xb8(%rsp), %rdi
movl (%rax), %esi
callq 0x161f7
movq 0x28(%rbx), %rbx
jmp 0x13bb1
movq 0x18(%r13), %rax
cmpq 0x60(%rsp), %rax
jae 0x13c71
movl $0x0, 0xc(%r12)
movq %r13, %rdi
callq 0x1ce92
jmp 0x13c8c
movl %eax, 0xc(%r12)
testq %rbp, %rbp
je 0x13c84
movq %r13, 0x10(%rbp)
movq %r13, %rbp
jmp 0x13c8c
movq %r13, %rbp
movq %r13, 0x38(%rsp)
movq 0x18(%r12), %r12
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x13ba4
cmpb $0x0, 0x100(%rsp)
je 0x13db9
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %r12
je 0x13cee
movq 0x10(%rdi), %rbx
movq $0x0, 0x10(%rdi)
callq 0x1ce4c
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x13cbb
jmp 0x13cee
movq $0x0, 0x38(%rsp)
cmpb $0x0, 0x100(%rsp)
movq 0x30(%rsp), %r12
je 0x13cfd
movq 0x192d3(%rip), %rax     # 0x2cfc8
movq (%rax), %rdi
callq 0x11a0
testq %r12, %r12
je 0x13d88
movq 0x108(%rsp), %r14
xorl %ebp, %ebp
movq 0x18(%r12), %rbx
movq $0x0, 0x18(%r12)
cmpl $0x0, 0xc(%r12)
je 0x13d6e
incl %ebp
movq 0x10(%r12), %rax
movq (%rax), %rdi
movq %rdi, %rsi
movq 0x120(%rsp), %r15
movq %r15, %rdx
callq 0x736c
movl 0xc(%r12), %ecx
movl %ecx, 0x28(%rax)
movq (%r14), %rdi
movq %rax, %rsi
movq 0x118(%rsp), %rdx
movq %r15, %rcx
callq 0x1ae89
movq (%r14), %rax
movl 0x20(%rax), %eax
movl %eax, 0x8(%r12)
jmp 0x13d7e
movq 0x118(%rsp), %rdi
movq %r12, %rsi
callq 0x14700
movq %rbx, %r12
testq %rbx, %rbx
jne 0x13d10
jmp 0x13d8a
xorl %ebp, %ebp
leaq 0xcc19(%rip), %rsi      # 0x209aa
movq 0x110(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1160
movq 0x38(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %r12
je 0x13cfd
movq 0x10(%rdi), %r14
callq 0x1ce4c
testq %r14, %r14
je 0x13cfd
movq 0x10(%r14), %rbx
movq %r14, %rdi
callq 0x1030
movq %rbx, %r14
testq %rbx, %rbx
jne 0x13dde
jmp 0x13cfd