// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/hit.c
// Function: mp_select_sub
void mp_select_sub(void *km, float pri_ratio, int min_diff, int best_n, int *n_, mp_reg1_t *r)
{
	if (pri_ratio > 0.0f && *n_ > 0) {
		int i, k, n = *n_, n_2nd = 0, chn_sc_ungap = -1;
		for (i = 0; i < n; ++i) // find the largest chn_sc_ungap
			chn_sc_ungap = chn_sc_ungap > r[i].chn_sc_ungap? chn_sc_ungap : r[i].chn_sc_ungap;
		for (i = k = 0; i < n; ++i) {
			int p = r[i].parent;
			int sci = r[i].p? r[i].p->dp_max : r[i].chn_sc;
			int scp = r[p].p? r[p].p->dp_max : r[p].chn_sc;
			if (p == i) { // primary or inversion
				r[k++] = r[i];
			} else if ((sci >= scp * pri_ratio || sci + min_diff >= scp) && n_2nd < best_n) {
				if (!(r[i].qs == r[p].qs && r[i].qe == r[p].qe && r[i].vid == r[p].vid && r[i].vs == r[p].vs && r[i].ve == r[p].ve)) // not identical hits
					r[k++] = r[i], ++n_2nd;
				else if (r[i].p) { free(r[i].p); free(r[i].feat); }
			} else if (r[i].p == 0 && r[p].p == 0 && chn_sc_ungap > 0 && r[i].chn_sc_ungap >= chn_sc_ungap * pri_ratio && n_2nd < best_n) {
				if (!(r[i].qs == r[p].qs && r[i].qe == r[p].qe && r[i].vid == r[p].vid && r[i].vs == r[p].vs && r[i].ve == r[p].ve)) // not identical hits
					r[k++] = r[i], ++n_2nd;
			} else if (r[i].p) { free(r[i].p); free(r[i].feat); }
		}
		if (k != n) mp_sync_regs(km, k, r); // removing hits requires sync()
		*n_ = k;
	}
}

// Assembly:
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xf685
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movslq (%rcx), %r13
testq %r13, %r13
jle 0xf677
movq %r8, %r15
movl %esi, %ebx
movq %rdi, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
imulq $0x68, %r13, %rax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl %r12d, %esi
movl 0x28(%r15,%rcx), %r12d
cmpl %r12d, %esi
cmovgl %esi, %r12d
addq $0x68, %rcx
cmpq %rcx, %rax
jne 0xf438
xorps %xmm1, %xmm1
cvtsi2ss %r12d, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x10(%rsp)
xorl %ebp, %ebp
movq %r15, %r14
xorl %r10d, %r10d
xorl %r11d, %r11d
movss %xmm0, (%rsp)
movq %r15, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movl %ebx, 0x14(%rsp)
movl 0xc(%r14), %eax
cmpq %rax, %rbp
jne 0xf4a6
movslq %r10d, %rax
incl %r10d
imulq $0x68, %rax, %rdi
addq %r15, %rdi
movl $0xd, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
jmp 0xf644
movq 0x60(%r14), %rdi
cltq
imulq $0x68, %rax, %rcx
leaq (%r15,%rcx), %rax
movq 0x60(%r15,%rcx), %rcx
leaq 0x24(%rax), %r8
leaq 0x4(%rcx), %rsi
testq %rcx, %rcx
cmoveq %r8, %rsi
leaq 0x24(%r14), %r9
leaq 0x4(%rdi), %r8
testq %rdi, %rdi
cmoveq %r9, %r8
movl (%r8), %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9d, %xmm2
movl (%rsi), %esi
xorps %xmm1, %xmm1
cvtsi2ss %esi, %xmm1
mulss %xmm0, %xmm1
ucomiss %xmm1, %xmm2
setae %r8b
addl %ebx, %r9d
cmpl %esi, %r9d
setge %r9b
orb %r8b, %r9b
cmpl %edx, %r11d
setl %sil
andb %r9b, %sil
cmpb $0x1, %sil
jne 0xf597
movl 0x34(%r14), %ecx
cmpl 0x34(%rax), %ecx
jne 0xf629
movl 0x38(%r14), %ecx
cmpl 0x38(%rax), %ecx
jne 0xf629
movl 0x30(%r14), %ecx
cmpl 0x30(%rax), %ecx
jne 0xf629
movq 0x40(%r14), %rcx
cmpq 0x40(%rax), %rcx
jne 0xf629
movq 0x48(%r14), %rcx
cmpq 0x48(%rax), %rcx
jne 0xf629
testq %rdi, %rdi
je 0xf644
movl %edx, 0xc(%rsp)
movl %r10d, 0x8(%rsp)
movl %r11d, 0x4(%rsp)
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
movl 0x4(%rsp), %r11d
movl 0x8(%rsp), %r10d
movss (%rsp), %xmm0
movl 0xc(%rsp), %edx
jmp 0xf644
testq %rdi, %rdi
je 0xf5cf
movl %edx, %ebx
movl %r10d, %r15d
movl %r11d, %r13d
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
movl %r13d, %r11d
movl %r15d, %r10d
movss (%rsp), %xmm0
movl %ebx, %edx
movl 0x14(%rsp), %ebx
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %r15
jmp 0xf644
testq %rcx, %rcx
jne 0xf644
testl %r12d, %r12d
jle 0xf644
xorps %xmm1, %xmm1
cvtsi2ssl 0x28(%r14), %xmm1
cmpl %edx, %r11d
setl %cl
ucomiss 0x10(%rsp), %xmm1
setae %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0xf644
movl 0x34(%r14), %ecx
cmpl 0x34(%rax), %ecx
jne 0xf629
movl 0x38(%r14), %ecx
cmpl 0x38(%rax), %ecx
jne 0xf629
movl 0x30(%r14), %ecx
cmpl 0x30(%rax), %ecx
jne 0xf629
movq 0x40(%r14), %rcx
cmpq 0x40(%rax), %rcx
jne 0xf629
movq 0x48(%r14), %rcx
cmpq 0x48(%rax), %rcx
je 0xf644
movslq %r10d, %rax
incl %r10d
imulq $0x68, %rax, %rdi
addq %r15, %rdi
movl $0xd, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
incl %r11d
incq %rbp
addq $0x68, %r14
cmpq %rbp, %r13
jne 0xf480
cmpl %r13d, %r10d
je 0xf66f
movq 0x18(%rsp), %rdi
movl %r10d, %esi
movq %r15, %rdx
movl %r10d, %ebx
callq 0xf322
movl %ebx, %r10d
movq 0x20(%rsp), %rax
movl %r10d, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq