// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: get_ecov_adv_back(ul_idx_t const*, ug_opt_t const*, unsigned int, unsigned int, long, double, long, unsigned int*)
int64_t get_ecov_adv_back(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, uint32_t *is_contain)
{
	int64_t dt = -1, dif, mm; if(is_contain) (*is_contain) = 0;
	const asg_t *g = uref?uref->ug->g:NULL;
	uint32_t nv, i; asg_arc_t *av = NULL;
	if(g) {
		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;
			break;
		}
	}

	if(dt < 0 && uopt) {
		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) {
				if(r == MA_HT_QCONT || r == MA_HT_TCONT) {
					if(src[x].buffer[z].rev == ((uint32_t)(v^w))) {
						dt = Get_qe(src[x].buffer[z]) - Get_qs(src[x].buffer[z]);
						if(dt < Get_te(src[x].buffer[z]) - Get_ts(src[x].buffer[z])) {
							dt = Get_te(src[x].buffer[z]) - Get_ts(src[x].buffer[z]);
						}
						if(is_contain) (*is_contain) = 1;
						break;
					}
				}
				continue;
			}
			if((e.ul>>32) != v || e.v != w) continue;
			dt = e.ol;
			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 $0x58, %rsp
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x162eec
andl $0x0, (%rax)
movl %edx, %eax
movq %rax, 0x30(%rsp)
testq %rdi, %rdi
je 0x162f4a
movq (%rdi), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x162f4a
movq 0x8(%rax), %r11
movq 0x28(%rax), %rax
movq 0x30(%rsp), %rdi
movq (%rax,%rdi,8), %rax
movl %eax, %edi
shrq $0x20, %rax
imulq $0x18, %rdi, %r10
imulq $0x18, %rax, %rax
addq %rax, %r11
addq $0xc, %r11
xorl %edi, %edi
cmpq %rdi, %r10
je 0x162f4a
movl (%r11,%rdi), %eax
testl %eax, %eax
js 0x162f44
cmpl %ecx, -0x4(%r11,%rdi)
je 0x163056
addq $0x18, %rdi
jmp 0x162f2c
testq %rsi, %rsi
je 0x16303a
movq %r9, (%rsp)
movsd %xmm0, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movq 0x8(%rsi), %rax
movl 0x44(%rsi), %edi
movl %edi, 0x2c(%rsp)
movl 0x40(%rsi), %esi
movl %esi, 0x28(%rsp)
movl %edx, %esi
shrl %esi
imulq $0x18, %rsi, %rsi
leaq (%rax,%rsi), %rbx
movl 0xc(%rax,%rsi), %eax
movl %ecx, %r14d
shrl %r14d
leaq 0xf129f(%rip), %rsi     # 0x254230
movq 0x18(%rsi), %rsi
movq %rsi, 0x38(%rsp)
leaq 0xf07b7(%rip), %rsi     # 0x253758
movss 0x158(%rsi), %xmm0
movss %xmm0, 0x24(%rsp)
movl %ecx, 0x20(%rsp)
xorl %ecx, %edx
movl %edx, 0x1c(%rsp)
imulq $0x28, %rax, %r12
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x16303a
movq (%rbx), %r13
cmpl %r14d, 0xc(%r13,%rbp)
jne 0x163034
movq %r13, %rdi
addq %rbp, %rdi
movq (%rdi), %r15
movq %r15, %rax
shrq $0x20, %rax
movq 0x38(%rsp), %rcx
movl (%rcx,%rax,8), %esi
movl (%rcx,%r14,8), %edx
movl 0x28(%rsp), %ecx
movss 0x24(%rsp), %xmm0
movl 0x2c(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x15d560
testl %eax, %eax
js 0x16301e
movq 0x30(%rsp), %rax
cmpl %eax, 0x44(%rsp)
jne 0x163034
movl 0x20(%rsp), %eax
cmpl %eax, 0x48(%rsp)
jne 0x163034
jmp 0x16303e
addl $0x3, %eax
cmpl $0x1, %eax
ja 0x163034
movl 0x18(%r13,%rbp), %eax
shrl $0x1f, %eax
cmpl 0x1c(%rsp), %eax
je 0x163098
addq $0x28, %rbp
jmp 0x162fbf
xorl %eax, %eax
jmp 0x163089
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x4c(%rsp), %eax
movq 0x10(%rsp), %r8
movsd 0x8(%rsp), %xmm0
movq (%rsp), %r9
movl %eax, %eax
movq %rax, %rcx
subq %r9, %rcx
cmovgq %rax, %r9
movq %rcx, %rdx
negq %rdx
cmovsq %rcx, %rdx
cvtsi2sd %r9, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cmpq %r8, %rax
cmovgq %rax, %r8
xorl %eax, %eax
cmpq %r8, %rdx
setle %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r13,%rbp), %ecx
movl 0x14(%r13,%rbp), %eax
subl %r15d, %ecx
subl 0x10(%r13,%rbp), %eax
cmpl %eax, %ecx
cmoval %ecx, %eax
movq 0x90(%rsp), %rcx
testq %rcx, %rcx
je 0x163047
movl $0x1, (%rcx)
jmp 0x163047