// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: dump_all_chain(kv_ul_ov_t*, kv_ul_ov_t*, long, long, float, float)
void dump_all_chain(kv_ul_ov_t *idx, kv_ul_ov_t *ax, int64_t ax_new_occ, int64_t qlen, float primary_cov_rate, float primary_score_rate) {
	if(idx->n <= 0) return;
	ul_ov_t *m = &(idx->a[idx->n-1]); //largest chain
	ul_ov_t *a = ax->a + ax->n; int64_t k, i, z, l, idx_n = idx->n; uint64_t ovlp;
	if((m->qe-m->qs) > (qlen*primary_cov_rate)) { ///found a primary chain
		for (k = m->ts, l = 0; k < m->te; k++) {
			a[l] = a[k]; a[l].tn |= ((uint32_t)(0x80000000));
			l++;
		}
		ax->n += l;
	} else {
		for (k = idx_n-1; k >= 0; k--) {
			for (i = idx_n-1; i > k; i--) {
				if(idx->a[i].qn == (uint32_t)-1) continue;///just remove totally contained alignments
				if(idx->a[k].qn > idx->a[i].qn*primary_score_rate) continue;///consider score
				ovlp = ((MIN(idx->a[k].qe, idx->a[i].qe) > MAX(idx->a[k].qs, idx->a[i].qs))?
								(MIN(idx->a[k].qe, idx->a[i].qe) - MAX(idx->a[k].qs, idx->a[i].qs)):0);
				if(ovlp > ((idx->a[k].qe-idx->a[k].qs)*primary_cov_rate)) {
					for (z = idx->a[k].ts; z < idx->a[k].te; z++) a[z].el = 1;
					idx->a[k].qn = (uint32_t)-1;
					break;
				}
			}
			// ins_merge_ul_ov(idx, idx_n, idx->n, idx->a[k]);
		}
		for (k = 0, l = 0; k < ax_new_occ; k++) {
			if(a[k].el) continue;
			a[l] = a[k]; l++;
		}
		radix_sort_ul_ov_srt_qe(a, a + l);
		ax->n += l;
	}
}

// Assembly:
movq 0x8(%rdi), %r9
testq %r9, %r9
je 0x1a447f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %rax
movq (%rdi), %r8
leaq -0x1(%r9), %rsi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
leaq -0x1(%r9,%rdi), %r14
movq (%rbx), %r10
movq 0x8(%rbx), %r11
leaq (%r11,%r11,8), %rdi
movl 0x8(%r8,%r14), %r12d
subl 0x4(%r8,%r14), %r12d
leaq (%rdi,%rdi,2), %r15
cvtsi2ss %r12, %xmm2
leaq (%r10,%r11), %rdi
cvtsi2ss %rcx, %xmm3
addq %r15, %rdi
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jbe 0x1a42db
addq %r14, %r8
movl 0x10(%r8), %eax
cmpl 0x14(%r8), %eax
jae 0x1a4450
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
xorl %r14d, %r14d
movups (%rdi,%rcx), %xmm0
movups 0xc(%rdi,%rcx), %xmm1
movups %xmm1, 0xc(%rdi)
movups %xmm0, (%rdi)
orb $-0x80, 0xf(%rdi)
movl 0x14(%r8), %edx
leaq (%rax,%r14), %rsi
incq %rsi
incq %r14
addq $0x1c, %rdi
cmpq %rdx, %rsi
jb 0x1a42ab
jmp 0x1a446d
movq %rbx, 0x8(%rsp)
testq %rsi, %rsi
js 0x1a4411
leaq (%r9,%r9,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r9, %rcx
addq $-0x14, %rcx
addq %r11, %r15
leaq (%r10,%r15), %r8
addq $0x18, %r8
movq %r8, 0x10(%rsp)
movq %rsi, %r9
cmpq %r9, %rsi
jle 0x1a4401
movq (%rax), %r11
leaq (%r9,%r9,8), %r10
leaq (%r10,%r10,2), %r10
addq %r9, %r10
leaq (%r11,%r10), %r14
leaq (%r11,%r10), %r15
addq $0x4, %r15
addq %rcx, %r11
movq %rsi, %r12
movl -0x8(%r11), %ebp
cmpl $-0x1, %ebp
je 0x1a43ab
movl (%r14), %r13d
xorps %xmm2, %xmm2
cvtsi2ss %r13, %xmm2
movl %ebp, %r13d
xorps %xmm3, %xmm3
cvtsi2ss %r13, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm3, %xmm2
ja 0x1a43ab
movl 0x8(%r14), %r13d
movl -0x4(%r11), %ebp
movl (%r11), %r8d
cmpl %r8d, %r13d
cmovbl %r13d, %r8d
movl (%r15), %ebx
cmpl %ebp, %ebx
cmoval %ebx, %ebp
xorps %xmm2, %xmm2
cmpl %ebp, %r8d
jbe 0x1a4396
movl 0x4(%r15), %r8d
movl (%r11), %ebx
cmpl %ebx, %r8d
cmovbl %r8d, %ebx
subl %ebp, %ebx
xorps %xmm2, %xmm2
cvtsi2ss %rbx, %xmm2
subl 0x4(%r14), %r13d
xorps %xmm3, %xmm3
cvtsi2ss %r13, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
ja 0x1a43bd
decq %r12
addq $-0x1c, %r11
cmpq %r9, %r12
jg 0x1a4334
jmp 0x1a4401
movl 0x10(%r14), %r11d
movq (%rax), %r14
cmpl 0x14(%r14,%r10), %r11d
jae 0x1a43f7
leaq (%r11,%r11,8), %r8
leaq (%r8,%r8,2), %r15
movq 0x10(%rsp), %r8
addq %r11, %r8
addq %r8, %r15
orb $0x40, 0x3(%r15)
incq %r11
movq (%rax), %r14
movl 0x14(%r14,%r10), %r8d
addq $0x1c, %r15
cmpq %r8, %r11
jb 0x1a43de
addq %r10, %r14
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
leaq -0x1(%r9), %r8
testq %r9, %r9
movq %r8, %r9
jg 0x1a430b
xorl %r14d, %r14d
testq %rdx, %rdx
jle 0x1a4455
movq %rdi, %rax
movq 0x8(%rsp), %rbx
testb $0x40, 0x1b(%rax)
jne 0x1a4445
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r14, %rcx
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movups %xmm1, 0xc(%rdi,%rcx)
movups %xmm0, (%rdi,%rcx)
incq %r14
addq $0x1c, %rax
decq %rdx
jne 0x1a4421
jmp 0x1a445a
xorl %r14d, %r14d
jmp 0x1a446d
movq 0x8(%rsp), %rbx
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r14, %rsi
addq %rdi, %rsi
callq 0x195511
addq %r14, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq