// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: update_exist_chain(ul_idx_t const*, ul_ov_t*, unsigned long*, long, long, long, double, mg_lchain_t*)
void update_exist_chain(const ul_idx_t *uref, ul_ov_t *ch, uint64_t *idx, int64_t idx_n, int64_t tid, int64_t bw, 
double diff_ec_ul, mg_lchain_t *res)
{
	int64_t i, j, cov_i, i_qs, i_qe, i_ts, i_te, j_qs, j_qe, j_ts, j_te, dq, dt, dd, mm, sc = 0; 
	int64_t tlen = uref->ug->g->seq[tid].len; memset(res, 0, sizeof(*res));
	ul_ov_t *li, *lj;
	if(idx_n <= 0) return;
	i = idx_n - 1; 
	res->qs = (ch[idx[i]].qs<<1)>>1; res->qe = ch[idx[i]].qe;
	res->rs = ch[idx[i]].ts; res->re = ch[idx[i]].te;
	for (; i >= 0; i--) {
		li = &(ch[idx[i]]); 
		i_qs = (li->qs<<1)>>1; i_qe = li->qe; 
		i_ts = (li->rev?(tlen-li->te):(li->ts));
		i_te = (li->rev?(tlen-li->ts):(li->te));

		if((int64_t)((li->qs<<1)>>1) < res->qs) res->qs = ((li->qs<<1)>>1); 
		if((int64_t)li->ts < res->rs) res->rs = li->ts;
		if((int64_t)li->qe > res->qe) res->qe = li->qe;
		if((int64_t)li->te > res->re) res->re = li->te;

		cov_i = 0; j = i + 1;
		if(j < idx_n) {
			lj = &(ch[idx[j]]); 
			j_qs = (lj->qs<<1)>>1; j_qe = lj->qe; 
			j_ts = (lj->rev?(tlen-lj->te):(lj->ts));
			j_te = (lj->rev?(tlen-lj->ts):(lj->te));
			if(j_qs <= i_qs && j_qe <= i_qe && j_ts <= i_ts && j_te <= i_te) {///co-linear
				assert(li->rev == lj->rev);
				if(j_qs == i_qs && j_qe == i_qe && j_ts == i_ts && j_te == i_te) continue;
				dq = i_qe - j_qs; dt = i_te - j_ts;
                dd = (dq>dt? dq-dt:dt-dq);
                mm = MAX(dq, dt); mm *= diff_ec_ul; if(mm < bw) mm = bw;
				if(dd <= mm) {///pass distance checking
                    sc += get_add_cov_score(uref, lj->ts, lj->te, li->ts, li->te, tid, &cov_i);
                }
			}
		} else {
			sc += retrieve_u_cov_region(uref, tid, 0, li->ts, li->te, &cov_i);
		}
	}
	res->score = (sc>0x3FFFFFFF?0x3FFFFFFF:sc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movsd %xmm0, 0x60(%rsp)
movq %r9, 0x28(%rsp)
movq 0xa0(%rsp), %rbx
movq %rdi, 0x48(%rsp)
movq (%rdi), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq %r8, 0x50(%rsp)
movl (%rax,%r8,8), %eax
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rbx)
movupd %xmm0, (%rbx)
movq $0x0, 0x20(%rbx)
testq %rcx, %rcx
jle 0x1d1649
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x40(%rsp)
movq -0x8(%rdx,%rcx,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl 0x4(%rsi,%rcx), %eax
andl %ebp, %eax
movl %eax, 0x14(%rbx)
movl 0x8(%rsi,%rcx), %eax
movl %eax, 0x18(%rbx)
movq 0x10(%rsi,%rcx), %rax
movq %rax, 0xc(%rbx)
movq $0x0, 0x20(%rsp)
movq %r14, %r15
movq %rdx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq -0x8(%r12,%r15,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
leaq (%rcx,%r13), %rdx
cmpl $0x0, 0x18(%r13,%rcx)
js 0x1d147f
movl 0x10(%rdx), %r8d
movl 0x14(%rdx), %r10d
movq %r8, %rsi
movq %r10, %rax
jmp 0x1d1495
movl 0x10(%rdx), %r8d
movl 0x14(%rdx), %r10d
movq 0x40(%rsp), %rax
movq %rax, %rsi
subq %r10, %rsi
subq %r8, %rax
movl 0x4(%r13,%rcx), %r9d
andl %ebp, %r9d
movl 0x8(%r13,%rcx), %edi
cmpl 0x14(%rbx), %r9d
jge 0x1d14ac
movl %r9d, 0x14(%rbx)
movl %r8d, %ecx
movslq 0xc(%rbx), %r11
cmpq %r11, %rcx
jge 0x1d14bc
movl %r8d, 0xc(%rbx)
movslq 0x18(%rbx), %r8
cmpq %r8, %rdi
jle 0x1d14c8
movl %edi, 0x18(%rbx)
movl %r10d, %r8d
movslq 0x10(%rbx), %r11
cmpq %r11, %r8
jle 0x1d14d8
movl %r10d, 0x10(%rbx)
movq $0x0, 0x58(%rsp)
cmpq %r14, %r15
jge 0x1d1516
movq (%r12,%r15,8), %r10
leaq (%r10,%r10,8), %r11
leaq (%r11,%r11,2), %r14
addq %r10, %r14
leaq (%r14,%r13), %r10
movl 0x18(%r13,%r14), %ebp
testl %ebp, %ebp
js 0x1d1536
movl 0x10(%r10), %r11d
movl 0x14(%r10), %r10d
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
jmp 0x1d155e
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
xorl %edx, %edx
leaq 0x58(%rsp), %r9
callq 0x363d1
addq %rax, 0x20(%rsp)
jmp 0x1d15c0
movl 0x10(%r10), %ebx
movl 0x14(%r10), %r12d
movq 0x40(%rsp), %r10
movq %r10, %r11
movq %r12, 0x38(%rsp)
subq %r12, %r11
movq %rbx, 0x30(%rsp)
subq %rbx, %r10
movq 0xa0(%rsp), %rbx
movl 0x4(%r13,%r14), %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
cmpl %r9d, %r12d
ja 0x1d15b1
movl 0x8(%r13,%r14), %r14d
cmpl %edi, %r14d
ja 0x1d15b1
cmpq %rsi, %r11
jg 0x1d15b1
cmpq %rax, %r10
jg 0x1d15b1
xorl 0x18(%rdx), %ebp
js 0x1d1658
cmpl %r9d, %r12d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
jne 0x1d15cb
cmpl %edi, %r14d
jne 0x1d15cb
cmpq %rsi, %r11
jne 0x1d15cb
cmpq %rax, %r10
jne 0x1d15cb
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0x1d15c0
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r12
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
decq %r15
jg 0x1d1453
jmp 0x1d1635
subq %r12, %rdi
subq %r11, %rax
movq %rdi, %rsi
subq %rax, %rsi
cmovgq %rdi, %rax
movq %rsi, %rdx
negq %rdx
cmovsq %rsi, %rdx
cvtsi2sd %rax, %xmm0
mulsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq 0x28(%rsp), %rax
jg 0x1d1601
movq 0x28(%rsp), %rax
cmpq %rax, %rdx
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r12
jg 0x1d15c0
movl 0x30(%rsp), %esi
movl 0x38(%rsp), %edx
leaq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %r9
callq 0x1ce6cc
jmp 0x1d152c
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rcx
cmpq %rax, %rcx
cmovlq %rcx, %rax
movl %eax, 0x1c(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x70c39(%rip), %rdi     # 0x242298
leaq 0x6e5f5(%rip), %rsi     # 0x23fc5b
leaq 0x710e4(%rip), %rcx     # 0x242751
movl $0x399e, %edx           # imm = 0x399E
callq 0x2110