// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/lwmr_miningAndExtension.c
// Function: extendPreviousLevelRooted
static void _extendPreviousLevelRooted( // input
	struct SupportSet *previousLevelSupportLists,
	struct Vertex *previousLevelSearchTree,
	struct Vertex *currentLevelFrequentPatterns, // used for pruning already frequent patterns. if NULL, it is ignored
	struct ShallowGraph *extensionEdges,
	size_t threshold,
	char useAprioriPruning,
	// output
	struct SupportSet **resultCandidateSupportSuperSets,
	struct Graph **resultCandidates,
	FILE *logStream,
	// memory management
	struct GraphPool *gp,
	struct ShallowGraphPool *sgp)
{

	assert(previousLevelSupportLists != NULL);
	assert(extensionEdges != NULL);

	if (useAprioriPruning) {
		assert(previousLevelSearchTree != NULL);
	}


	*resultCandidateSupportSuperSets = NULL;
	*resultCandidates = NULL;

	struct Vertex* currentLevelCandidateSearchTree = getVertex(gp->vertexPool);

	int nAllGeneratedExtensions = 0;
	int nAllUniqueGeneratedExtensions = 0;
	int nAllKnownExtensions = 0;
	int nAllExtensionsPostApriori = 0;
	int nAllExtensionsPostIntersectionFilter = 0;
	int nAddedToOutput = 0;
	int nDumped = 0;

	// generate a list of extensions of all frequent patterns
	// filter these extensions using an apriori property
	// for each extension, compute a list of ids of their apriori parents

	for (struct SupportSet* frequentPatternSupportList=previousLevelSupportLists; frequentPatternSupportList!=NULL; frequentPatternSupportList=frequentPatternSupportList->next) {
		struct Graph* frequentPattern = frequentPatternSupportList->first->data.h;

		// extend frequent pattern
		struct Graph* listOfExtensions = extendRootedPatternAllWays(frequentPattern, extensionEdges, gp);

		for (struct Graph* extension=popGraph(&listOfExtensions); extension!=NULL; extension=popGraph(&listOfExtensions)) {
			// count number of generated extensions
			++nAllGeneratedExtensions;

			/* filter out patterns that were already enumerated before (in currentLevelFrequentPatterns) or as the extension of some other pattern
				and are in the search tree; here a distinction between rooted and unrooted trees takes place */
			struct ShallowGraph* string = canonicalStringOfRootedTree(extension->vertices[0], extension->vertices[0], sgp);
			int itIsKnown = 0;
			if ((currentLevelFrequentPatterns)) {
				itIsKnown = containsString(currentLevelFrequentPatterns, string);
				if (itIsKnown) {
					++nAllKnownExtensions;
				}
			}
			int previousNumberOfDistinctPatterns = currentLevelCandidateSearchTree->d;
			addToSearchTree(currentLevelCandidateSearchTree, string, gp, sgp);

			if (useAprioriPruning) {
				struct IntSet *aprioriParentIdSet;
				if ((previousNumberOfDistinctPatterns == currentLevelCandidateSearchTree->d) || (itIsKnown)) {
					aprioriParentIdSet = NULL;
				} else {
					++nAllUniqueGeneratedExtensions;
					aprioriParentIdSet = aprioriCheckExtensionRootedReturnList(extension, previousLevelSearchTree, gp, sgp);
				}

				if (aprioriParentIdSet) {
					// count number of apriori survivors
					++nAllExtensionsPostApriori;

					// get (hopefully small) superset of the support set of the extension
					struct SupportSet* extensionSupportSuperSet = getCandidateSupportSuperSet(aprioriParentIdSet, previousLevelSupportLists, frequentPattern->number);
					dumpIntSet(aprioriParentIdSet);

					// check if support superset is larger than the threshold
					if (extensionSupportSuperSet->size >= threshold) {
						// count number of intersection/threshold survivors
						++nAllExtensionsPostIntersectionFilter;

						// add extension and support super set to list of candidates for next level
						extension->next = *resultCandidates;
						*resultCandidates = extension;
						extensionSupportSuperSet->next = *resultCandidateSupportSuperSets;
						*resultCandidateSupportSuperSets = extensionSupportSuperSet;

						++nAddedToOutput;
					} else {
						// dump extension and support superset
						dumpGraph(gp, extension);
						dumpSupportSetCopy(extensionSupportSuperSet);

						++nDumped;
					}
				} else {
					// dump extension that does not fulfill apriori property
					dumpGraph(gp, extension);
					++nDumped;
				}
			} else {
				if ((previousNumberOfDistinctPatterns < currentLevelCandidateSearchTree->d) && (!itIsKnown)) {
					++nAllUniqueGeneratedExtensions;

					// add extension and support super set to list of candidates for next level 
					// without apriori et al. filtering, we keep each unique candidate and its support superset is just the support of the parent pattern.
					extension->next = *resultCandidates;
					*resultCandidates = extension;
					struct SupportSet *extensionSupportSuperSet = shallowCopySupportSet(frequentPatternSupportList);
					extensionSupportSuperSet->next = *resultCandidateSupportSuperSets;
					*resultCandidateSupportSuperSets = extensionSupportSuperSet;

					++nAddedToOutput;
				} else {
					// dump extension that does not fulfill apriori property
					dumpGraph(gp, extension);
					++nDumped;
				}
			}
		}
	}

	dumpSearchTree(gp, currentLevelCandidateSearchTree);
	fprintf(logStream, "generated extensions: %i\n"
					   "unique extensions: %i\n"
					   "unknown extensions: %i\n"
					   "apriori filtered extensions: %i\n"
					   "intersection filtered extensions: %i\n",
			nAllGeneratedExtensions, 
			nAllUniqueGeneratedExtensions, 
			nAllUniqueGeneratedExtensions - nAllKnownExtensions, 
			nAllExtensionsPostApriori, 
			nAllExtensionsPostIntersectionFilter);

	assert(nAddedToOutput + nDumped == nAllGeneratedExtensions);
}

// Assembly:
subq $0xa8, %rsp
movb %r9b, %al
movq 0xd0(%rsp), %r9
movq 0xc8(%rsp), %r9
movq 0xc0(%rsp), %r9
movq 0xb8(%rsp), %r9
movq 0xb0(%rsp), %r9
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movb %al, 0x7f(%rsp)
cmpb $0x0, 0x7f(%rsp)
je 0x1ed77
jmp 0x1ed77
movq 0xb0(%rsp), %rax
movq $0x0, (%rax)
movq 0xb8(%rsp), %rax
movq $0x0, (%rax)
movq 0xc8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movl $0x0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x1f10d
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x313e0
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
callq 0xba00
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x1f0f8
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0xd0(%rsp), %rdx
callq 0x94c0
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x1eeb9
movq 0x90(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x2c280
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x1eeb7
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x1eeb9
movq 0x70(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x70(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0xd0(%rsp), %rcx
callq 0x2c520
cmpb $0x0, 0x7f(%rsp)
je 0x1f03f
movl 0x20(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x28(%rcx), %eax
je 0x1ef04
cmpl $0x0, 0x24(%rsp)
je 0x1ef0f
movq $0x0, 0x18(%rsp)
jmp 0x1ef41
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
movq 0x30(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0xd0(%rsp), %rcx
callq 0x314c0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x1f01d
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
movq 0x18(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x40(%rsp), %rax
movl 0x8(%rax), %edx
callq 0x1cc70
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
callq 0xde90
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x80(%rsp), %rax
jb 0x1eff4
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movq 0xb8(%rsp), %rax
movq (%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x30(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, (%rax)
movq 0xb0(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq 0xb0(%rsp), %rax
movq %rcx, (%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x1f01b
movq 0xc8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1fb30
movq 0x10(%rsp), %rdi
callq 0x2fd70
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1f03a
movq 0xc8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1fb30
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1f0e2
movl 0x20(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x1f0c3
cmpl $0x0, 0x24(%rsp)
jne 0x1f0c3
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
movq 0xb8(%rsp), %rax
movq (%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x30(%rsp), %rcx
movq 0xb8(%rsp), %rax
movq %rcx, (%rax)
movq 0x48(%rsp), %rdi
callq 0x30280
movq %rax, 0x8(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %rcx
movq 0xb0(%rsp), %rax
movq %rcx, (%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x1f0e0
movq 0xc8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1fb30
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1f0e2
jmp 0x1f0e4
leaq 0x38(%rsp), %rdi
callq 0xba00
movq %rax, 0x30(%rsp)
jmp 0x1ee3b
jmp 0x1f0fa
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x1edf0
movq 0xc8(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x2d3c0
movq 0xc0(%rsp), %rdi
movl 0x6c(%rsp), %edx
movl 0x68(%rsp), %ecx
movl 0x68(%rsp), %r8d
subl 0x64(%rsp), %r8d
movl 0x60(%rsp), %r9d
movl 0x5c(%rsp), %eax
leaq 0x1692f(%rip), %rsi     # 0x35a78
movl %eax, (%rsp)
movb $0x0, %al
callq 0x1140
addq $0xa8, %rsp
retq
nopl (%rax,%rax)