// File: chhylp123[P]hifiasm/inter.cpp
// Function: get_ecov_el(ul_idx_t const*, ug_opt_t const*, unsigned int, unsigned int, long, double, long, unsigned long, long*)
int64_t get_ecov_el(const ul_idx_t *uref, const ug_opt_t *uopt, uint32_t v, uint32_t w, int64_t bw, double diff_ec_ul, int64_t dq, uint64_t mode, int64_t *el)
{
	int64_t dt = -1, dif, mm; (*el) = 0;
	uint32_t nv, i; asg_arc_t *av = NULL; ///ma_hit_t *x = NULL;
	if(!mode) {
		const asg_t *g = uref?uref->ug->g:NULL;
		nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
		for (i = 0; i < nv; i++) {
			if(av[i].del || av[i].v != w) continue;
			dt = av[i].ol; (*el) = av[i].el;
			// if(v==1772 && w==1769) fprintf(stderr, "+++v:%u, w:%u, ou:%u\n", v, w, av[i].ou);
			// if((v>>1) == 3012 && (w>>1) == 3011) fprintf(stderr, "******************\n");
			break;
		}
	}else {
		ma_hit_t_alloc* src = uopt->sources;
		int64_t min_ovlp = uopt->min_ovlp;
		int64_t max_hang = uopt->max_hang;
		uint64_t z, qn, tn, x = v>>1; int32_t r = 1; asg_arc_t e;
		for (z = 0; z < src[x].length; z++) {
			qn = Get_qn(src[x].buffer[z]); tn = Get_tn(src[x].buffer[z]);
			if(tn != (w>>1)) continue;
			r = ma_hit2arc(&(src[x].buffer[z]), Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), max_hang, asm_opt.max_hang_rate, min_ovlp, &e);
			if(r < 0) continue;
			if((e.ul>>32) != v || e.v != w) continue;
			dt = e.ol; (*el) = src[x].buffer[z].el;
			break;
		}
	}
	if(dt < 0) return 0;
	dif = (dq>dt? dq-dt:dt-dq);
	mm = MAX(dq, dt); 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 $0xe0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $-0x1, -0x40(%rbp)
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x60(%rbp)
cmpq $0x0, 0x10(%rbp)
jne 0x2a22b6
cmpq $0x0, -0x10(%rbp)
je 0x2a21df
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x2a21ea
xorl %eax, %eax
movq %rax, -0xc8(%rbp)
jmp 0x2a21ea
movq -0xc8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x68(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x2a22b1
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2a226b
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x2a226d
jmp 0x2a22a6
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzbl 0x12(%rax), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2a22b1
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2a2234
jmp 0x2a2487
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x1c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0xa0(%rbp)
movl $0x1, -0xa4(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
imulq $0x18, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2a2485
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x2a238b
jmp 0x2a246e
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x88(%rbp), %rax
addq %rax, %rdi
leaq 0x122f21(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x122f09(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movl %eax, %ecx
leaq 0x122413(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x78(%rbp), %rax
movl %eax, %r8d
leaq -0xc0(%rbp), %r9
callq 0x287f40
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jge 0x2a2411
jmp 0x2a246e
movq -0xc0(%rbp), %rax
shrq $0x20, %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x2a242f
movl -0xb8(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x2a2431
jmp 0x2a246e
movl -0xb4(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movzbl 0x20(%rax), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2a2485
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x2a22fd
jmp 0x2a2487
cmpq $0x0, -0x40(%rbp)
jge 0x2a249b
movq $0x0, -0x8(%rbp)
jmp 0x2a2543
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x2a24b6
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x2a24c5
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x2a24e7
movq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x2a24f2
movq -0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x50(%rbp)
movsd -0x30(%rbp), %xmm1
cvtsi2sdq -0x50(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x2a2527
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jg 0x2a253b
movq $0x1, -0x8(%rbp)
jmp 0x2a2543
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq