// File: /workspace/github_c_makefile_star2_O2/pwelke[P]GraphMiningTools/minhashing.c
// Function: fastMinHashForTrees
int* fastMinHashForTrees(struct Graph* g, struct EvaluationPlan p, struct GraphPool* gp) {
	int* sketch = malloc(p.sketchSize * sizeof(int));
	if (!sketch) {
		fprintf(stderr, "Could not allocate memory for sketch. This is a bad thing.\n");
		return NULL;
	}
	int nEvaluations = 0;

	cleanEvaluationPlan(p);

	for (size_t i=0; i<p.sketchSize; ++i) {
		sketch[i] = -1; // init sketch values to 'infty'
	}
	for (size_t i=0; i<p.orderLength; ++i) {
		struct PosPair current = p.order[i];
		int currentGraphNumber = p.shrunkPermutations[current.permutation][current.level];

		// check if we already found level min for the permutation
		if (sketch[current.permutation] != -1) {
			continue;
		}

		// check if we already evaluated the embedding operator for this pattern or found a subpattern that had no match
		if (p.poset->vertices[currentGraphNumber]->visited != 0) {
			// either the pattern with id currentGraphNumber was evaluated positively and we hence have found the
			// min value for the current permutation or we need to continue
			if (p.poset->vertices[currentGraphNumber]->visited == 1) {
				sketch[current.permutation] = current.level;
			}
			continue;
		}

		// evaluate the embedding operator
		struct Graph* currentGraph = (struct Graph*)(p.poset->vertices[currentGraphNumber]->label);
		char match = isSubtree(g, currentGraph, gp);
		++nEvaluations;

		updateEvaluationPlan(p, currentGraphNumber, match);
	}

	fprintf(stderr, "%i\n", nEvaluations);
	return sketch;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movq 0xa8(%rsp), %r15
leaq (,%r15,4), %rdi
callq 0x1180
movq %rax, %rbx
testq %rax, %rax
jne 0x1228c
movq 0x17d86(%rip), %rax     # 0x29ff8
movq (%rax), %rcx
leaq 0xb94a(%rip), %rdi      # 0x1dbc6
pushq $0x3b
popq %rsi
pushq $0x1
popq %rdx
callq 0x1210
jmp 0x12393
leaq 0x80(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %rax
movl (%r14), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x122c7
movq 0x10(%r14), %rsi
movq (%rsi,%rdx,8), %rsi
andl $0x0, 0x1c(%rsi)
movq 0x10(%rax), %rsi
movq (%rsi,%rdx,8), %rsi
andl $0x0, 0x1c(%rsi)
incq %rdx
jmp 0x122a5
xorl %eax, %eax
cmpq %rax, %r15
je 0x122d7
orl $-0x1, (%rbx,%rax,4)
incq %rax
jmp 0x122c9
leaq 0x80(%rsp), %rax
movq 0x20(%rax), %r15
movq 0x10(%rax), %r13
movq 0x18(%rax), %rbp
addq $0x8, %r13
movl $0x0, 0x34(%rsp)
subq $0x1, %r15
jb 0x12377
movq (%r13), %rax
cmpl $-0x1, (%rbx,%rax,4)
je 0x1230d
addq $0x10, %r13
jmp 0x122f7
movq -0x8(%r13), %rcx
movq (%rbp,%rax,8), %rdx
movslq (%rdx,%rcx,4), %r12
movq 0x10(%r14), %rdx
movq (%rdx,%r12,8), %rdx
movl 0x1c(%rdx), %esi
testl %esi, %esi
je 0x12333
cmpl $0x1, %esi
jne 0x12307
movl %ecx, (%rbx,%rax,4)
jmp 0x12307
movq (%rdx), %rsi
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
callq 0x86b2
incl 0x34(%rsp)
leaq 0x80(%rsp), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movsbl %al, %esi
movl %r12d, %edi
callq 0x120b2
jmp 0x12307
movq 0x17c7a(%rip), %rax     # 0x29ff8
movq (%rax), %rdi
leaq 0xacae(%rip), %rsi      # 0x1d036
movl 0x34(%rsp), %edx
xorl %eax, %eax
callq 0x1150
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq