// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movq 0xb8(%rsp), %r14
leaq (,%r14,4), %rbp
movq %rbp, %rdi
callq 0x1190
testq %rax, %rax
jne 0x155d2
callq 0x1e90
xorl %ebx, %ebx
jmp 0x15664
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq (%rax), %r12
movslq (%r12), %rax
testq %rax, %rax
jle 0x1561a
leaq 0x90(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x10(%r12), %rcx
movq 0x10(%rdx), %rdx
xorl %esi, %esi
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
movl %esi, 0x1c(%r8)
movq (%rdx,%rdi,8), %r8
movl %esi, 0x1c(%r8)
incq %rdi
cmpq %rdi, %rax
jne 0x15602
testq %r14, %r14
je 0x1562f
movq %rbx, %rdi
movl $0xff, %esi
movq %rbp, %rdx
callq 0x10d0
leaq 0x90(%rsp), %rax
movq 0x20(%rax), %r14
movl $0x0, 0x34(%rsp)
testq %r14, %r14
jne 0x15676
movq 0x179a9(%rip), %rax     # 0x2cff8
movq (%rax), %rdi
leaq 0xa9dd(%rip), %rsi      # 0x20036
movl 0x34(%rsp), %edx
xorl %eax, %eax
callq 0x1160
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rax), %r15
movq 0x18(%rax), %r13
movq (%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
addq $0x8, %r15
movl $0x0, 0x34(%rsp)
movq (%r15), %rax
cmpl $-0x1, (%rbx,%rax,4)
je 0x156af
addq $0x10, %r15
decq %r14
jne 0x1569b
jmp 0x15648
movq -0x8(%r15), %rcx
movq (%r13,%rax,8), %rdx
movslq (%rdx,%rcx,4), %rbp
movq 0x10(%r12), %rdx
movq (%rdx,%rbp,8), %rdx
movl 0x1c(%rdx), %esi
testl %esi, %esi
je 0x156d6
cmpl $0x1, %esi
jne 0x156a4
movl %ecx, (%rbx,%rax,4)
jmp 0x156a4
movq (%rdx), %rsi
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rdx
callq 0xabfd
incl 0x34(%rsp)
testb %al, %al
je 0x15728
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rdi
leaq 0x90(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x15417
jmp 0x156a4
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rdi
leaq 0x90(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x15484
jmp 0x156a4