// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/pe.c
// Function: mm_select_sub_multi
void mm_select_sub_multi(void *km, float pri_ratio, float pri1, float pri2, int max_gap_ref, int min_diff, int best_n, int n_segs, const int *qlens, int *n_, mm_reg1_t *r)
{
	if (pri_ratio > 0.0f && *n_ > 0) {
		int i, k, n = *n_, n_2nd = 0;
		int max_dist = n_segs == 2? qlens[0] + qlens[1] + max_gap_ref : 0;
		for (i = k = 0; i < n; ++i) {
			int to_keep = 0;
			if (r[i].parent == i) { // primary
				to_keep = 1;
			} else if (r[i].score + min_diff >= r[r[i].parent].score) {
				to_keep = 1;
			} else {
				mm_reg1_t *p = &r[r[i].parent], *q = &r[i];
				if (p->rev == q->rev && p->rid == q->rid && q->re - p->rs < max_dist && p->re - q->rs < max_dist) { // child and parent are close on the ref
					if (q->score >= p->score * pri1)
						to_keep = 1;
				} else {
					int is_par_both = (n_segs == 2 && p->qs < qlens[0] && p->qe > qlens[0]);
					int is_chi_both = (n_segs == 2 && q->qs < qlens[0] && q->qe > qlens[0]);
					if (is_chi_both || is_chi_both == is_par_both) {
						if (q->score >= p->score * pri_ratio)
							to_keep = 1;
					} else { // the remaining case: is_chi_both == 0 && is_par_both == 1
						if (q->score >= p->score * pri2)
							to_keep = 1;
					}
				}
			}
			if (to_keep && r[i].parent != i) {
				if (n_2nd++ >= best_n) to_keep = 0; // don't keep if there are too many secondary hits
			}
			if (to_keep) r[k++] = r[i];
			else if (r[i].p) free(r[i].p);
		}
		if (k != n) mm_sync_regs(km, k, r); // removing hits requires sync()
		*n_ = k;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movss %xmm1, -0x10(%rbp)
movss %xmm2, -0x14(%rbp)
movl %esi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movss -0xc(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x182db
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x182db
movq 0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x2, -0x24(%rbp)
jne 0x17fed
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
addl 0x4(%rcx), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x17ff4
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0x17ff4
movl -0x64(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x182ba
movl $0x0, -0x48(%rbp)
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
cmpl -0x34(%rbp), %eax
jne 0x1803e
movl $0x1, -0x48(%rbp)
jmp 0x1820b
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
addl -0x1c(%rbp), %eax
movq 0x18(%rbp), %rcx
movq 0x18(%rbp), %rdx
movslq -0x34(%rbp), %rsi
imulq $0x50, %rsi, %rsi
addq %rsi, %rdx
movslq 0x20(%rdx), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jl 0x18082
movl $0x1, -0x48(%rbp)
jmp 0x18209
movq 0x18(%rbp), %rax
movq 0x18(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
movslq 0x20(%rcx), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movl 0x3c(%rax), %eax
shrl $0xa, %eax
andl $0x1, %eax
movq -0x58(%rbp), %rcx
movl 0x3c(%rcx), %ecx
shrl $0xa, %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
jne 0x18133
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x18133
movq -0x58(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x18(%rcx), %eax
cmpl -0x44(%rbp), %eax
jge 0x18133
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x18(%rcx), %eax
cmpl -0x44(%rbp), %eax
jge 0x18133
movq -0x58(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm0
movq -0x50(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm1
mulss -0x10(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jb 0x1812e
movl $0x1, -0x48(%rbp)
jmp 0x18207
xorl %eax, %eax
cmpl $0x2, -0x24(%rbp)
movb %al, -0x65(%rbp)
jne 0x18165
movq -0x50(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x65(%rbp)
jge 0x18165
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
setg %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x5c(%rbp)
xorl %eax, %eax
cmpl $0x2, -0x24(%rbp)
movb %al, -0x66(%rbp)
jne 0x181a2
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x66(%rbp)
jge 0x181a2
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
setg %al
movb %al, -0x66(%rbp)
movb -0x66(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
jne 0x181bb
movl -0x60(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jne 0x181e0
movq -0x58(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm0
movq -0x50(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm1
mulss -0xc(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jb 0x181de
movl $0x1, -0x48(%rbp)
jmp 0x18205
movq -0x58(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm0
movq -0x50(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm1
mulss -0x14(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jb 0x18203
movl $0x1, -0x48(%rbp)
jmp 0x18205
jmp 0x18207
jmp 0x18209
jmp 0x1820b
cmpl $0x0, -0x48(%rbp)
je 0x18241
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
cmpl -0x34(%rbp), %eax
je 0x18241
movl -0x40(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp)
cmpl -0x20(%rbp), %eax
jl 0x1823f
movl $0x0, -0x48(%rbp)
jmp 0x18241
cmpl $0x0, -0x48(%rbp)
je 0x1827a
movq 0x18(%rbp), %rdi
movl -0x38(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x38(%rbp)
cltq
imulq $0x50, %rax, %rax
addq %rax, %rdi
movq 0x18(%rbp), %rsi
movslq -0x34(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rsi
movl $0x50, %edx
callq 0x2290
jmp 0x182aa
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x48(%rax)
je 0x182a8
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rdi
callq 0x2040
jmp 0x182aa
jmp 0x182ac
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x18008
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x182d2
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
movq 0x18(%rbp), %rdx
callq 0x2ae60
movl -0x38(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)