// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: get_ecov_contain_adv(ul_idx_t const*, ug_opt_t const*, unsigned int, unsigned int, long, double, long, long*)
int64_t get_ecov_contain_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, int64_t *is_contain)
{
	int64_t dt = -1, dif, mm; 
	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((e.ul>>32) != v || e.v != w) continue;
			dt = e.ol; if(is_contain) (*is_contain) = 0;
			break;
		} else if(r == MA_HT_TCONT) {///tn is contained in qn
			// if(qn == 543 && tn == 548) {
			// 	fprintf(stderr, "[M::%s]\t%.*s\t->%.*s\tr::%d\tsrc::%c\tqry::%c\n", __func__, (int)Get_NAME_LENGTH(R_INF, qn), 
			// 		Get_NAME(R_INF, qn), (int)Get_NAME_LENGTH(R_INF, tn), Get_NAME(R_INF, tn), r,
			// 		"+-"[src[x].buffer[z].rev], "+-"[((uint32_t)(v^w))]);
			// }
			if((src[x].buffer[z].rev == (((uint32_t)(v^w))&1)) && (tn == (w>>1))) {
				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;
				// fprintf(stderr, "[M::%s]\t%.*s\t->%.*s\tdt::%ld\n", __func__, (int)Get_NAME_LENGTH(R_INF, qn), 
				// Get_NAME(R_INF, qn), (int)Get_NAME_LENGTH(R_INF, tn), Get_NAME(R_INF, tn), dt);
				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
movq %r9, (%rsp)
movsd %xmm0, 0x28(%rsp)
movq %r8, 0x8(%rsp)
movq 0x8(%rsi), %rax
movl 0x44(%rsi), %edi
movl %edi, 0x24(%rsp)
movl 0x40(%rsi), %esi
movl %esi, 0x20(%rsp)
movl %ecx, %esi
xorl %edx, %esi
movl %edx, %edi
movq %rdi, 0x30(%rsp)
shrl %edx
imulq $0x18, %rdx, %rdx
leaq (%rax,%rdx), %rbx
movl 0xc(%rax,%rdx), %eax
movl %ecx, 0x18(%rsp)
movl %ecx, %ebp
shrl %ebp
leaq 0xe18f9(%rip), %rcx     # 0x254230
movq 0x18(%rcx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0xe0e11(%rip), %rcx     # 0x253758
movss 0x158(%rcx), %xmm0
movss %xmm0, 0x1c(%rsp)
andl $0x1, %esi
movl %esi, 0x14(%rsp)
imulq $0x28, %rax, %r15
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x1729d8
movq (%rbx), %r12
cmpl %ebp, 0xc(%r12,%r13)
jne 0x1729d2
leaq (%r12,%r13), %rdi
movq (%rdi), %r14
movq %r14, %rax
shrq $0x20, %rax
movq 0x38(%rsp), %rcx
movl (%rcx,%rax,8), %esi
movl (%rcx,%rbp,8), %edx
movl 0x20(%rsp), %ecx
movss 0x1c(%rsp), %xmm0
movl 0x24(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x15d560
testl %eax, %eax
js 0x1729bf
movq 0x30(%rsp), %rax
cmpl %eax, 0x44(%rsp)
jne 0x1729d2
movl 0x18(%rsp), %eax
cmpl %eax, 0x48(%rsp)
jne 0x1729d2
jmp 0x1729df
cmpl $-0x3, %eax
jne 0x1729d2
movl 0x18(%r12,%r13), %eax
shrl $0x1f, %eax
cmpl 0x14(%rsp), %eax
je 0x1729f9
addq $0x28, %r13
jmp 0x172963
xorl %eax, %eax
jmp 0x172a6c
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x4c(%rsp), %eax
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x172a2e
xorl %ecx, %ecx
jmp 0x172a20
movl 0x8(%r12,%r13), %ecx
movl 0x14(%r12,%r13), %eax
subl %r14d, %ecx
subl 0x10(%r12,%r13), %eax
cmpl %eax, %ecx
cmoval %ecx, %eax
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x172a2e
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movq %rcx, (%rdi)
jmp 0x172a37
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movl %eax, %eax
movq %rax, %rcx
subq %rsi, %rcx
cmovgq %rax, %rsi
movq %rcx, %rdi
negq %rdi
cmovsq %rcx, %rdi
cvtsi2sd %rsi, %xmm0
mulsd 0x28(%rsp), %xmm0
cvttsd2si %xmm0, %rcx
cmpq %rdx, %rcx
cmovgq %rcx, %rdx
xorl %eax, %eax
cmpq %rdx, %rdi
setle %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq