// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x20(%rsp)
movq 0x88(%rsp), %rbx
andq $0x0, (%rbx)
cmpq $0x0, 0x80(%rsp)
je 0x16b45d
movq %r9, 0x10(%rsp)
movq %r8, 0x18(%rsp)
movq 0x8(%rsi), %rax
movl 0x44(%rsi), %edi
movl %edi, 0xc(%rsp)
movl 0x40(%rsi), %esi
movl %esi, 0x8(%rsp)
movl %edx, %esi
movq %rsi, 0x28(%rsp)
shrl %edx
imulq $0x18, %rdx, %rdx
leaq (%rax,%rdx), %r14
movl 0xc(%rax,%rdx), %eax
movl %ecx, (%rsp)
movl %ecx, %r13d
shrl %r13d
leaq 0xe8e4d(%rip), %rcx     # 0x254230
movq 0x18(%rcx), %rbx
leaq 0xe836a(%rip), %rcx     # 0x253758
movss 0x158(%rcx), %xmm0
movss %xmm0, 0x4(%rsp)
imulq $0x28, %rax, %r15
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x16b456
movq (%r14), %r12
cmpl %r13d, 0xc(%r12,%rbp)
jne 0x16b450
leaq (%r12,%rbp), %rdi
movl 0x4(%rdi), %eax
movl (%rbx,%rax,8), %esi
movl (%rbx,%r13,8), %edx
movl 0x8(%rsp), %ecx
movss 0x4(%rsp), %xmm0
movl 0xc(%rsp), %r8d
leaq 0x30(%rsp), %r9
callq 0x15d560
testl %eax, %eax
js 0x16b450
movq 0x28(%rsp), %rax
cmpl %eax, 0x34(%rsp)
jne 0x16b450
movl (%rsp), %eax
cmpl %eax, 0x38(%rsp)
je 0x16b4a8
addq $0x28, %rbp
jmp 0x16b402
xorl %eax, %eax
jmp 0x16b50f
movq (%rdi), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %r14
movq 0x28(%rax), %rax
movl %edx, %edx
movq (%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rdi
imulq $0x18, %rax, %rdx
leaq (%rdx,%r14), %r11
addq $0x12, %r11
xorl %eax, %eax
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0x16b50f
movl -0x6(%r11,%r10), %esi
testl %esi, %esi
js 0x16b4a2
cmpl %ecx, -0xa(%r11,%r10)
je 0x16b4ce
addq $0x18, %r10
jmp 0x16b48d
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x3c(%rsp), %esi
movzbl 0x20(%r12,%rbp), %eax
movq 0x88(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %r9
jmp 0x16b4da
addq %r14, %rdx
movzbl 0x12(%r10,%rdx), %eax
movq %rax, (%rbx)
movl %esi, %eax
movq %rax, %rcx
subq %r9, %rcx
cmovgq %rax, %r9
movq %rcx, %rdx
negq %rdx
cmovsq %rcx, %rdx
cvtsi2sd %r9, %xmm0
mulsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq %r8, %rax
cmovgq %rax, %r8
xorl %eax, %eax
cmpq %r8, %rdx
setle %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq