// File: chhylp123[P]hifiasm/inter.cpp
// Function: query_ovlp_src(ug_opt_t const*, unsigned int, unsigned int, long, double, unsigned int*)
ma_hit_t* query_ovlp_src(const ug_opt_t *uopt, uint32_t v, uint32_t w, int64_t o, double diff_ec_ul, uint32_t *ol)
{
	ma_hit_t_alloc* src = uopt->sources;
    int64_t min_ovlp = uopt->min_ovlp;
    int64_t max_hang = uopt->max_hang, d, l, max_l;
    uint64_t z, qn, tn, x = v>>1; int32_t r = 1; asg_arc_t e;
	l = (o>=0?o:-o); //l *= diff_ec_ul;
	if(l <= 0) return NULL;
    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;
		// if(v == 56 && w == 25) fprintf(stderr, "+xxxx, o:%ld, e.ol:%u\n", o, e.ol);
		// if(v == 25 && w == 56) fprintf(stderr, "-xxxx, o:%ld, e.ol:%u\n", o, e.ol);
		d = (o>=e.ol?o-e.ol:e.ol-o);
		max_l = MAX(l, e.ol);
		if(d <= (max_l*diff_ec_ul)) {
			if(ol) (*ol) = e.ol;
			return &(src[x].buffer[z]);
		}
    }
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq 0x44(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movl $0x1, -0x84(%rbp)
cmpq $0x0, -0x20(%rbp)
jl 0x29004f
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x29005c
xorl %eax, %eax
subq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jg 0x29007b
movq $0x0, -0x8(%rbp)
jmp 0x290299
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
imulq $0x18, -0x80(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x290291
movq -0x38(%rbp), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x2900f6
jmp 0x290280
movq -0x38(%rbp), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x68(%rbp), %rax
addq %rax, %rdi
leaq 0x1351bc(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0x1351a7(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x48(%rbp), %rax
movl %eax, %ecx
leaq 0x1346b4(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x40(%rbp), %rax
movl %eax, %r8d
leaq -0xa0(%rbp), %r9
callq 0x287f40
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
jge 0x290173
jmp 0x290280
movq -0xa0(%rbp), %rax
shrq $0x20, %rax
movl -0x14(%rbp), %ecx
cmpq %rcx, %rax
jne 0x290191
movl -0x98(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x290196
jmp 0x290280
movq -0x20(%rbp), %rax
movl -0x94(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jl 0x2901cb
movq -0x20(%rbp), %rax
movl -0x94(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2901e3
movl -0x94(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movl -0x94(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jl 0x290212
movq -0x58(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x290226
movl -0x94(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x60(%rbp)
cvtsi2sdq -0x50(%rbp), %xmm1
cvtsi2sdq -0x60(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x29027e
cmpq $0x0, -0x30(%rbp)
je 0x290261
movl -0x94(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x290299
jmp 0x290280
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x290083
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)