// File: chhylp123[P]hifiasm/inter.cpp
// Function: max_ovlp_src_contain(ug_opt_t const*, unsigned int)
int64_t max_ovlp_src_contain(const ug_opt_t *uopt, uint32_t v)
{
	ma_hit_t_alloc* src = uopt->sources;
    int64_t min_ovlp = uopt->min_ovlp, max_hang = uopt->max_hang;
	uint32_t i, qn, tn, o = 0, x = v>>1, dt; asg_arc_t e; int32_t r = 1;

	for (i = 0; i < src[x].length; i++) {
        qn = Get_qn(src[x].buffer[i]); tn = Get_tn(src[x].buffer[i]);
		r = ma_hit2arc(&(src[x].buffer[i]), Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), 
														max_hang, asm_opt.max_hang_rate, min_ovlp, &e);
		// if(qn == 20171 && tn == 20172) {
		// 	fprintf(stderr, "[r::%d]\t%.*s\t%c\tq::[%u, %u)\t%.*s\tt::[%u, %u)\n", r,
        //             (int)Get_NAME_LENGTH(R_INF, qn), Get_NAME(R_INF, qn), "+-"[src[x].buffer[i].rev], 
		// 			Get_qs(src[x].buffer[i]), Get_qe(src[x].buffer[i]), 
		// 			(int)Get_NAME_LENGTH(R_INF, tn), Get_NAME(R_INF, tn),
		// 			Get_ts(src[x].buffer[i]), Get_te(src[x].buffer[i]));
		// }
		if(r >= 0) {
			if((e.ul>>32) != v) continue;
			if(o < e.ol) o = e.ol;
		} else if(r == MA_HT_TCONT) {///tn is contained in qn
			if(v&1) dt = Get_qe(src[x].buffer[i]);
			else dt = Get_READ_LENGTH(R_INF, qn) - Get_qs(src[x].buffer[i]);
			if(o < dt) o = dt;
		}
    }

	return o;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl -0xc(%rbp), %eax
shrl %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x5c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x3c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jae 0x2b2a31
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq 0x1129ae(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x11299a(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movl %eax, %ecx
leaq 0x111ea8(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x20(%rbp), %rax
movl %eax, %r8d
leaq -0x58(%rbp), %r9
callq 0x287f40
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x2b29a3
movq -0x58(%rbp), %rax
shrq $0x20, %rax
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
je 0x2b2986
jmp 0x2b2a23
movl -0x38(%rbp), %eax
movl -0x4c(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x2b29a1
movl -0x4c(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x38(%rbp)
jmp 0x2b2a21
cmpl $-0x3, -0x5c(%rbp)
jne 0x2b2a1f
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b29d7
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x2b2a0f
leaq 0x1128f2(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movl -0x3c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movl -0x2c(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x2b2a1d
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x2b2a1f
jmp 0x2b2a21
jmp 0x2b2a23
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2b28a0
movl -0x38(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)