// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %rbp
movq 0x8(%rdi), %rdx
xorl %r13d, %r13d
testq %rdx, %rdx
je 0x1ad187
movq %rdi, %rbx
movq (%rdi), %r12
leaq (%rdx,%rdx,8), %rax
leaq (%rax,%rax,2), %r14
addq %rdx, %r14
movl -0x14(%r12,%r14), %eax
subl -0x18(%r12,%r14), %eax
cvtsi2ss %rax, %xmm3
cvtsi2ss %rsi, %xmm4
mulss %xmm0, %xmm4
ucomiss %xmm3, %xmm4
jae 0x1ad187
movl $0x1, %r13d
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x1ad187
movq %rcx, 0x50(%rsp)
movq %r8, 0x38(%rsp)
movq %r9, 0x48(%rsp)
movsd %xmm2, 0x60(%rsp)
movq %rdx, 0x30(%rsp)
addq %r14, %r12
movl -0xc(%r12), %r15d
movl -0x8(%r12), %ecx
leaq (%r15,%r15,8), %rax
leaq (%rax,%rax,2), %rax
addq %r15, %rbp
addq %rax, %rbp
movl %ecx, 0x28(%rsp)
movl %ecx, %esi
subl %r15d, %esi
movq %rbp, %rdi
movss %xmm1, 0x44(%rsp)
movaps %xmm1, %xmm0
callq 0x1ace38
testl %eax, %eax
jne 0x1ad187
cmpq $0x0, 0x50(%rsp)
sete %al
cmpq $0x0, 0x38(%rsp)
sete %cl
orb %al, %cl
cmpq $0x0, 0x48(%rsp)
sete %al
orb %cl, %al
movl $0x0, %r13d
jne 0x1ad187
cmpl 0x28(%rsp), %r15d
jae 0x1ad17b
movq $0x0, 0x28(%rsp)
testb $0x40, 0x1b(%rbp)
jne 0x1ad0b7
movl (%rbp), %r13d
movq $0x0, 0x58(%rsp)
movl $0x1, %r8d
movq 0x38(%rsp), %rdi
movq %r13, %rsi
leaq 0x58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x1a7f4d
testq %rax, %rax
jle 0x1ad199
movq 0x50(%rsp), %rcx
movq (%rcx), %rsi
imulq $0xa8, %r13, %rcx
cmpb $0x2, 0x2c(%rsi,%rcx)
jne 0x1ad199
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 0x1ad11e
leaq (%rcx,%rdx,8), %r8
movq 0x58(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
movq 0x38(%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 0x1a9863
addq %rax, 0x28(%rsp)
jmp 0x1ad11e
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1ad0fa
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rbx)
leaq (%rsi,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rsi, %rdx
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x1ee21d
movq %rax, (%rbx)
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 0x1acff0
cmpq $0x0, 0x28(%rsp)
je 0x1ad17b
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 0x19e2b4
addq (%rbx), %r14
movq 0x8(%rbx), %rsi
movq 0x30(%rsp), %r15
subq %r15, %rsi
movq %r14, %rdi
movss 0x44(%rsp), %xmm0
callq 0x1ace38
movl %eax, %r13d
jmp 0x1ad183
xorl %r13d, %r13d
movq 0x30(%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 0x93678(%rip), %rdi     # 0x240818
leaq 0x92ab4(%rip), %rsi     # 0x23fc5b
leaq 0x93694(%rip), %rcx     # 0x240842
movl $0xfb7, %edx            # imm = 0xFB7
callq 0x2110