// File: /workspace/github_c_makefile_star2_O3/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, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r13
movq 0x90(%rsp), %rbx
movq %rcx, %rdi
movq %rbx, %rsi
callq 0x1b598
movq %rax, %r14
incq %r13
movq %r15, 0x8(%rsp)
cmpq %r15, %r13
jbe 0x13769
movq %rbp, %r15
movq %r14, %rsi
jmp 0x13872
cmpl $0x0, 0x18(%r14)
jle 0x1375e
movq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0xd200(%rip), %rsi      # 0x20982
movq %r13, %rdx
xorl %eax, %eax
callq 0x1160
movq %r15, %rdi
callq 0x11a0
movq 0x10(%rbx), %rdi
callq 0x1447e
movq %rax, %r12
movq %rax, 0x30(%rsp)
movl 0x20(%r14), %esi
movq %rax, %rdi
callq 0x1b0bb
subq $0x8, %rsp
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x28(%rsp), %xmm0
movq 0xa0(%rsp), %rax
pushq %rax
pushq %rbx
pushq %r15
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x1
callq 0x138a5
addq $0x30, %rsp
movq %rax, %r15
movq %r12, 0x28(%rsp)
movq %r12, %rdi
movq 0x80(%rsp), %r12
movq %r12, %rsi
movq 0x98(%rsp), %rdx
callq 0x1b764
movq %r12, %rdi
callq 0x11a0
movq %r15, %rdi
movq 0x78(%rsp), %r12
movq %r12, %rsi
callq 0x1cdf7
movq %r12, %rdi
callq 0x11a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b546
testq %rbp, %rbp
je 0x13859
movq 0x10(%rbp), %r14
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1cf17
movq %r14, %rbp
testq %r14, %r14
jne 0x13842
incq %r13
movq 0x28(%rsp), %rsi
movq %rsi, %r14
movq %r15, %rbp
cmpq 0x8(%rsp), %r13
jbe 0x13769
movq %rbx, %rdi
callq 0x1b546
testq %r15, %r15
je 0x13896
movq 0x10(%r15), %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1cf17
movq %r14, %r15
testq %r14, %r14
jne 0x1387f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq