// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movss %xmm0, -0x2c(%rbp)
movss %xmm1, -0x30(%rbp)
movss %xmm2, -0x34(%rbp)
movss %xmm3, -0x38(%rbp)
movss %xmm4, -0x3c(%rbp)
movq %r8, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
ja 0x2959b0
movq $0x0, -0x8(%rbp)
jmp 0x29619d
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq -0x1c(%rax,%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
cvtsi2ssq -0x28(%rbp), %xmm1
mulss -0x2c(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x295b2d
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movl %eax, %esi
movss -0x3c(%rbp), %xmm0
callq 0x2946e0
cmpl $0x0, %eax
je 0x295b2d
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jge 0x295b0d
movq -0x58(%rbp), %rcx
imulq $0x1c, -0x60(%rbp), %rax
addq %rax, %rcx
movq -0x58(%rbp), %rax
imulq $0x1c, -0x70(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
imulq $0x1c, -0x70(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
imulq $0x1c, -0x70(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x295a72
movq -0x70(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq $0x1, -0x98(%rbp)
jmp 0x296192
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
cvtsi2ssq -0x28(%rbp), %xmm1
mulss -0x34(%rbp), %xmm1
ucomiss %xmm1, %xmm0
ja 0x295b68
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
cmpq -0x48(%rbp), %rax
jbe 0x295e52
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movl %eax, %esi
movss -0x3c(%rbp), %xmm0
callq 0x2946e0
cmpl $0x0, %eax
je 0x295e52
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x78(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x295df3
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x295bfd
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x295c15
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jb 0x295c4b
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x295c63
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0xa0(%rbp), %eax
movl -0xa4(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x295d1d
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x295ca1
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xa8(%rbp)
jmp 0x295cb9
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jb 0x295cef
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb0(%rbp)
jmp 0x295d07
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0xb0(%rbp)
movl -0xac(%rbp), %eax
movl -0xb0(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0xb4(%rbp)
jmp 0x295d27
xorl %eax, %eax
movl %eax, -0xb4(%rbp)
jmp 0x295d27
movl -0xb4(%rbp), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x295d3f
jmp 0x295de2
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jle 0x295d8a
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
cvtsi2sdq -0x80(%rbp), %xmm0
cvtsi2sdq -0x90(%rbp), %xmm1
movsd 0xe9277(%rip), %xmm2    # 0x37f018
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x295de0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movl (%rax,%rcx), %eax
cvtsi2ss %rax, %xmm0
movq -0x50(%rbp), %rax
movl (%rax), %eax
cvtsi2ss %rax, %xmm1
mulss -0x38(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x295de0
jmp 0x295df3
jmp 0x295de2
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x295bbe
movq -0x60(%rbp), %rax
movq -0x78(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jl 0x295e50
movq -0x50(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jge 0x295e45
movq -0x58(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x295e0f
movq $0x1, -0x98(%rbp)
jmp 0x295e52
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27b350
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x295f6a
movq -0x60(%rbp), %rax
movq -0x78(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x295eca
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq -0x60(%rbp), %rdx
addq $0x1, %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x295eca
jmp 0x295f6a
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl 0x4(%rax,%rdx), %ecx
movl 0x8(%rax,%rdx), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
cvtsi2ssq -0x28(%rbp), %xmm1
mulss -0x30(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x295f57
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movl %eax, %esi
movss -0x3c(%rbp), %xmm0
callq 0x2946e0
cmpl $0x0, %eax
jne 0x295f55
jmp 0x295f6a
jmp 0x295f57
jmp 0x295f59
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x295e79
movq -0x60(%rbp), %rax
cmpq -0x78(%rbp), %rax
jne 0x29603a
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x296038
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl 0x4(%rax,%rdx), %ecx
movl 0x8(%rax,%rdx), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm1
cvtsi2ssq -0x28(%rbp), %xmm0
mulss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x295fc5
jmp 0x296027
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0x60(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jge 0x29601c
movq -0x58(%rbp), %rax
imulq $0x1c, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x295fdb
movq $0x1, -0x98(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x295f80
jmp 0x29603a
movq $0x0, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x2960de
movq -0x58(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x29608b
movq -0x58(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x2960cb
movq -0x58(%rbp), %rcx
imulq $0x1c, -0x60(%rbp), %rax
addq %rax, %rcx
movq -0x58(%rbp), %rax
imulq $0x1c, -0x70(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2960cd
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x29604a
movq -0x70(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rdi
movq -0x58(%rbp), %rsi
imulq $0x1c, -0x20(%rbp), %rax
addq %rax, %rsi
callq 0x27b350
movq $0x1, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jg 0x296182
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x29613f
movq -0x58(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
imulq $0x1c, -0x70(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
je 0x296172
movq -0x60(%rbp), %rax
subq -0x70(%rbp), %rax
cmpq $0x1, %rax
jle 0x29616a
movq -0x58(%rbp), %rdi
imulq $0x1c, -0x70(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rsi
imulq $0x1c, -0x60(%rbp), %rax
addq %rax, %rsi
callq 0x27b890
movq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x296174
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x29610b
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x98(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)