// File: /workspace/github_cpp_makefile_star2_O2/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 0x164d4d
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r8
movq %rdi, %rcx
movq (%rdi), %rax
leaq -0x1(%r9), %r13
imulq $0x1c, 0x8(%rsi), %r10
imulq $0x1c, %r13, %r11
movl 0x8(%rax,%r11), %edi
subl 0x4(%rax,%r11), %edi
cvtsi2ss %rdi, %xmm2
movq %rsi, (%rsp)
movq (%rsi), %rbx
cvtsi2ss %r8, %xmm3
leaq (%rbx,%r10), %rdi
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
jbe 0x164c05
addq %r11, %rax
movl 0x10(%rax), %esi
imulq $0x1c, %rsi, %rcx
xorl %r14d, %r14d
movq (%rsp), %r9
leaq (%rsi,%r14), %rdx
movl 0x14(%rax), %r8d
cmpq %r8, %rdx
jae 0x164d3b
movups (%rdi,%rcx), %xmm0
movups 0xc(%rdi,%rcx), %xmm1
movups %xmm1, 0xc(%rdi)
movups %xmm0, (%rdi)
orb $-0x80, 0xf(%rdi)
incq %r14
addq $0x1c, %rdi
jmp 0x164bd7
imulq $0x1c, %r9, %rsi
addq $-0x14, %rsi
movq %rsi, 0x10(%rsp)
leaq (%r10,%rbx), %rsi
addq $0x18, %rsi
movq %rsi, 0x8(%rsp)
movq %r13, %r10
testq %r10, %r10
js 0x164cf5
imulq $0x1c, %r10, %r11
leaq (%rax,%r11), %r14
leaq (%rax,%r11), %r15
addq $0x4, %r15
movq 0x10(%rsp), %rsi
leaq (%rax,%rsi), %r12
movq %r13, %rsi
cmpq %r10, %r13
jle 0x164cb6
movl -0x8(%r12), %r9d
cmpl $-0x1, %r9d
je 0x164cad
movl (%r14), %ebx
cvtsi2ss %rbx, %xmm2
movl %r9d, %r9d
cvtsi2ss %r9, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm3, %xmm2
ja 0x164cad
movl 0x8(%r14), %ebp
movl -0x4(%r12), %r8d
movl (%r12), %r9d
cmpl %r9d, %ebp
cmovbl %ebp, %r9d
movl (%r15), %ebx
cmpl %r8d, %ebx
cmoval %ebx, %r8d
subl %r8d, %r9d
ja 0x164c98
xorps %xmm2, %xmm2
jmp 0x164c9d
cvtsi2ss %r9, %xmm2
subl %ebx, %ebp
cvtsi2ss %rbp, %xmm3
mulss %xmm0, %xmm3
ucomiss %xmm3, %xmm2
ja 0x164cbb
decq %r13
addq $-0x1c, %r12
jmp 0x164c47
movq %rsi, %r13
jmp 0x164ced
movl 0x10(%r14), %r14d
imulq $0x1c, %r14, %r15
addq 0x8(%rsp), %r15
movq %rsi, %r13
movl 0x14(%rax,%r11), %r8d
cmpq %r8, %r14
jae 0x164ce6
orb $0x40, 0x3(%r15)
incq %r14
movq (%rcx), %rax
addq $0x1c, %r15
jmp 0x164ccb
addq %rax, %r11
orl $-0x1, (%r11)
decq %r10
jmp 0x164c22
xorl %r14d, %r14d
testq %rdx, %rdx
cmovleq %r14, %rdx
movq %rdi, %rax
subq $0x1, %rdx
jb 0x164d2b
testb $0x40, 0x1b(%rax)
jne 0x164d25
imulq $0x1c, %r14, %rcx
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movups %xmm1, 0xc(%rdi,%rcx)
movups %xmm0, (%rdi,%rcx)
incq %r14
addq $0x1c, %rax
jmp 0x164d02
imulq $0x1c, %r14, %rsi
addq %rdi, %rsi
callq 0x156f5c
movq (%rsp), %r9
addq %r14, 0x8(%r9)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq