// File: chhylp123[P]hifiasm/inter.cpp
// Function: update_exist_chain_adv(ul_idx_t const*, ul_ov_t*, unsigned long*, long, long, mg_lchain_t*)
void update_exist_chain_adv(const ul_idx_t *uref, ul_ov_t *ch, uint64_t *idx, int64_t idx_n, int64_t tid, mg_lchain_t *res)
{
	int64_t i, j, cov_i, sc = 0; memset(res, 0, sizeof(*res));
	ul_ov_t *li, *lj;
	if(idx_n <= 0) return;
	i = 0; 
	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 < idx_n; i++) {
		li = &(ch[idx[i]]); 

		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 >= 0) {
			lj = &(ch[idx[j]]); 
			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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2100
cmpq $0x0, -0x20(%rbp)
jg 0x2d7744
jmp 0x2d796a
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
shll %ecx
shrl %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x2d7940
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
shrl %eax
movl %eax, %eax
movq -0x30(%rbp), %rcx
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jge 0x2d7822
movq -0x58(%rbp), %rax
movl 0x4(%rax), %ecx
shll %ecx
shrl %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x30(%rbp), %rcx
movslq 0xc(%rcx), %rcx
cmpq %rcx, %rax
jge 0x2d7844
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x30(%rbp), %rcx
movslq 0x18(%rcx), %rcx
cmpq %rcx, %rax
jle 0x2d7866
movq -0x58(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jle 0x2d7888
movq -0x58(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jl 0x2d78ff
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x60(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edx
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
movq -0x28(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x2d0050
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2d792d
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %r8d
xorl %edx, %edx
leaq -0x48(%rbp), %r9
callq 0x110c0
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2d792f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2d77d0
cmpq $0x3fffffff, -0x50(%rbp) # imm = 0x3FFFFFFF
jle 0x2d7955
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, -0x68(%rbp)
jmp 0x2d795d
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x1c(%rax)
addq $0x70, %rsp
popq %rbp
retq