// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/lwmr_miningAndExtension.c
// Function: BFSStrategyRooted
void BFSStrategyRooted(size_t startPatternSize,
					  size_t maxPatternSize,
		              size_t threshold,
					  struct Vertex* initialFrequentPatterns,
					  struct SupportSet* supportSets,
					  struct ShallowGraph* extensionEdges,
					  // embedding operator function pointer,
					  struct SubtreeIsoDataStore (*embeddingOperator)(struct SubtreeIsoDataStore, struct Graph*, double, struct GraphPool*, struct ShallowGraphPool*),
					  double importance,
					  FILE* featureStream,
					  FILE* patternStream,
					  FILE* logStream,
					  struct GraphPool* gp,
					  struct ShallowGraphPool* sgp) {

	const char useAprioriPruning = 1;

	// levelwise search for patterns with more than one vertex:
	struct Vertex* previousLevelSearchTree = shallowCopySearchTree(initialFrequentPatterns, gp);
	struct SupportSet* previousLevelSupportSets = supportSets;
	struct Vertex* currentLevelSearchTree = previousLevelSearchTree; // initialization for garbage collection in case of maxPatternSize == 1
	struct SupportSet* currentLevelSupportSets = previousLevelSupportSets; // initialization for garbage collection in case of maxPatternSize == 1

	for (size_t p=startPatternSize+1; (p<=maxPatternSize) && (previousLevelSearchTree->number>0); ++p) {
		fprintf(logStream, "Processing patterns with %zu vertices:\n", p); fflush(logStream);
		currentLevelSearchTree = getVertex(gp->vertexPool);
		offsetSearchTreeIds(currentLevelSearchTree, previousLevelSearchTree->lowPoint);

		currentLevelSupportSets = _getNextLevelRooted(previousLevelSupportSets, previousLevelSearchTree, NULL, threshold, extensionEdges, embeddingOperator, importance, useAprioriPruning, &currentLevelSearchTree, logStream, gp, sgp);

		printStringsInSearchTree(currentLevelSearchTree, patternStream, sgp);
		fflush(patternStream);
		printSupportSetsSparse(currentLevelSupportSets, featureStream);
		fflush(featureStream);

		// garbage collection:
		// what is now all previousLevel... data structures will not be used at all in the next iteration
		dumpSearchTree(gp, previousLevelSearchTree);
		while (previousLevelSupportSets) {
			struct SupportSet* tmp = previousLevelSupportSets->next;
			// ...hence, we also dump the pattern graphs completely, which we can't do in a DFS mining approach.
			dumpSupportSetWithPattern(previousLevelSupportSets, gp);
			previousLevelSupportSets = tmp;
		}

		// previous level = current level
		previousLevelSearchTree = currentLevelSearchTree;
		previousLevelSupportSets = currentLevelSupportSets;
	}

	// garbage collection
	dumpSearchTree(gp, previousLevelSearchTree);

	while (previousLevelSupportSets) {
		struct SupportSet* tmp = previousLevelSupportSets->next;
		// we also dump the pattern graphs completely, which we can't do in a DFS mining approach.
		dumpSupportSetWithPattern(previousLevelSupportSets, gp);
		previousLevelSupportSets = tmp;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x10(%rsp)
movq %r9, 0x8(%rsp)
movq %r8, %r14
movq %rdx, (%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbp
movq 0x90(%rsp), %rbx
movq %rcx, %rdi
movq %rbx, %rsi
callq 0x18e1c
movq %rax, %r13
incq %rbp
cmpq 0x18(%rsp), %rbp
ja 0x10aa9
cmpl $0x0, 0x18(%r13)
jle 0x10aa9
movq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0xcf8c(%rip), %rsi      # 0x1d94d
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1150
movq %r15, %rdi
callq 0x1190
movq 0x10(%rbx), %rdi
callq 0x114a5
movq %rax, %r12
movq %rax, 0x30(%rsp)
movl 0x20(%r13), %esi
movq %rax, %rdi
callq 0x18943
subq $0x8, %rsp
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x18(%rsp), %xmm0
movq 0xa0(%rsp), %rax
pushq %rax
pushq %rbx
pushq %r15
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x1
callq 0x10adc
addq $0x30, %rsp
movq %rax, %r15
movq %r12, %rdi
movq %r13, 0x20(%rsp)
movq 0x80(%rsp), %r13
movq %r13, %rsi
movq 0x98(%rsp), %rdx
callq 0x18fd2
movq %r13, %rdi
callq 0x1190
movq %r15, 0x28(%rsp)
movq %r15, %rdi
movq 0x78(%rsp), %r13
movq %r13, %rsi
callq 0x1a3b4
movq %r13, %rdi
callq 0x1190
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x18dcd
testq %r14, %r14
je 0x10a9c
movq 0x10(%r14), %r13
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1a4cd
movq %r13, %r14
jmp 0x10a83
movq 0x28(%rsp), %r14
movq %r12, %r13
jmp 0x10996
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18dcd
testq %r14, %r14
je 0x10acd
movq 0x10(%r14), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1a4cd
movq %r15, %r14
jmp 0x10ab4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq