// File: /workspace/github_cpp_makefile_star2_O1/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 0x8(%rdi), %r15
xorl %r13d, %r13d
testq %r15, %r15
je 0x1a3f72
movq %rdi, %rbx
movq (%rdi), %r12
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %r14
addq %r15, %r14
movl -0x14(%r12,%r14), %eax
subl -0x18(%r12,%r14), %eax
cvtsi2ss %rax, %xmm3
cvtsi2ss %rsi, %xmm4
mulss %xmm0, %xmm4
ucomiss %xmm3, %xmm4
jae 0x1a3f72
movl $0x1, %r13d
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x1a3f72
movq %rdx, %rbp
movq %rcx, 0x50(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x48(%rsp)
movsd %xmm2, 0x60(%rsp)
addq %r14, %r12
movl -0xc(%r12), %edi
movl -0x8(%r12), %esi
leaq (%rdi,%rdi,8), %rax
leaq (%rax,%rax,2), %rax
subl %edi, %esi
addq %rdx, %rdi
addq %rax, %rdi
movss %xmm1, 0x3c(%rsp)
movaps %xmm1, %xmm0
callq 0x1a3c15
testl %eax, %eax
jne 0x1a3f72
cmpq $0x0, 0x50(%rsp)
sete %al
cmpq $0x0, 0x30(%rsp)
sete %cl
orb %al, %cl
cmpq $0x0, 0x48(%rsp)
sete %al
orb %cl, %al
movl $0x0, %r13d
jne 0x1a3f72
movq %r15, 0x28(%rsp)
movl -0xc(%r12), %r15d
cmpl -0x8(%r12), %r15d
jae 0x1a3f66
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r15, %rbp
addq %rax, %rbp
movq $0x0, 0x40(%rsp)
testb $0x40, 0x1b(%rbp)
jne 0x1a3ea2
movl (%rbp), %r13d
movq $0x0, 0x58(%rsp)
movl $0x1, %r8d
movq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0x58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x19f226
testq %rax, %rax
jle 0x1a3f84
movq 0x50(%rsp), %rcx
movq (%rcx), %rsi
imulq $0xa8, %r13, %rcx
cmpb $0x2, 0x2c(%rsi,%rcx)
jne 0x1a3f84
addq %rcx, %rsi
movq 0x48(%rsp), %rdi
movq (%rdi), %rcx
movq 0x10(%rcx), %rcx
movl 0x10(%rsi), %edx
leaq (%rdx,%rdx,4), %rdx
cmpl $0x2, 0x10(%rcx,%rdx,8)
movsd 0x60(%rsp), %xmm0
jb 0x1a3f09
leaq (%rcx,%rdx,8), %r8
movq 0x58(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
movq 0x30(%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 0x1a0ae8
addq %rax, 0x40(%rsp)
jmp 0x1a3f09
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1a3ede
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rsi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rdx
addq %rcx, %rdx
movq 0xa8(%rsp), %rdi
callq 0x1e3800
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups (%rbp), %xmm0
movups 0xc(%rbp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %r15
movl -0x8(%r12), %eax
addq $0x1c, %rbp
cmpq %rax, %r15
jb 0x1a3ddb
cmpq $0x0, 0x40(%rsp)
je 0x1a3f66
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
leaq (%rsi,%r14), %rdi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rsi
addq %rcx, %rsi
callq 0x195511
addq (%rbx), %r14
movq 0x8(%rbx), %rsi
movq 0x28(%rsp), %r15
subq %r15, %rsi
movq %r14, %rdi
movss 0x3c(%rsp), %xmm0
callq 0x1a3c15
movl %eax, %r13d
jmp 0x1a3f6e
xorl %r13d, %r13d
movq 0x28(%rsp), %r15
movq %r15, 0x8(%rbx)
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x905bd(%rip), %rdi     # 0x234548
leaq 0x8f9f9(%rip), %rsi     # 0x23398b
leaq 0x905d9(%rip), %rcx     # 0x234572
movl $0xfb7, %edx            # imm = 0xFB7
callq 0x2110