// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $-0x1, -0x40(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x291903
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
cmpq $0x0, -0x10(%rbp)
je 0x29191e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x291929
xorl %eax, %eax
movq %rax, -0xc8(%rbp)
jmp 0x291929
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x2919ea
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x2919e8
movq -0x68(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2919bd
movq -0x68(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x2919bf
jmp 0x2919dd
movq -0x68(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0x2919e8
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x291986
jmp 0x2919ea
cmpq $0x0, -0x40(%rbp)
jge 0x291ce6
cmpq $0x0, -0x18(%rbp)
je 0x291ce6
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x1c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0xa0(%rbp)
movl $0x1, -0xa4(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
imulq $0x18, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x291ce4
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x291ad5
jmp 0x291ccd
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x88(%rbp), %rax
addq %rax, %rdi
leaq 0x1337d7(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x1337bf(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movl %eax, %ecx
leaq 0x132cc9(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x78(%rbp), %rax
movl %eax, %r8d
leaq -0xc0(%rbp), %r9
callq 0x287f40
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jge 0x291c9a
cmpl $-0x2, -0xa4(%rbp)
je 0x291b73
cmpl $-0x3, -0xa4(%rbp)
jne 0x291c98
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movl -0x1c(%rbp), %ecx
xorl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jne 0x291c96
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x70(%rbp), %rcx
imulq $0x18, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x88(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x70(%rbp), %rcx
imulq $0x18, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x88(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq -0x70(%rbp), %rdx
imulq $0x18, -0xa0(%rbp), %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
imulq $0x28, -0x88(%rbp), %rsi
addq %rsi, %rdx
subl 0x10(%rdx), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jge 0x291c83
movq -0x70(%rbp), %rax
imulq $0x18, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x88(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x70(%rbp), %rcx
imulq $0x18, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x88(%rbp), %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x291c94
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x291ce4
jmp 0x291c98
jmp 0x291ccd
movq -0xc0(%rbp), %rax
shrq $0x20, %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x291cb8
movl -0xb8(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x291cba
jmp 0x291ccd
movl -0xb4(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0x291ce4
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x291a47
jmp 0x291ce6
cmpq $0x0, -0x40(%rbp)
jge 0x291cfa
movq $0x0, -0x8(%rbp)
jmp 0x291da2
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x291d15
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x291d24
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x291d46
movq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x291d51
movq -0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x50(%rbp)
movsd -0x30(%rbp), %xmm1
cvtsi2sdq -0x50(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x291d86
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jg 0x291d9a
movq $0x1, -0x8(%rbp)
jmp 0x291da2
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nop