// File: /workspace/github_c_makefile_star2_O1/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 0xf2e6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r15
movslq (%rcx), %r8
testq %r8, %r8
jle 0xf2d8
movl %esi, %r12d
movq %rdi, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
imulq $0x68, %r8, %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl %ebx, %esi
movl 0x28(%r15,%rcx), %ebx
cmpl %ebx, %esi
cmovgl %esi, %ebx
addq $0x68, %rcx
cmpq %rcx, %rax
jne 0xf0a9
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x14(%rsp)
movq %r8, 0x28(%rsp)
movl %r8d, %r10d
xorl %ebp, %ebp
movq %r15, %r14
xorl %r13d, %r13d
xorl %r11d, %r11d
movss %xmm0, 0x4(%rsp)
movq %r10, 0x18(%rsp)
movl %edx, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movl 0xc(%r14), %eax
cmpq %rax, %rbp
jne 0xf11c
movslq %r13d, %rax
incl %r13d
imulq $0x68, %rax, %rdi
addq %r15, %rdi
movl $0xd, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
jmp 0xf2a9
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 %r12d, %r9d
cmpl %esi, %r9d
setge %r9b
orb %r8b, %r9b
cmpl %edx, %r11d
setl %sil
andb %r9b, %sil
cmpb $0x1, %sil
jne 0xf201
movl 0x34(%r14), %ecx
cmpl 0x34(%rax), %ecx
jne 0xf25f
movl 0x38(%r14), %ecx
cmpl 0x38(%rax), %ecx
jne 0xf25f
movl 0x30(%r14), %ecx
cmpl 0x30(%rax), %ecx
jne 0xf25f
movq 0x40(%r14), %rcx
cmpq 0x40(%rax), %rcx
jne 0xf25f
movq 0x48(%r14), %rcx
cmpq 0x48(%rax), %rcx
jne 0xf25f
testq %rdi, %rdi
je 0xf2a9
movl %r11d, 0xc(%rsp)
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
movl 0xc(%rsp), %r11d
movq 0x18(%rsp), %r10
movss 0x4(%rsp), %xmm0
movl 0x8(%rsp), %edx
jmp 0xf2a9
testq %rdi, %rdi
jne 0xf27c
testq %rcx, %rcx
jne 0xf27c
testl %ebx, %ebx
jle 0xf27c
xorps %xmm1, %xmm1
cvtsi2ssl 0x28(%r14), %xmm1
cmpl %edx, %r11d
setl %cl
ucomiss 0x14(%rsp), %xmm1
setae %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0xf27c
movl 0x34(%r14), %ecx
cmpl 0x34(%rax), %ecx
jne 0xf25f
movl 0x38(%r14), %ecx
cmpl 0x38(%rax), %ecx
jne 0xf25f
movl 0x30(%r14), %ecx
cmpl 0x30(%rax), %ecx
jne 0xf25f
movq 0x40(%r14), %rcx
cmpq 0x40(%rax), %rcx
jne 0xf25f
movq 0x48(%r14), %rcx
cmpq 0x48(%rax), %rcx
je 0xf2a9
movslq %r13d, %rax
incl %r13d
imulq $0x68, %rax, %rdi
addq %r15, %rdi
movl $0xd, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
incl %r11d
jmp 0xf2a9
testq %rdi, %rdi
je 0xf2a9
movl %r11d, %r12d
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
movl %r12d, %r11d
movq 0x18(%rsp), %r10
movss 0x4(%rsp), %xmm0
movl 0x8(%rsp), %edx
movl 0x10(%rsp), %r12d
incq %rbp
addq $0x68, %r14
cmpq %rbp, %r10
jne 0xf0f6
cmpl 0x28(%rsp), %r13d
je 0xf2d0
movq 0x20(%rsp), %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0xef79
movq 0x30(%rsp), %rax
movl %r13d, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq