// File: /workspace/github_cpp_makefile_star2_O3/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
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x1ab14e
movl $0x0, (%rax)
testq %rdi, %rdi
je 0x1ab1af
movq (%rdi), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1ab1af
movq 0x28(%rax), %rdi
movl %edx, %r10d
movq (%rdi,%r10,8), %rdi
testl %edi, %edi
je 0x1ab1af
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
movl (%rax,%r10), %r15d
testl %r15d, %r15d
js 0x1ab1a6
cmpl %ecx, -0x4(%rax,%r10)
je 0x1ab3f5
addq $0x18, %r10
cmpq %r10, %rdi
jne 0x1ab192
testq %rsi, %rsi
je 0x1ab3b8
movq 0x8(%rsi), %rdi
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,2), %r10
movl 0xc(%rdi,%r10,8), %eax
testq %rax, %rax
je 0x1ab3b8
movq %r9, -0x38(%rsp)
movq %r8, -0x30(%rsp)
movl 0x44(%rsi), %r8d
movl %r8d, -0x40(%rsp)
movl 0x40(%rsi), %esi
movl %esi, -0x3c(%rsp)
leaq (%rdi,%r10,8), %rsi
movq (%rsi), %r11
movl %ecx, %ebx
shrl %ebx
leaq 0xeb032(%rip), %rsi     # 0x296230
movq 0x18(%rsi), %rsi
movq %rsi, -0x18(%rsp)
leaq 0xea54a(%rip), %rsi     # 0x295758
movss 0x158(%rsi), %xmm1
movl %edx, %esi
movq %rsi, -0x10(%rsp)
xorl %ecx, %edx
movl %edx, -0x44(%rsp)
movl %ecx, -0x1c(%rsp)
andl $-0x2, %ecx
movl %ecx, -0x20(%rsp)
shlq $0x3, %rax
leaq (%rax,%rax,4), %rax
movq %rax, -0x8(%rsp)
xorl %r13d, %r13d
cmpl %ebx, 0xc(%r11,%r13)
jne 0x1ab3a9
movq 0x18(%r11,%r13), %rcx
movq -0x18(%rsp), %rax
movl (%rax,%rbx,8), %r8d
movq %rcx, -0x28(%rsp)
testl %ecx, %ecx
js 0x1ab275
movl 0x10(%r11,%r13), %ecx
movl 0x14(%r11,%r13), %r15d
subl %r15d, %r8d
movl %r8d, %r9d
movl %ecx, %r8d
jmp 0x1ab285
movl 0x10(%r11,%r13), %ecx
movl 0x14(%r11,%r13), %r15d
subl %r15d, %r8d
movl %ecx, %r9d
movq (%r11,%r13), %rdi
movq %rdi, %rax
shrq $0x20, %rax
movq -0x18(%rsp), %rdx
movl (%rdx,%rax,8), %r14d
cmpl %edi, %r8d
movl %edi, %ebp
cmovll %r8d, %ebp
movl 0x8(%r11,%r13), %eax
movl %r14d, %r10d
subl %eax, %r10d
cmpl %r9d, %r10d
movl %r9d, %edx
cmovll %r10d, %edx
cmpl -0x3c(%rsp), %ebp
jg 0x1ab3a9
cmpl -0x3c(%rsp), %edx
jg 0x1ab3a9
movl %eax, %esi
subl %edi, %esi
xorps %xmm2, %xmm2
cvtsi2ss %rsi, %xmm2
leal (%rsi,%rbp), %r12d
addl %edx, %r12d
xorps %xmm3, %xmm3
cvtsi2ss %r12, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x1ab3a9
subl %ecx, %r15d
xorps %xmm2, %xmm2
cvtsi2ss %r15, %xmm2
addl %ebp, %edx
addl %r15d, %edx
xorps %xmm3, %xmm3
cvtsi2ss %rdx, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x1ab3a9
cmpl %r9d, %r10d
setl -0x45(%rsp)
setg %bpl
cmpl %r8d, %edi
setg %cl
setl %r10b
orb %bpl, %cl
cmpb $0x1, %cl
jne 0x1ab39b
orb -0x45(%rsp), %r10b
je 0x1ab39b
cmpl -0x40(%rsp), %r12d
jl 0x1ab3a9
cmpl -0x40(%rsp), %edx
jl 0x1ab3a9
addl %eax, %r9d
movl %r14d, %ecx
subl %r9d, %ecx
movl %edi, %eax
subl %r8d, %eax
cmovlel %ecx, %eax
testl %eax, %eax
js 0x1ab393
xorl %esi, %esi
cmpl %r8d, %edi
setle %sil
setg %cl
cmpl $0x0, -0x28(%rsp)
setns %dl
shrq $0x1f, %rdi
andl $-0x2, %edi
orl %edi, %esi
cmpl -0x10(%rsp), %esi
jne 0x1ab3a9
xorb %cl, %dl
movzbl %dl, %ecx
orl -0x20(%rsp), %ecx
cmpl -0x1c(%rsp), %ecx
jne 0x1ab3a9
jmp 0x1ab3de
addl $0x3, %eax
cmpl $0x1, %eax
ja 0x1ab3a9
movq -0x28(%rsp), %rax
shrl $0x1f, %eax
cmpl -0x44(%rsp), %eax
je 0x1ab3c5
addq $0x28, %r13
cmpq %r13, -0x8(%rsp)
jne 0x1ab23e
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r15d, %esi
cmoval %esi, %r15d
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x1ab3eb
movl $0x1, (%rax)
jmp 0x1ab3eb
subl %eax, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movl %r14d, %r15d
movq -0x30(%rsp), %r8
movq -0x38(%rsp), %r9
movl %r15d, %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, %rcx
cmpq %r8, %rcx
cmovgq %rcx, %r8
xorl %eax, %eax
cmpq %r8, %rdx
setle %al
jmp 0x1ab3ba