// File: /workspace/github_cpp_makefile_star2_O3/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
movq 0x8(%rsi), %r10
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,2), %rdi
movl 0xc(%r10,%rdi,8), %eax
testq %rax, %rax
je 0x1bd102
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 (%r10,%rdi,8), %rsi
movq (%rsi), %r11
movl %ecx, %ebx
shrl %ebx
leaq 0xd92d1(%rip), %rsi     # 0x296230
movq 0x18(%rsi), %rsi
movq %rsi, -0x18(%rsp)
leaq 0xd87e9(%rip), %rsi     # 0x295758
movss 0x158(%rsi), %xmm1
movl %ecx, %esi
xorl %edx, %esi
andl $0x1, %esi
movl %esi, -0x44(%rsp)
movl %edx, %edx
movq %rdx, -0x10(%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 0x1bd091
movq 0x18(%r11,%r13), %rcx
movq -0x18(%rsp), %rax
movl (%rax,%rbx,8), %r10d
movq %rcx, -0x28(%rsp)
testl %ecx, %ecx
js 0x1bcfdb
movl 0x10(%r11,%r13), %esi
movl 0x14(%r11,%r13), %edi
subl %edi, %r10d
movl %r10d, %r15d
movl %esi, %r10d
jmp 0x1bcfeb
movl 0x10(%r11,%r13), %esi
movl 0x14(%r11,%r13), %edi
subl %edi, %r10d
movl %esi, %r15d
movq (%r11,%r13), %rdx
movq %rdx, %rax
shrq $0x20, %rax
movq -0x18(%rsp), %rcx
movl (%rcx,%rax,8), %r14d
cmpl %edx, %r10d
movl %edx, %r9d
cmovll %r10d, %r9d
movl 0x8(%r11,%r13), %eax
movl %r14d, %r8d
subl %eax, %r8d
cmpl %r15d, %r8d
movl %r15d, %ecx
cmovll %r8d, %ecx
cmpl -0x3c(%rsp), %r9d
jg 0x1bd091
cmpl -0x3c(%rsp), %ecx
jg 0x1bd091
movl %eax, %ebp
subl %edx, %ebp
xorps %xmm2, %xmm2
cvtsi2ss %rbp, %xmm2
leal (%r9,%rbp), %r12d
addl %ecx, %r12d
xorps %xmm3, %xmm3
cvtsi2ss %r12, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x1bd091
subl %esi, %edi
xorps %xmm2, %xmm2
cvtsi2ss %rdi, %xmm2
addl %r9d, %ecx
addl %edi, %ecx
xorps %xmm3, %xmm3
cvtsi2ss %rcx, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x1bd091
cmpl %r10d, %edx
jg 0x1bd079
cmpl %r15d, %r8d
jle 0x1bd091
cmpl %r10d, %edx
jl 0x1bd0a2
cmpl %r15d, %r8d
jl 0x1bd0a2
movq -0x28(%rsp), %rax
shrl $0x1f, %eax
cmpl -0x44(%rsp), %eax
je 0x1bd10f
addq $0x28, %r13
cmpq %r13, -0x8(%rsp)
jne 0x1bcfa4
jmp 0x1bd102
cmpl -0x40(%rsp), %r12d
jl 0x1bd091
cmpl -0x40(%rsp), %ecx
jl 0x1bd091
addl %eax, %r15d
movl %r14d, %ecx
subl %r15d, %ecx
movl %edx, %eax
subl %r10d, %eax
cmovlel %ecx, %eax
testl %eax, %eax
js 0x1bd0fb
xorl %edi, %edi
cmpl %r10d, %edx
setle %dil
setg %cl
cmpl $0x0, -0x28(%rsp)
setns %sil
shrq $0x1f, %rdx
andl $-0x2, %edx
orl %edx, %edi
cmpl -0x10(%rsp), %edi
jne 0x1bd091
xorb %cl, %sil
movzbl %sil, %ecx
orl -0x20(%rsp), %ecx
cmpl -0x1c(%rsp), %ecx
jne 0x1bd091
jmp 0x1bd12f
cmpl $-0x3, %eax
je 0x1bd083
jmp 0x1bd091
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %edi, %ebp
cmoval %ebp, %edi
movl $0x1, %eax
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
movq -0x30(%rsp), %rdx
movq -0x38(%rsp), %rsi
jne 0x1bd151
jmp 0x1bd154
subl %eax, %r14d
movl %r14d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x1bd18c
xorl %eax, %eax
movq -0x30(%rsp), %rdx
movq -0x38(%rsp), %rsi
movq %rax, (%rcx)
movl %edi, %eax
movq %rax, %rcx
subq %rsi, %rcx
cmovgq %rax, %rsi
movq %rcx, %rdi
negq %rdi
cmovsq %rcx, %rdi
cvtsi2sd %rsi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
cmpq %rdx, %rcx
cmovgq %rcx, %rdx
xorl %eax, %eax
cmpq %rdx, %rdi
setle %al
jmp 0x1bd104
movq -0x30(%rsp), %rdx
movq -0x38(%rsp), %rsi
jmp 0x1bd154