// File: /workspace/github_c_makefile_star2_O2/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 0xdae4
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movslq (%rcx), %r15
testq %r15, %r15
jle 0xdad6
movq %r8, %rbx
movl %edx, %r10d
movl %esi, %r13d
imulq $0x68, %r15, %rax
pushq $-0x1
popq %r12
xorl %esi, %esi
cmpq %rsi, %rax
je 0xd8c2
movl 0x28(%rbx,%rsi), %edx
cmpl %edx, %r12d
cmovlel %edx, %r12d
addq $0x68, %rsi
jmp 0xd8ac
movq %rdi, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
cvtsi2ss %r12d, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x1c(%rsp)
xorl %ebp, %ebp
pushq $0xd
popq %r11
movq %rbx, %r14
movl $0x0, 0x10(%rsp)
xorl %edx, %edx
movss %xmm0, 0x14(%rsp)
movq %rbx, 0x30(%rsp)
cmpq %rbp, %r15
je 0xdab7
movl 0xc(%r14), %ecx
movslq %edx, %rax
cmpq %rcx, %rbp
jne 0xd926
leal 0x1(%rax), %edx
imulq $0x68, %rax, %rdi
addq %rbx, %rdi
movq %r11, %rcx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
jmp 0xdaab
movl %edx, 0xc(%rsp)
movq 0x60(%r14), %rdi
movslq %ecx, %rcx
imulq $0x68, %rcx, %rdx
leaq (%rbx,%rdx), %rcx
movq 0x60(%rbx,%rdx), %rdx
leaq 0x24(%rcx), %rsi
leaq 0x4(%rdx), %r8
testq %rdx, %rdx
cmoveq %rsi, %r8
leaq 0x24(%r14), %rsi
leaq 0x4(%rdi), %r9
testq %rdi, %rdi
cmoveq %rsi, %r9
movl (%r9), %esi
cvtsi2ss %esi, %xmm2
movl (%r8), %r8d
cvtsi2ss %r8d, %xmm1
mulss %xmm0, %xmm1
ucomiss %xmm1, %xmm2
setae %r9b
addl %r13d, %esi
cmpl %r8d, %esi
setge %sil
orb %r9b, %sil
cmpl %r10d, 0x10(%rsp)
setl %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0xda01
movl 0x34(%r14), %edx
cmpl 0x34(%rcx), %edx
jne 0xda94
movl 0x38(%r14), %edx
cmpl 0x38(%rcx), %edx
jne 0xda94
movl 0x30(%r14), %edx
cmpl 0x30(%rcx), %edx
jne 0xda94
movq 0x40(%r14), %rdx
cmpq 0x40(%rcx), %rdx
jne 0xda94
movq 0x48(%r14), %rdx
cmpq 0x48(%rcx), %rdx
jne 0xda94
testq %rdi, %rdi
je 0xda35
movl %r10d, 0x18(%rsp)
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
pushq $0xd
popq %r11
movss 0x14(%rsp), %xmm0
movl 0x18(%rsp), %r10d
jmp 0xda35
testq %rdi, %rdi
je 0xda3b
movq %r15, %rbx
movl %r13d, %r15d
movl %r10d, %r13d
callq 0x2050
movq 0x58(%r14), %rdi
callq 0x2050
pushq $0xd
popq %r11
movss 0x14(%rsp), %xmm0
movl %r13d, %r10d
movl %r15d, %r13d
movq %rbx, %r15
movq 0x30(%rsp), %rbx
movl 0xc(%rsp), %edx
jmp 0xdaab
testq %rdx, %rdx
jne 0xda35
testl %r12d, %r12d
jle 0xda35
cvtsi2ssl 0x28(%r14), %xmm1
cmpl %r10d, 0x10(%rsp)
setl %dl
ucomiss 0x1c(%rsp), %xmm1
setae %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xda35
movl 0x34(%r14), %edx
cmpl 0x34(%rcx), %edx
jne 0xda94
movl 0x38(%r14), %edx
cmpl 0x38(%rcx), %edx
jne 0xda94
movl 0x30(%r14), %edx
cmpl 0x30(%rcx), %edx
jne 0xda94
movq 0x40(%r14), %rdx
cmpq 0x40(%rcx), %rdx
jne 0xda94
movq 0x48(%r14), %rdx
cmpq 0x48(%rcx), %rdx
je 0xda35
leal 0x1(%rax), %edx
imulq $0x68, %rax, %rdi
addq %rbx, %rdi
movq %r11, %rcx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
incl 0x10(%rsp)
incq %rbp
addq $0x68, %r14
jmp 0xd8f9
cmpl %r15d, %edx
je 0xdacf
movq 0x20(%rsp), %rdi
movl %edx, %esi
movl %edx, %ebp
movq %rbx, %rdx
callq 0xd7a7
movl %ebp, %edx
movq 0x28(%rsp), %rax
movl %edx, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq