// File: /workspace/github_cpp_makefile_star2_O3/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 0x1ad6be
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rax
movq (%rdi), %r11
leaq -0x1(%r9), %r8
leaq (%r8,%r8,8), %rdi
leaq (%rdi,%rdi,2), %rdi
leaq -0x1(%r9,%rdi), %r12
movq (%rsi), %r10
movq %rsi, (%rsp)
movq 0x8(%rsi), %r14
leaq (%r14,%r14,8), %rdi
movl 0x8(%r11,%r12), %ebx
subl 0x4(%r11,%r12), %ebx
leaq (%rdi,%rdi,2), %r15
cvtsi2ss %rbx, %xmm2
leaq (%r10,%r14), %rdi
cvtsi2ss %rcx, %xmm3
addq %r15, %rdi
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jbe 0x1ad523
addq %r12, %r11
movl 0x10(%r11), %ecx
cmpl 0x14(%r11), %ecx
jae 0x1ad686
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rdx
addq %rcx, %rdx
xorl %eax, %eax
movq (%rsp), %rbx
movups (%rdi,%rdx), %xmm0
movups 0xc(%rdi,%rdx), %xmm1
movups %xmm1, 0xc(%rdi)
movups %xmm0, (%rdi)
orb $-0x80, 0xf(%rdi)
movl 0x14(%r11), %r8d
leaq (%rcx,%rax), %r9
incq %r9
incq %rax
addq $0x1c, %rdi
cmpq %r8, %r9
jb 0x1ad4ef
movq 0x8(%rbx), %r14
jmp 0x1ad68c
testq %r8, %r8
js 0x1ad648
leaq (%r9,%r9,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r9, %rcx
addq $-0x14, %rcx
movq %rcx, 0x10(%rsp)
addq %r14, %r15
leaq (%r10,%r15), %rcx
addq $0x18, %rcx
movq %rcx, 0x8(%rsp)
movq %r8, %r10
cmpq %r10, %r8
jle 0x1ad638
leaq (%r10,%r10,8), %r9
leaq (%r9,%r9,2), %rsi
addq %r10, %rsi
leaq (%r11,%rsi), %r14
leaq (%r11,%rsi), %r15
addq $0x4, %r15
movq 0x10(%rsp), %rcx
leaq (%r11,%rcx), %r12
movq %r8, %r13
movl -0x8(%r12), %r9d
cmpl $-0x1, %r9d
je 0x1ad5ea
movl (%r14), %ebx
xorps %xmm2, %xmm2
cvtsi2ss %rbx, %xmm2
movl %r9d, %r9d
xorps %xmm3, %xmm3
cvtsi2ss %r9, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm3, %xmm2
ja 0x1ad5ea
movl 0x8(%r14), %ebp
movl -0x4(%r12), %ecx
movl (%r12), %ebx
cmpl %ebx, %ebp
cmovbl %ebp, %ebx
movl (%r15), %r9d
cmpl %ecx, %r9d
cmoval %r9d, %ecx
subl %ecx, %ebx
ja 0x1ad5ce
xorps %xmm2, %xmm2
jmp 0x1ad5d6
xorps %xmm2, %xmm2
cvtsi2ss %rbx, %xmm2
subl %r9d, %ebp
xorps %xmm3, %xmm3
cvtsi2ss %rbp, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
ja 0x1ad5f8
decq %r13
addq $-0x1c, %r12
cmpq %r10, %r13
jg 0x1ad57f
jmp 0x1ad638
movl 0x10(%r14), %r14d
cmpl 0x14(%r11,%rsi), %r14d
jae 0x1ad62f
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %r15
movq 0x8(%rsp), %rcx
addq %r14, %rcx
addq %rcx, %r15
orb $0x40, 0x3(%r15)
incq %r14
movq (%rax), %r11
movl 0x14(%r11,%rsi), %ecx
addq $0x1c, %r15
cmpq %rcx, %r14
jb 0x1ad616
addq %r11, %rsi
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
leaq -0x1(%r10), %rcx
testq %r10, %r10
movq %rcx, %r10
jg 0x1ad553
xorl %r14d, %r14d
testq %rdx, %rdx
jle 0x1ad691
movq %rdi, %rax
movq (%rsp), %rbx
testb $0x40, 0x1b(%rax)
jne 0x1ad67b
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 0x1ad657
jmp 0x1ad695
xorl %eax, %eax
movq (%rsp), %rbx
addq %rax, %r14
jmp 0x1ad6ac
movq (%rsp), %rbx
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r14, %rsi
addq %rdi, %rsi
callq 0x19e2b4
addq 0x8(%rbx), %r14
movq %r14, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq