// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: dump_all_chain_simple(kv_ul_ov_t*, kv_ul_ov_t*, long, long, float, float, float, float, float, unsigned long)
int64_t dump_all_chain_simple(kv_ul_ov_t *idx, kv_ul_ov_t *ax, int64_t ax_new_occ, int64_t qlen, 
float primary_cov_rate, float fragement_cov_rate, float primary_fragment_cov_rate, 
float primary_fragment_second_score_rate, float trans_thres, uint64_t mini_primary_fragment_len) 
{
	if(idx->n <= 0) return 0;
	ul_ov_t *m = &(idx->a[idx->n-1]); //largest chain
	ul_ov_t *a = ax->a + ax->n; int64_t k, z, l, idx_n = idx->n, ovlp, om, ok, ff = 0;
	// fprintf(stderr, "[M::%s] m->score:%u, m->qs:%u, m->qe:%u, chain_n:%u\n", __func__, m->qn, m->qs, m->qe, m->te-m->ts);
	if(((m->qe-m->qs) > (qlen*primary_cov_rate)) && 
						(check_trans_rate(a+m->ts, m->te-m->ts, trans_thres))) { ///found a primary chain
		for (k = m->ts, l = 0; k < m->te; k++) {
			a[l] = a[k]; a[l].tn |= ((uint32_t)(0x80000000)); a[l].el = 1;
			l++;
		}
		ax->n += l; ff = 1;
	} else {
		if((((m->qe-m->qs) > (qlen*primary_fragment_cov_rate)) || ((m->qe - m->qs) > mini_primary_fragment_len)) 
		&& (check_trans_rate(a+m->ts, m->te-m->ts, trans_thres))) {
			om = m->qe - m->qs;
			for (k = 0; k < idx_n-1; k++) {
				ovlp = ((MIN((m->qe), (idx->a[k].qe)) > MAX((m->qs), (idx->a[k].qs)))? 
										(MIN((m->qe), (idx->a[k].qe)) - MAX((m->qs), (idx->a[k].qs))):0);
				if(ovlp == 0) continue;
				ok = idx->a[k].qe - idx->a[k].qs;
				if(ok > om ) ok = om;
				if((ovlp > ok*0.1/**0.25**/) && idx->a[k].qn > (m->qn*primary_fragment_second_score_rate)) break;
			}

			if(k >= idx_n-1) {
				for (k = m->ts; k < m->te; k++) {
					// if(a[k].el) a[k].tn |= ((uint32_t)(0x80000000));
					a[k].tn |= ((uint32_t)(0x80000000));
				}
				ff = 1;
			}
		}

		radix_sort_ul_ov_srt_qe(idx->a, idx->a + idx->n);
		for (k = 0; k < idx_n; k++) {
			if(k < idx_n-1 && idx->a[k].qe > idx->a[k+1].qs) break;//not one chain
			if((idx->a[k].qe - idx->a[k].qs) > (qlen*fragement_cov_rate)) {///large enough fragements
				if(!check_trans_rate(a+idx->a[k].ts, idx->a[k].te-idx->a[k].ts, trans_thres)) break;
			}
		}

		if(k == idx_n) {///only if there is a clear chain (with holes)
			for (k = 0; k < idx_n; k++) {
				if((idx->a[k].qe - idx->a[k].qs) <= (qlen*fragement_cov_rate)) continue;
				for (z = idx->a[k].ts; z < idx->a[k].te; z++) {
					// if(a[z].el) a[z].tn |= ((uint32_t)(0x80000000));
					a[z].tn |= ((uint32_t)(0x80000000));
				}
				ff = 1;
			}
		} 
		/**
		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;
		**/
		for (k = 0, l = 0; k < ax_new_occ; k++) {
			if(a[k].el || (a[k].tn&((uint32_t)(0x80000000)))) {
				a[l] = a[k]; l++;
			}
		}
		ax_new_occ = l;

		radix_sort_ul_ov_srt_qe(a, a + ax_new_occ);
		for (k = 1, l = 0; k <= ax_new_occ; k++) {
			if (k == ax_new_occ || a[k].qe != a[l].qe) {
				if(k - l > 1) radix_sort_ul_ov_srt_qs(a+l, a+k);
				l = k;
			}
		}
		ax->n += ax_new_occ;
	}
	return ff;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movss %xmm4, 0x14(%rsp)
movq 0x8(%rdi), %rbx
testq %rbx, %rbx
je 0x1a474e
movq %rdx, %r15
movss %xmm1, 0x6c(%rsp)
movq %rdi, 0x58(%rsp)
movq (%rdi), %r10
leaq -0x1(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq -0x1(%rbx,%rax), %rax
leaq (%r10,%rax), %r11
movq (%rsi), %rdi
movq %rsi, 0x20(%rsp)
movq 0x8(%rsi), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x4(%r10,%rax), %r9d
movl 0x8(%r10,%rax), %r12d
movl %r12d, %eax
movl %r9d, 0x68(%rsp)
subl %r9d, %eax
movq %rax, 0x70(%rsp)
xorps %xmm4, %xmm4
cvtsi2ss %rax, %xmm4
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
leaq (%rdi,%rsi), %r14
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
movq %rdx, 0x38(%rsp)
addq %rdx, %r14
mulss %xmm1, %xmm0
ucomiss %xmm0, %xmm4
movss %xmm1, 0xc(%rsp)
jbe 0x1a45f6
movl 0x10(%r11), %r13d
movl 0x14(%r11), %esi
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rbp
addq %r13, %rbp
leaq (%r14,%rbp), %rdi
subl %r13d, %esi
movss 0x14(%rsp), %xmm0
movq %r10, 0x18(%rsp)
movq %r11, 0x30(%rsp)
movss %xmm3, 0x10(%rsp)
movq %r8, 0x28(%rsp)
movss %xmm2, 0x64(%rsp)
movss %xmm4, 0x60(%rsp)
callq 0x1a3c15
movss 0x60(%rsp), %xmm4
movss 0x64(%rsp), %xmm2
movq 0x28(%rsp), %r8
movss 0x10(%rsp), %xmm3
movq 0x30(%rsp), %r11
movq 0x18(%rsp), %r10
movss 0xc(%rsp), %xmm1
testl %eax, %eax
je 0x1a45f6
cmpl 0x14(%r11), %r13d
jae 0x1a4755
xorl %ebx, %ebx
movq 0x20(%rsp), %rdx
movups (%r14,%rbp), %xmm0
movups 0xc(%r14,%rbp), %xmm1
movups %xmm1, 0xc(%r14)
movups %xmm0, (%r14)
orb $-0x80, 0xf(%r14)
orb $0x40, 0x1b(%r14)
movl 0x14(%r11), %eax
leaq (%rbx,%r13), %rcx
incq %rcx
incq %rbx
addq $0x1c, %r14
cmpq %rax, %rcx
jb 0x1a45bc
jmp 0x1a475c
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm4
setbe %al
movl 0x70(%rsp), %ecx
cmpq %r8, %rcx
setbe %cl
testb %cl, %al
jne 0x1a4773
movss %xmm3, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl 0x10(%r11), %ecx
movq %r11, %rbp
movl 0x14(%r11), %r13d
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
movq %rax, 0x28(%rsp)
leaq (%r14,%rax), %rdi
movl %r13d, %esi
movq %rcx, 0x30(%rsp)
subl %ecx, %esi
movss 0x14(%rsp), %xmm0
callq 0x1a3c15
testl %eax, %eax
je 0x1a4766
movq 0x50(%rsp), %r9
testq %r9, %r9
setg %al
movq 0x18(%rsp), %r10
movq %rbp, %r11
movss 0x10(%rsp), %xmm3
movl 0x68(%rsp), %ebp
jle 0x1a470c
leaq 0x8(%r10), %rcx
movl $0x1, %edx
movsd 0x80543(%rip), %xmm0    # 0x224bd0
movl -0x4(%rcx), %r8d
movl (%rcx), %edi
cmpl %edi, %r12d
cmovbl %r12d, %edi
cmpl %r8d, %ebp
cmoval %ebp, %r8d
subl %r8d, %edi
jbe 0x1a46fa
movl $0x0, %esi
cmovbl %esi, %edi
movl (%rcx), %r8d
subl -0x4(%rcx), %r8d
movq 0x70(%rsp), %rsi
cmpl %esi, %r8d
cmovael %esi, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r8, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x1a46fa
movl -0x8(%rcx), %edi
xorps %xmm1, %xmm1
cvtsi2ss %rdi, %xmm1
movl (%r11), %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
mulss %xmm3, %xmm2
ucomiss %xmm2, %xmm1
ja 0x1a476f
cmpq %r9, %rdx
setl %al
addq $0x1c, %rcx
incq %rdx
cmpq %rdx, %rbx
jne 0x1a468d
movl $0x1, %ebp
movq 0x30(%rsp), %rax
cmpl %r13d, %eax
jae 0x1a4775
subq %rax, %r13
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
addq %rcx, %rax
movq 0x28(%rsp), %rcx
addq %rax, %rcx
movq 0x48(%rsp), %rax
addq %rcx, %rax
addq $0xc, %rax
orb $-0x80, 0x3(%rax)
addq $0x1c, %rax
decq %r13
jne 0x1a473f
jmp 0x1a4775
xorl %ebp, %ebp
jmp 0x1a49ac
xorl %ebx, %ebx
movq 0x20(%rsp), %rdx
movl $0x1, %ebp
jmp 0x1a49a8
xorl %ebp, %ebp
movq 0x18(%rsp), %r10
jmp 0x1a4775
testb $0x1, %al
je 0x1a470c
xorl %ebp, %ebp
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rbx, %rsi
addq %r10, %rsi
movq %r10, %rdi
callq 0x195511
movss 0xc(%rsp), %xmm1
mulss 0x6c(%rsp), %xmm1
testq %rbx, %rbx
jle 0x1a482e
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rsi
movss %xmm1, 0xc(%rsp)
cmpq %rsi, %r12
jge 0x1a47ca
movq (%rdx), %rax
movl 0x8(%rax,%r13), %ecx
cmpl 0x20(%rax,%r13), %ecx
ja 0x1a4836
movq (%rdx), %rax
movl 0x8(%rax,%r13), %ecx
subl 0x4(%rax,%r13), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1a481d
movl 0x10(%rax,%r13), %ecx
movl 0x14(%rax,%r13), %esi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rdi
addq %rcx, %rdi
addq %r14, %rdi
subl %ecx, %esi
movss 0x14(%rsp), %xmm0
callq 0x1a3c15
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movss 0xc(%rsp), %xmm1
testl %eax, %eax
je 0x1a4836
incq %r12
addq $0x1c, %r13
cmpq %r12, %rbx
jne 0x1a47b6
movq %rbx, %r12
jmp 0x1a4836
xorl %r12d, %r12d
movq 0x58(%rsp), %rdx
cmpq %rbx, %r12
setne %al
testq %rbx, %rbx
setle %cl
orb %al, %cl
jne 0x1a48be
movq (%rdx), %rax
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %rdx
addq %rdx, %rcx
movq 0x48(%rsp), %rdx
addq %rdx, %rcx
addq $0xc, %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rdi
addq %rdx, %rdi
movl 0x8(%rax,%rdi), %esi
subl 0x4(%rax,%rdi), %esi
xorps %xmm0, %xmm0
cvtsi2ss %rsi, %xmm0
ucomiss %xmm0, %xmm1
jae 0x1a48b6
leaq (%rax,%rdi), %rsi
movl 0x10(%rsi), %esi
movl 0x14(%rax,%rdi), %edi
movl $0x1, %ebp
cmpl %edi, %esi
jae 0x1a48b6
subq %rsi, %rdi
leaq (%rsi,%rsi,8), %r8
leaq (%r8,%r8,2), %r8
addq %rcx, %rsi
addq %r8, %rsi
orb $-0x80, 0x3(%rsi)
addq $0x1c, %rsi
decq %rdi
jne 0x1a48a9
incq %rdx
cmpq %rbx, %rdx
jne 0x1a4864
xorl %ebx, %ebx
testq %r15, %r15
jle 0x1a48fd
movq %r14, %rax
testb $0x40, 0x1b(%rax)
jne 0x1a48d4
cmpl $0x0, 0xc(%rax)
jns 0x1a48f4
leaq (%rbx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbx, %rcx
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movups %xmm1, 0xc(%r14,%rcx)
movups %xmm0, (%r14,%rcx)
incq %rbx
addq $0x1c, %rax
decq %r15
jne 0x1a48c8
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rbx, %rsi
addq %r14, %rsi
movq %r14, %rdi
callq 0x195511
testq %rbx, %rbx
jle 0x1a49a3
movq %rbx, %r12
negq %r12
movq 0x38(%rsp), %rcx
addq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
leaq (%rax,%rcx), %r15
addq $0x1c, %r15
movl $0x1, %r13d
xorl %eax, %eax
movq %r12, %rcx
addq %r13, %rcx
je 0x1a4964
movl 0x8(%r15), %ecx
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
cmpl 0x8(%r14,%rdx), %ecx
jne 0x1a4964
movq %rax, %rcx
jmp 0x1a498c
movq %r13, %rdx
subq %rax, %rdx
movq %r13, %rcx
cmpq $0x2, %rdx
jl 0x1a498c
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0x1957bd
movq %r13, %rcx
leaq (%r12,%r13), %rdx
incq %rdx
incq %r13
addq $0x1c, %r15
movq %rcx, %rax
cmpq $0x1, %rdx
jne 0x1a4941
movq 0x20(%rsp), %rdx
addq %rbx, 0x8(%rdx)
movq %rbp, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq