// File: chhylp123[P]hifiasm/inter.cpp
// Function: ff_chain(kv_ul_ov_t*, long, float, float, ul_ov_t*, overlap_region_alloc*, haplotype_evdience_alloc*, ul_idx_t const*, double, long, void*)
uint32_t ff_chain(kv_ul_ov_t *idx, int64_t qlen, float cov_rate, float trans_thres, ul_ov_t *a, 
overlap_region_alloc* olist, haplotype_evdience_alloc *hap, const ul_idx_t *uref, double diff_ec_ul, int64_t winLen, 
void *km)
{
	if(idx->n <= 0) return 0;
	ul_ov_t *m = &(idx->a[idx->n-1]); //largest chain
	// 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*cov_rate)) return 0;
	if(trans_thres >= 0) {
		if(check_trans_rate(a+m->ts, m->te-m->ts, trans_thres)) return 1;
		if(olist && hap && uref) {
			int64_t idx_n = idx->n, z, i, het_n, resc_tk = 0, f = 0; 
			uint64_t si; ma_utg_t *u = NULL;
			for (z = m->ts; z < m->te; z++) {
				if(a[z].el) {
					kv_push_km(km, ul_ov_t, *idx, a[z]);
				} else {
					i = a[z].qn; si = 0;
					het_n = update_ava_het_site(hap, i, &si, NULL, 1);
					assert(het_n > 0 && olist->list[i].is_match == 2);
					u = &(uref->ug->u.a[olist->list[i].y_id]);
					if(u->n > 1) {
						resc_tk += rescue_trans_ul_chains(uref, &(olist->list[i]), hap->list+si, het_n, u, 
						idx, diff_ec_ul, winLen, 0, NULL, km);
					}
				}
			}

			if(resc_tk) {
				radix_sort_ul_ov_srt_qe(idx->a+idx_n, idx->a+idx->n);
				f = check_trans_rate(idx->a+idx_n, idx->n-idx_n, trans_thres);
			}
			idx->n = idx_n;
			return f;
		}
		return 0;
	} else {
		return 1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movsd %xmm2, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
ja 0x2948e1
movl $0x0, -0x4(%rbp)
jmp 0x294c9d
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 -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm1
cvtsi2ssq -0x18(%rbp), %xmm0
mulss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x29492d
movl $0x0, -0x4(%rbp)
jmp 0x294c9d
movss -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x294c96
movq -0x28(%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 -0x20(%rbp), %xmm0
callq 0x2946e0
cmpl $0x0, %eax
je 0x29497d
movl $0x1, -0x4(%rbp)
jmp 0x294c9d
cmpq $0x0, -0x30(%rbp)
je 0x294c8d
cmpq $0x0, -0x38(%rbp)
je 0x294c8d
cmpq $0x0, -0x40(%rbp)
je 0x294c8d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x90(%rbp)
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 0x294c1f
movq -0x28(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x294ac3
jmp 0x294a04
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x294a75
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x294a35
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x294a43
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x294a43
movq -0x98(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rdx
callq 0x30e740
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
imulq $0x1c, -0x60(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rsi
movq 0x8(%rsi), %rdx
movq %rdx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
imulq $0x1c, %rdx, %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)
jmp 0x294c0c
movq -0x28(%rbp), %rax
imulq $0x1c, -0x60(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq %rax, -0x68(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x38(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq -0x88(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %r8d
callq 0x28c790
movq %rax, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0x99(%rbp)
jle 0x294b33
movq -0x30(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x68(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x2, %eax
sete %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x294b3f
jmp 0x294b41
jmp 0x294b60
leaq 0xfc8a4(%rip), %rdi     # 0x3913ec
leaq 0xfbce0(%rip), %rsi     # 0x39082f
movl $0xfb7, %edx            # imm = 0xFB7
leaq 0xfc8bb(%rip), %rcx     # 0x391416
callq 0x2130
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x68(%rbp), %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jbe 0x294c0a
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x68(%rbp), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
imulq $0x18, -0x88(%rbp), %rax
addq %rax, %rdx
movq -0x70(%rbp), %rcx
movq -0x90(%rbp), %r8
movq -0x10(%rbp), %r9
movsd -0x48(%rbp), %xmm0
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
xorl %r11d, %r11d
movq %r10, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x28f130
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x294c0c
jmp 0x294c0e
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2949d0
cmpq $0x0, -0x78(%rbp)
je 0x294c78
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x1c, -0x58(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27b350
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x1c, -0x58(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
subq -0x58(%rbp), %rsi
movss -0x20(%rbp), %xmm0
callq 0x2946e0
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x294c9d
movl $0x0, -0x4(%rbp)
jmp 0x294c9d
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)