// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
xorl %r13d, %r13d
testq %rdi, %rdi
je 0x1648d0
movq %rdx, %rbp
movq (%rbx), %r12
imulq $0x1c, %rdi, %rdx
movl -0x14(%r12,%rdx), %eax
subl -0x18(%r12,%rdx), %eax
cvtsi2ss %rax, %xmm3
cvtsi2ss %rsi, %xmm4
mulss %xmm0, %xmm4
ucomiss %xmm3, %xmm4
jae 0x1648d0
pushq $0x1
popq %r13
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x1648d0
movq %rcx, 0x48(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x40(%rsp)
movsd %xmm2, 0x60(%rsp)
movq %rdi, 0x30(%rsp)
movq %rdx, 0x58(%rsp)
addq %rdx, %r12
movl -0xc(%r12), %r14d
movl -0x8(%r12), %r15d
imulq $0x1c, %r14, %rax
addq %rax, %rbp
movl %r15d, %esi
subl %r14d, %esi
movq %rbp, %rdi
movss %xmm1, 0x2c(%rsp)
movaps %xmm1, %xmm0
callq 0x1645d6
testl %eax, %eax
jne 0x1648d0
cmpq $0x0, 0x48(%rsp)
sete %al
cmpq $0x0, 0x20(%rsp)
sete %cl
orb %al, %cl
cmpq $0x0, 0x40(%rsp)
sete %al
orb %cl, %al
movl $0x0, %r13d
jne 0x1648d0
movq $0x0, 0x38(%rsp)
movl %r15d, %eax
cmpq %rax, %r14
jae 0x164881
testb $0x40, 0x1b(%rbp)
jne 0x164819
movl (%rbp), %r13d
andq $0x0, 0x50(%rsp)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
leaq 0x50(%rsp), %rdx
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x160309
testq %rax, %rax
jle 0x1648e2
movq 0x48(%rsp), %rcx
movq (%rcx), %rsi
imulq $0xa8, %r13, %rcx
cmpb $0x2, 0x2c(%rsi,%rcx)
jne 0x1648e2
addq %rcx, %rsi
movq 0x40(%rsp), %rdi
movq (%rdi), %rcx
movq 0x10(%rcx), %r8
movl 0x10(%rsi), %ecx
imulq $0x28, %rcx, %rcx
cmpl $0x2, 0x10(%r8,%rcx)
movsd 0x60(%rsp), %xmm0
jb 0x164870
addq %rcx, %r8
imulq $0x18, 0x50(%rsp), %rdx
movq 0x20(%rsp), %rcx
addq (%rcx), %rdx
movq 0xa8(%rsp), %rcx
movq %rcx, 0x18(%rsp)
xorps %xmm1, %xmm1
movups %xmm1, 0x8(%rsp)
movq 0xa0(%rsp), %rcx
movq %rcx, (%rsp)
movq %rax, %rcx
movq %rbx, %r9
callq 0x1619a7
addq %rax, 0x38(%rsp)
jmp 0x164870
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x164853
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rdx
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x1a3acc
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movups (%rbp), %xmm0
movups 0xc(%rbp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
incq %r14
movl -0x8(%r12), %r15d
addq $0x1c, %rbp
jmp 0x164752
cmpq $0x0, 0x38(%rsp)
movq 0x58(%rsp), %r15
je 0x1648c4
movq (%rbx), %rax
leaq (%rax,%r15), %rdi
imulq $0x1c, 0x8(%rbx), %rsi
addq %rax, %rsi
callq 0x156f5c
addq (%rbx), %r15
movq 0x8(%rbx), %rsi
movq 0x30(%rsp), %r14
subq %r14, %rsi
movq %r15, %rdi
movss 0x2c(%rsp), %xmm0
callq 0x1645d6
movl %eax, %r13d
jmp 0x1648cc
xorl %r13d, %r13d
movq 0x30(%rsp), %r14
movq %r14, 0x8(%rbx)
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8ddf7(%rip), %rdi     # 0x1f26e0
leaq 0x8d233(%rip), %rsi     # 0x1f1b23
leaq 0x8de13(%rip), %rcx     # 0x1f270a
movl $0xfb7, %edx            # imm = 0xFB7
callq 0x2110