// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: get_ecov_adv(ul_idx_t const*, ug_opt_t const*, unsigned int, unsigned int, long, double, long, unsigned long, long*)
int64_t get_ecov_adv(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 *contain_off)
{
	int64_t dt = -1, dif, mm; if(contain_off) (*contain_off) = 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; 
			// if((v>>1)==25288) fprintf(stderr, "+++v:%u, w:%u, ou:%ld\n", v, w, dt);
			// if((v>>1) == 3012 && (w>>1) == 3011) fprintf(stderr, "******************\n");
			if(contain_off) {
				(*contain_off) = av[i].ou;
				if(av[i].ou >= OU_MASK) {				
					x = get_ug_edge_src(uref->ug, uopt->sources, uopt->max_hang, uopt->min_ovlp, 
																				av[i].ul>>32, av[i].v);
					(*contain_off) = x->cc;
					// if(v==1772 && w==1769) fprintf(stderr, "---v:%u, w:%u, cc:%u\n", v, w, x->cc);
				}
			}
			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; if(contain_off) (*contain_off) = src[x].buffer[z].cc;
			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
movq %r9, %r12
movsd %xmm0, 0x20(%rsp)
movq %r8, %r15
movq 0x88(%rsp), %rbx
movq 0x80(%rsp), %rax
testq %rbx, %rbx
je 0x1a2529
movq $0x0, (%rbx)
testq %rax, %rax
je 0x1a25fe
movq 0x8(%rsi), %rax
movl %edx, %edi
shrl %edi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rax,%rdi,8), %ebx
movq $-0x1, %r14
testq %rbx, %rbx
je 0x1a2661
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movl 0x44(%rsi), %r8d
movl %r8d, 0x1c(%rsp)
movl 0x40(%rsi), %r13d
leaq (%rax,%rdi,8), %rax
movq (%rax), %r15
movl %ecx, 0x14(%rsp)
movl %ecx, %ebp
shrl %ebp
leaq 0xe8cb2(%rip), %rax     # 0x28b230
movq 0x18(%rax), %r12
leaq 0xe81cf(%rip), %rax     # 0x28a758
movss 0x158(%rax), %xmm0
movss %xmm0, 0x18(%rsp)
movl %edx, %eax
movq %rax, 0x28(%rsp)
movl 0xc(%r15), %eax
cmpl %ebp, %eax
jne 0x1a25ea
movl 0x4(%r15), %ecx
movl (%r12,%rcx,8), %esi
movl (%r12,%rax,8), %edx
movq %r15, %rdi
movl %r13d, %ecx
movss 0x18(%rsp), %xmm0
movl 0x1c(%rsp), %r8d
leaq 0x30(%rsp), %r9
callq 0x19c0d3
testl %eax, %eax
js 0x1a25ea
movq 0x28(%rsp), %rax
cmpl %eax, 0x34(%rsp)
jne 0x1a25ea
movl 0x14(%rsp), %eax
cmpl %eax, 0x38(%rsp)
je 0x1a26af
addq $0x28, %r15
decq %rbx
jne 0x1a259e
movq 0x8(%rsp), %r15
movq (%rsp), %r12
jmp 0x1a2661
movq (%rdi), %rdi
movq 0x18(%rdi), %rax
movq 0x28(%rax), %r8
movl %edx, %edx
movq (%r8,%rdx,8), %r8
testl %r8d, %r8d
je 0x1a265a
movq 0x8(%rax), %rax
movq %r8, %rdx
shrq $0x20, %rdx
movl %r8d, %r9d
leaq (%rdx,%rdx,2), %r11
leaq (%rax,%r11,8), %r8
addq $0x10, %r8
shlq $0x3, %r9
leaq (%r9,%r9,2), %rdx
xorl %r10d, %r10d
movslq -0x4(%r8,%r10), %r14
testq %r14, %r14
js 0x1a2651
movl -0x8(%r8,%r10), %r9d
cmpl %ecx, %r9d
je 0x1a26dd
addq $0x18, %r10
cmpq %r10, %rdx
jne 0x1a2639
movq $-0x1, %r14
testq %r14, %r14
js 0x1a269e
movq %r14, %rax
subq %r12, %rax
cmovgq %r14, %r12
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
mulsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq %r15, %rax
cmovgq %rax, %r15
xorl %eax, %eax
cmpq %r15, %rcx
setle %al
jmp 0x1a26a0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x3c(%rsp), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq 0x88(%rsp), %rcx
testq %rcx, %rcx
je 0x1a25f3
movq 0x18(%r15), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, (%rcx)
jmp 0x1a25f3
testq %rbx, %rbx
je 0x1a2661
leaq (%rax,%r11,8), %rax
movzwl 0x10(%r10,%rax), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq %rcx, (%rbx)
movl 0x10(%r10,%rax), %eax
notl %eax
testl $0x3fff, %eax           # imm = 0x3FFF
jne 0x1a2661
movq 0x8(%rsi), %rax
movslq 0x40(%rsi), %rdx
movslq 0x44(%rsi), %rcx
movl -0xc(%r8,%r10), %r8d
movq %rax, %rsi
callq 0x1a23dc
movq 0x18(%rax), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, (%rbx)
jmp 0x1a2661