// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r14
movq %r8, %rbx
movl %ecx, %r10d
movq 0x78(%rsp), %r15
movq 0x70(%rsp), %rax
testq %r15, %r15
je 0x1ab66d
movq $0x0, (%r15)
testq %rax, %rax
je 0x1ab87a
movq 0x8(%rsi), %rcx
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,2), %rdi
movl 0xc(%rcx,%rdi,8), %eax
testq %rax, %rax
je 0x1ab8d2
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movl 0x44(%rsi), %r8d
movl %r8d, (%rsp)
movl 0x40(%rsi), %esi
movl %esi, 0x4(%rsp)
leaq (%rcx,%rdi,8), %rcx
movq (%rcx), %rdi
movl %r10d, %r8d
shrl %r8d
leaq 0xeab74(%rip), %rcx     # 0x296230
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rsp)
leaq 0xea08c(%rip), %rcx     # 0x295758
movss 0x158(%rcx), %xmm3
movl %edx, %ecx
movq %rcx, 0x30(%rsp)
movl %r10d, 0x14(%rsp)
andl $-0x2, %r10d
movl %r10d, 0x10(%rsp)
shlq $0x3, %rax
leaq (%rax,%rax,4), %r13
xorl %edx, %edx
cmpl %r8d, 0xc(%rdi,%rdx)
jne 0x1ab7bc
movq 0x18(%rdi,%rdx), %rcx
movq 0x8(%rsp), %rax
movl (%rax,%r8,8), %ebx
testl %ecx, %ecx
movq %rcx, 0x18(%rsp)
js 0x1ab728
movl 0x10(%rdi,%rdx), %eax
movl 0x14(%rdi,%rdx), %r11d
subl %r11d, %ebx
movl %ebx, %r15d
movl %eax, %ebx
jmp 0x1ab737
movl 0x10(%rdi,%rdx), %eax
movl 0x14(%rdi,%rdx), %r11d
subl %r11d, %ebx
movl %eax, %r15d
movq (%rdi,%rdx), %r14
movq %r14, %rcx
shrq $0x20, %rcx
movq 0x8(%rsp), %rsi
movl (%rsi,%rcx,8), %r12d
cmpl %r14d, %ebx
movl %r14d, %r10d
cmovll %ebx, %r10d
movl 0x8(%rdi,%rdx), %ecx
movl %r12d, %ebp
subl %ecx, %ebp
cmpl %r15d, %ebp
movl %r15d, %r9d
cmovll %ebp, %r9d
cmpl 0x4(%rsp), %r10d
jg 0x1ab7bc
cmpl 0x4(%rsp), %r9d
jg 0x1ab7bc
movl %ecx, %esi
subl %r14d, %esi
xorps %xmm1, %xmm1
cvtsi2ss %rsi, %xmm1
addl %r10d, %esi
addl %r9d, %esi
xorps %xmm2, %xmm2
cvtsi2ss %rsi, %xmm2
mulss %xmm3, %xmm2
ucomiss %xmm1, %xmm2
ja 0x1ab7bc
subl %eax, %r11d
xorps %xmm1, %xmm1
cvtsi2ss %r11, %xmm1
addl %r10d, %r9d
addl %r11d, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9, %xmm2
mulss %xmm3, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1ab7ce
addq $0x28, %rdx
cmpq %rdx, %r13
jne 0x1ab6f3
jmp 0x1ab8d2
cmpl %r15d, %ebp
setl %al
setg %r11b
cmpl %ebx, %r14d
setg %bpl
setl %r10b
orb %r11b, %bpl
cmpb $0x1, %bpl
jne 0x1ab7bc
orb %al, %r10b
je 0x1ab7bc
cmpl (%rsp), %esi
jl 0x1ab7bc
cmpl (%rsp), %r9d
jl 0x1ab7bc
addl %ecx, %r15d
movl %r12d, %ecx
subl %r15d, %ecx
movl %r14d, %eax
subl %ebx, %eax
cmovlel %ecx, %eax
testl %eax, %eax
js 0x1ab7bc
xorl %r9d, %r9d
cmpl %ebx, %r14d
setle %r9b
setg %cl
cmpl $0x0, 0x18(%rsp)
setns %sil
shrq $0x1f, %r14
andl $-0x2, %r14d
orl %r14d, %r9d
cmpl 0x30(%rsp), %r9d
jne 0x1ab7bc
xorb %cl, %sil
movzbl %sil, %ecx
orl 0x10(%rsp), %ecx
cmpl 0x14(%rsp), %ecx
jne 0x1ab7bc
subl %eax, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq 0x78(%rsp), %r15
testq %r15, %r15
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rax
jne 0x1ab936
jmp 0x1ab93e
movq (%rdi), %rdi
movq 0x18(%rdi), %rcx
movq 0x28(%rcx), %rax
movl %edx, %edx
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x1ab8d2
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %r8d
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r11
addq $0x10, %r11
shlq $0x3, %r8
leaq (%r8,%r8,2), %r9
xorl %eax, %eax
xorl %r8d, %r8d
movl -0x4(%r11,%r8), %r12d
testl %r12d, %r12d
js 0x1ab8c7
cmpl %r10d, -0x8(%r11,%r8)
je 0x1ab8e3
addq $0x18, %r8
cmpq %r8, %r9
jne 0x1ab8b6
jmp 0x1ab8d4
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r15, %r15
je 0x1ab93e
leaq (%rcx,%rdx,8), %rcx
movzwl 0x10(%r8,%rcx), %edx
andl $0x3fff, %edx           # imm = 0x3FFF
movq %rdx, (%r15)
movl 0x10(%r8,%rcx), %ecx
notl %ecx
testl $0x3fff, %ecx           # imm = 0x3FFF
jne 0x1ab93e
movq 0x8(%rsi), %r9
movslq 0x40(%rsi), %rdx
movslq 0x44(%rsi), %rcx
movl -0xc(%r11,%r8), %r8d
movq %r9, %rsi
movl %r10d, %r9d
movsd %xmm0, 0x8(%rsp)
callq 0x1ab42b
movsd 0x8(%rsp), %xmm0
movq 0x18(%rax), %rax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, (%r15)
movl %r12d, %eax
movq %rax, %rcx
subq %r14, %rcx
cmovgq %rax, %r14
movq %rcx, %rdx
negq %rdx
cmovsq %rcx, %rdx
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
cmpq %rbx, %rcx
cmovgq %rcx, %rbx
xorl %eax, %eax
cmpq %rbx, %rdx
setle %al
jmp 0x1ab8d4