// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r13
movq 0x80(%rsp), %rbx
movq %rcx, %rdi
movq %rbx, %rsi
callq 0x1b696
movq %rax, %r14
movq %rax, (%rsp)
incq %r13
movq %r15, 0x8(%rsp)
cmpq %r15, %r13
jbe 0x13896
movq %rbp, %r12
jmp 0x1398f
cmpl $0x0, 0x18(%r14)
jle 0x1388e
movq 0x78(%rsp), %r12
movq %r12, %rdi
leaq 0xd0d6(%rip), %rsi      # 0x20982
movq %r13, %rdx
xorl %eax, %eax
callq 0x1160
movq %r12, %rdi
callq 0x11a0
movq 0x10(%rbx), %rdi
callq 0x145b2
movq %rax, %r15
movq %rax, (%rsp)
movl 0x20(%r14), %esi
movq %rax, %rdi
callq 0x1b1ae
subq $0x8, %rsp
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x68(%rsp), %r9
movsd 0x28(%rsp), %xmm0
movq 0x90(%rsp), %rax
pushq %rax
pushq %rbx
pushq %r12
leaq 0x20(%rsp), %rax
pushq %rax
pushq $0x1
callq 0x139c6
addq $0x30, %rsp
movq %rax, %r12
movq %r15, %rdi
movq 0x70(%rsp), %r15
movq %r15, %rsi
movq 0x88(%rsp), %rdx
callq 0x1b857
movq %r15, %rdi
callq 0x11a0
movq %r12, %rdi
movq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0x1cf5c
movq %r15, %rdi
callq 0x11a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b644
testq %rbp, %rbp
je 0x1397a
movq 0x10(%rbp), %r14
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1d07c
movq %r14, %rbp
testq %r14, %r14
jne 0x13963
movq (%rsp), %r14
incq %r13
movq %r12, %rbp
cmpq 0x8(%rsp), %r13
jbe 0x13896
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b644
testq %r12, %r12
je 0x139b7
movq 0x10(%r12), %r14
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1d07c
movq %r14, %r12
testq %r14, %r14
jne 0x1399f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq