// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x18(%rbp), %rax
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, 0x18(%rbp)
je 0x292048
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
cmpq $0x0, 0x10(%rbp)
jne 0x292200
cmpq $0x0, -0x10(%rbp)
je 0x29207e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0xd0(%rbp)
jmp 0x292089
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
jmp 0x292089
movq -0xd0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%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, -0x60(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x2921fb
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x29210e
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x292113
jmp 0x2921ed
movq -0x60(%rbp), %rax
movl -0x58(%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)
cmpq $0x0, 0x18(%rbp)
je 0x2921eb
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
cmpl $0x3fff, %eax           # imm = 0x3FFF
jb 0x2921e9
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rdx
movq -0x18(%rbp), %rax
movslq 0x44(%rax), %rcx
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %r8d
imulq $0x18, %r8, %r8
addq %r8, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %r8d
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %r9d
imulq $0x18, %r9, %r9
addq %r9, %rax
movl 0x8(%rax), %r9d
callq 0x291db0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2921eb
jmp 0x2921fb
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2920d3
jmp 0x2923e6
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x1c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0xa8(%rbp)
movl $0x1, -0xac(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x78(%rbp), %rcx
imulq $0x18, -0xa8(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2923e4
movq -0x78(%rbp), %rax
imulq $0x18, -0xa8(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0x78(%rbp), %rax
imulq $0x18, -0xa8(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x90(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x2922d8
jmp 0x2923cd
movq -0x78(%rbp), %rax
imulq $0x18, -0xa8(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x90(%rbp), %rax
addq %rax, %rdi
leaq 0x132fd4(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x132fbc(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0xa0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x88(%rbp), %rax
movl %eax, %ecx
leaq 0x1324c3(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x80(%rbp), %rax
movl %eax, %r8d
leaq -0xc8(%rbp), %r9
callq 0x287f40
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jge 0x292361
jmp 0x2923cd
movq -0xc8(%rbp), %rax
shrq $0x20, %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x29237f
movl -0xc0(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x292381
jmp 0x2923cd
movl -0xbc(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x2923cb
movq -0x78(%rbp), %rax
imulq $0x18, -0xa8(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x90(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
andq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2923e4
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x29224a
jmp 0x2923e6
cmpq $0x0, -0x40(%rbp)
jge 0x2923fa
movq $0x0, -0x8(%rbp)
jmp 0x2924a2
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x292415
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x292424
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x292446
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x292451
movq -0x40(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%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 0x292486
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jg 0x29249a
movq $0x1, -0x8(%rbp)
jmp 0x2924a2
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nop