// File: chhylp123[P]hifiasm/inter.cpp
// Function: get_ecov(ul_idx_t const*, ul_ov_t*, ul_ov_t*, long, long, double)
int64_t get_ecov(const ul_idx_t *uref, ul_ov_t *lv, ul_ov_t *lw, int64_t qlen, int64_t bw, double diff_ec_ul)
{
	int64_t dis_q = lv->qe - lw->qe, dis_t = 0, dif, mm;
	uint32_t i, v = ((lv->tn<<1)|lv->rev)^1, w = ((lw->tn<<1)|lw->rev)^1;
	const asg_t *g = uref->ug->g;
	uint32_t nv = asg_arc_n(g, v);
	asg_arc_t *av = asg_arc_a(g, v);
	for (i = 0; i < nv; i++) {
        if(av[i].del || av[i].v != w) continue;
		dis_t = ((uint32_t)av[i].ul);
		dis_t -= (lv->rev?lv->ts:g->seq[v>>1].len-lv->te);
		break;
    }
	
	dif = (dis_q>dis_t? dis_q-dis_t:dis_t-dis_q);
	mm = MAX(dis_q, dis_t); mm *= diff_ec_ul; if(mm < bw) mm = bw;
	// if((v>>1) == 1163 && (w>>1) == 1168) fprintf(stderr, ">>>>>>dis_q:%ld, dis_t:%ld, dif:%ld, mm:%ld\n", dis_q, dis_t, dif, mm);
	if(dif <= mm) return 1;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x18, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
xorl $0x1, %eax
movl %eax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x20(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
xorl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x60(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x74(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x60(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x28d17c
movq -0x80(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x28d0fc
movq -0x80(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x64(%rbp), %eax
je 0x28d0fe
jmp 0x28d16e
movq -0x80(%rbp), %rax
movl -0x5c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x28d133
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x84(%rbp)
jmp 0x28d157
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x60(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x28d17c
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x28d0c1
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jle 0x28d197
movq -0x40(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x28d1a6
movq -0x48(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jl 0x28d1c8
movq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x28d1d3
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movsd -0x38(%rbp), %xmm1
cvtsi2sdq -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x28d208
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jg 0x28d21c
movq $0x1, -0x8(%rbp)
jmp 0x28d224
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x18, %rsp
popq %rbp
retq
nop