// File: /workspace/github_cpp_makefile_star2_O1/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
movsd %xmm0, 0x30(%rsp)
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x1a21e1
movl $0x0, (%rax)
testq %rdi, %rdi
je 0x1a21ef
movq (%rdi), %rax
movq 0x18(%rax), %rax
jmp 0x1a21f1
xorl %eax, %eax
testq %rax, %rax
je 0x1a2242
movq 0x28(%rax), %rdi
movl %edx, %r10d
movq (%rdi,%r10,8), %rdi
testl %edi, %edi
je 0x1a2242
movq 0x8(%rax), %rax
movq %rdi, %r10
shrq $0x20, %r10
movl %edi, %edi
leaq (%r10,%r10,2), %r10
leaq (%rax,%r10,8), %rax
addq $0xc, %rax
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
xorl %r10d, %r10d
movslq (%rax,%r10), %r15
testq %r15, %r15
js 0x1a2239
cmpl %ecx, -0x4(%rax,%r10)
je 0x1a2249
addq $0x18, %r10
cmpq %r10, %rdi
jne 0x1a2229
movq $-0x1, %r15
testq %rsi, %rsi
je 0x1a235e
testq %r15, %r15
jns 0x1a235e
movq 0x8(%rsi), %rax
movl %edx, %edi
shrl %edi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rax,%rdi,8), %r14d
movq $-0x1, %r15
testq %r14, %r14
je 0x1a235e
movq %r9, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl 0x44(%rsi), %r8d
movl %r8d, 0x2c(%rsp)
movl 0x40(%rsi), %esi
movl %esi, 0x28(%rsp)
leaq (%rax,%rdi,8), %rax
movq (%rax), %r12
movl %ecx, %ebp
shrl %ebp
leaq 0xe8f88(%rip), %rax     # 0x28b230
movq 0x18(%rax), %r13
leaq 0xe84a5(%rip), %rax     # 0x28a758
movss 0x158(%rax), %xmm0
movss %xmm0, 0x24(%rsp)
movl %edx, %eax
movq %rax, 0x38(%rsp)
movl %ecx, 0x20(%rsp)
xorl %ecx, %edx
movl %edx, 0x1c(%rsp)
movl 0xc(%r12), %eax
cmpl %ebp, %eax
jne 0x1a233d
movq (%r12), %rbx
movq %rbx, %rcx
shrq $0x20, %rcx
movl (%r13,%rcx,8), %esi
movl (%r13,%rax,8), %edx
movq %r12, %rdi
movl 0x28(%rsp), %ecx
movss 0x24(%rsp), %xmm0
movl 0x2c(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x19c0d3
testl %eax, %eax
js 0x1a2327
movq 0x38(%rsp), %rax
cmpl %eax, 0x44(%rsp)
jne 0x1a233d
movl 0x20(%rsp), %eax
cmpl %eax, 0x48(%rsp)
jne 0x1a233d
jmp 0x1a2348
addl $0x3, %eax
cmpl $0x1, %eax
ja 0x1a233d
movl 0x18(%r12), %eax
shrl $0x1f, %eax
cmpl 0x1c(%rsp), %eax
je 0x1a23ac
addq $0x28, %r12
decq %r14
jne 0x1a22d2
jmp 0x1a2354
movl 0x4c(%rsp), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
testq %r15, %r15
js 0x1a239b
movq %r15, %rax
subq %r9, %rax
cmovgq %r15, %r9
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
mulsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq %r8, %rax
cmovgq %rax, %r8
xorl %eax, %eax
cmpq %r8, %rcx
setle %al
jmp 0x1a239d
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r12), %eax
movl 0x14(%r12), %r15d
subl %ebx, %eax
subl 0x10(%r12), %r15d
cmpl %r15d, %eax
cmoval %eax, %r15d
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x1a2354
movl $0x1, (%rax)
jmp 0x1a2354