// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/lwm_miningAndExtension.c
// Function: BFSStrategy
void BFSStrategy(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) {

	// 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 = _BFSgetNextLevel(previousLevelSupportSets, previousLevelSearchTree, threshold, extensionEdges, embeddingOperator, importance, &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;
	}

//	madness(currentLevelSupportSets, currentLevelSearchTree, extensionEdges, maxPatternSize, threshold, &previousLevelSupportSets, &previousLevelSearchTree, featureStream, patternStream, logStream, gp, sgp);

	// 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 $0xc8, %rsp
movsd %xmm0, 0x98(%rsp)
movq %r9, 0x80(%rsp)
movq %r8, 0x28(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x120(%rsp), %rbp
movq %rcx, %rdi
movq %rbp, %rsi
callq 0x1b598
movq %rax, %r12
incq %r14
movq %rbx, 0x70(%rsp)
cmpq %rbx, %r14
ja 0x1303b
movq 0x128(%rsp), %r15
movq 0x28(%rsp), %rax
cmpl $0x0, 0x18(%r12)
jle 0x13036
movq 0x118(%rsp), %rbx
movq %rbx, %rdi
movq %rax, 0x50(%rsp)
leaq 0xddc2(%rip), %rsi      # 0x20982
movq %r14, 0x78(%rsp)
movq %r14, %rdx
xorl %eax, %eax
callq 0x1160
movq %rbx, %rdi
callq 0x11a0
movq 0x10(%rbp), %rdi
callq 0x1447e
movq %r12, 0x68(%rsp)
movl 0x20(%r12), %esi
movq %rax, 0x58(%rsp)
movq %rax, %rdi
callq 0x1b0bb
movq 0x10(%rbp), %rdi
callq 0x1447e
movq 0x50(%rsp), %rcx
movq %rax, %r14
testq %rcx, %rcx
je 0x12d97
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x28(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x48(%rsp)
movq %rcx, 0x88(%rsp)
movq (%rcx), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x90(%rsp)
movq 0x80(%rsp), %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x1d78b
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x86c8
movq %rax, %r12
testq %rax, %rax
je 0x12d80
movq %r12, %rdi
movq %r15, %rsi
callq 0x7938
movl 0x28(%r14), %ebx
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x1ae1e
cmpl 0x28(%r14), %ebx
je 0x12d27
incl 0x28(%rsp)
movq %r12, %rdi
movq 0x68(%rsp), %rsi
movq %r15, %rcx
movq %rbp, %r15
movq %rbp, %rdx
callq 0x1d8da
testq %rax, %rax
je 0x12d1c
movq %rax, %rbp
incl 0x34(%rsp)
movq 0x90(%rsp), %rax
movl 0x8(%rax), %edx
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
callq 0x12ae8
movq %rax, %rbx
movq %rbp, %rdi
callq 0x9b28
movq 0x60(%rsp), %rax
cmpq %rax, 0x18(%rbx)
jae 0x12d34
movq %r15, %rbp
movq %r15, %rdi
movq %r12, %rsi
callq 0x14700
movq %rbx, %rdi
callq 0x1ce4c
jmp 0x12d60
movq %r15, %rbp
movq 0x128(%rsp), %r15
movq %rbp, %rdi
movq %r12, %rsi
callq 0x14700
jmp 0x12d68
movq 0x48(%rsp), %rax
incl %eax
movq %rax, 0x48(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x18(%r12)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rbx)
movq %rbx, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %r15, %rbp
movq 0x128(%rsp), %r15
leaq 0xa0(%rsp), %rdi
callq 0x86c8
movq %rax, %r12
incl %r13d
jmp 0x12c81
movq 0x88(%rsp), %rcx
movq 0x10(%rcx), %rcx
testq %rcx, %rcx
jne 0x12c3f
jmp 0x12dc5
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x28(%rsp)
xorl %r13d, %r13d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1b546
movq 0x118(%rsp), %rdi
leaq 0xdbe2(%rip), %rsi      # 0x209c1
movl %r13d, %edx
movl 0x28(%rsp), %ecx
movl 0x34(%rsp), %r8d
movq 0x48(%rsp), %r9
xorl %eax, %eax
callq 0x1160
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x12f31
movq $0x0, 0x28(%rsp)
xorl %r12d, %r12d
movq 0x38(%rsp), %r14
xorl %eax, %eax
callq 0x1ce22
movq %rax, %r15
movq (%rbx), %r13
testq %r13, %r13
je 0x12ec8
movq 0x20(%r13), %rax
movq %rax, 0x20(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
movsd 0x98(%rsp), %xmm0
movq %rbp, %rdx
movq 0x128(%rsp), %rcx
callq *0x100(%rsp)
cmpl $0x0, 0xc0(%rsp)
je 0x12ea8
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0xa0(%rsp), %xmm0
movups 0xb0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x1cc1f
jmp 0x12ebf
movq 0xa8(%rsp), %rax
movq 0xb8(%rsp), %rdi
movl (%rax), %esi
callq 0x161f7
movq 0x28(%r13), %r13
jmp 0x12e23
movq 0x18(%r15), %rax
cmpq 0x60(%rsp), %rax
jae 0x12ee5
movl $0x0, 0xc(%r14)
movq %r15, %rdi
callq 0x1ce92
jmp 0x12f00
movl %eax, 0xc(%r14)
testq %r12, %r12
je 0x12ef8
movq %r15, 0x10(%r12)
movq %r15, %r12
jmp 0x12f00
movq %r15, %r12
movq %r15, 0x28(%rsp)
movq 0x18(%r14), %r14
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x12e16
movq 0x40(%rsp), %rdi
movq 0x10(%rdi), %rbx
callq 0x1ce4c
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x12f16
movq 0x128(%rsp), %r15
jmp 0x12f3a
movq $0x0, 0x28(%rsp)
movq 0x58(%rsp), %r12
movq 0x38(%rsp), %rsi
xorl %r14d, %r14d
testq %rsi, %rsi
je 0x12fa2
movq 0x18(%rsi), %rbx
movq $0x0, 0x18(%rsi)
cmpl $0x0, 0xc(%rsi)
je 0x12f92
incl %r14d
movq %rsi, %rdi
movq %rsi, %r13
movq %r15, %rsi
callq 0x7938
movl 0xc(%r13), %ecx
movl %ecx, 0x28(%rax)
movq %r12, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x1ae89
movl 0x20(%r12), %eax
movl %eax, 0x8(%r13)
jmp 0x12f9a
movq %rbp, %rdi
callq 0x14700
movq %rbx, %rsi
testq %rbx, %rbx
jne 0x12f4c
movq 0x118(%rsp), %rdi
leaq 0xd9f9(%rip), %rsi      # 0x209aa
movl %r14d, %edx
xorl %eax, %eax
callq 0x1160
movq %r12, %rdi
movq 0x110(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1b764
movq %rbx, %rdi
callq 0x11a0
movq 0x28(%rsp), %rdi
movq 0x108(%rsp), %rbx
movq %rbx, %rsi
callq 0x1cdf7
movq %rbx, %rdi
callq 0x11a0
movq %rbp, %rdi
movq 0x68(%rsp), %rsi
callq 0x1b546
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x13021
movq 0x10(%rdi), %rbx
movq %rbp, %rsi
callq 0x1cf17
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x1300d
movq 0x78(%rsp), %r14
incq %r14
cmpq 0x70(%rsp), %r14
jbe 0x12b98
jmp 0x1303b
movq %rax, 0x28(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b546
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x13064
movq 0x10(%rdi), %rbx
movq %rbp, %rsi
callq 0x1cf17
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x13050
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop