// File: 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
movq %rsp, %rbp
subq $0xc0, %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)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x1c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movl $0x1, -0x8c(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
imulq $0x18, -0x88(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x2b0f92
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x2b0d82
jmp 0x2b0f81
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x70(%rbp), %rax
addq %rax, %rdi
leaq 0x11452d(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x114518(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x68(%rbp), %rax
movl %eax, %ecx
leaq 0x113a25(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x60(%rbp), %rax
movl %eax, %r8d
leaq -0xa8(%rbp), %r9
callq 0x287f40
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
jl 0x2b0e48
movq -0xa8(%rbp), %rax
shrq $0x20, %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x2b0e1b
movl -0xa0(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x2b0e20
jmp 0x2b0f81
movl -0x9c(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x2b0e43
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
jmp 0x2b0f92
cmpl $-0x3, -0x8c(%rbp)
jne 0x2b0f7d
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movl -0x1c(%rbp), %ecx
xorl -0x20(%rbp), %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2b0f7b
movq -0x80(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x2b0f7b
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
imulq $0x18, -0x88(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x70(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
imulq $0x18, -0x88(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x70(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq -0x58(%rbp), %rdx
imulq $0x18, -0x88(%rbp), %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
imulq $0x28, -0x70(%rbp), %rsi
addq %rsi, %rdx
subl 0x10(%rdx), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jge 0x2b0f67
movq -0x58(%rbp), %rax
imulq $0x18, -0x88(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x70(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
imulq $0x18, -0x88(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x70(%rbp), %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x2b0f79
movq 0x10(%rbp), %rax
movq $0x1, (%rax)
jmp 0x2b0f92
jmp 0x2b0f7d
jmp 0x2b0f7f
jmp 0x2b0f81
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2b0d06
cmpq $0x0, -0x40(%rbp)
jge 0x2b0fa6
movq $0x0, -0x8(%rbp)
jmp 0x2b104e
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x2b0fc1
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x2b0fd0
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x2b0ff2
movq -0x38(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x2b0ffd
movq -0x40(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%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 0x2b1032
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jg 0x2b1046
movq $0x1, -0x8(%rbp)
jmp 0x2b104e
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)