// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/minhashing.c
// Function: buildMinHashEvaluationPlan
struct EvaluationPlan buildMinHashEvaluationPlan(int** shrunkPermutations, size_t* permutationSizes, size_t K, struct Graph* F, struct GraphPool* gp) {
	struct EvaluationPlan p = {0};
	p.poset = F;
	p.reversePoset = reverseGraph(F, gp);
	p.sketchSize = K;
	p.shrunkPermutations = shrunkPermutations;

	size_t maxPermutationSize = 0;
	for (size_t i=0; i<K; ++i) {
		p.orderLength += permutationSizes[i];
		if (permutationSizes[i] > maxPermutationSize) {
			maxPermutationSize = permutationSizes[i];
		}
	}
	p.order = malloc(p.orderLength * sizeof(struct PosPair));
	if (p.order) {
		// fix some evaluation order.
		size_t position = 0;
		for (size_t level=0; level<maxPermutationSize; ++level) {
			size_t old_pos = position;
			for (size_t i=0; i<K; ++i) {
				if (level < permutationSizes[i]) {
					p.order[position].level = level;
					p.order[position].permutation = i;
					++position;
				}
			}
			// sort current level of the permutations based on the pattern id. This ensures that lower level
			// patterns come before higher level patterns in each level of the order.
			qsort_r(&(p.order[old_pos]), position - old_pos, sizeof(struct PosPair), &posPairSorter, &p);
		}

	} else {
		fprintf(stderr, "could not allocate space for evaluation plan. this program will break now.\n");
		p.poset = NULL;
		p.order = NULL;
		p.shrunkPermutations = NULL;
		p.orderLength = 0;
		p.sketchSize = 0;

	}

	free(permutationSizes); // we do not need this information any more
	return p;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x8(%rsp)
movq %rdi, %rax
movq %rax, (%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %r9, 0x40(%rsp)
xorl %esi, %esi
movl $0x30, %edx
callq 0x10b0
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, (%rdi)
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x20480
movq 0x8(%rsp), %rdi
movq %rax, 0x8(%rdi)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rdi)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rdi)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x2067f
movq 0x8(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq 0x58(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpq 0x38(%rsp), %rax
jbe 0x2066d
movq 0x58(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
jmp 0x2066f
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x2061e
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
shlq $0x4, %rdi
callq 0x1170
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x10(%rax)
je 0x20799
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x38(%rsp), %rax
jae 0x20797
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x50(%rsp), %rax
jae 0x20754
movq 0x20(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x10(%rsp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x20742
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rdx
movq 0x10(%rax), %rcx
movq 0x28(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rcx
movq %rdx, (%rcx)
movq 0x10(%rsp), %rcx
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x20744
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x206dd
movq 0x8(%rsp), %r8
movq 0x10(%r8), %rdi
movq 0x18(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq 0x28(%rsp), %rsi
subq 0x18(%rsp), %rsi
movl $0x10, %edx
leaq -0x39f(%rip), %rcx      # 0x203e0
callq 0x1160
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x206ba
jmp 0x207dd
movq 0x1d858(%rip), %rax     # 0x3dff8
movq (%rax), %rdi
leaq 0x153d8(%rip), %rsi     # 0x35b82
movb $0x0, %al
callq 0x1140
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
movq $0x0, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x20(%rax)
movq $0x0, 0x28(%rax)
movq 0x58(%rsp), %rdi
callq 0x1030
movq (%rsp), %rax
addq $0x68, %rsp
retq