// File: chhylp123[P]hifiasm/Correct.cpp
// Function: gen_sub_ov(ul_idx_t const*, overlap_region*, kv_ul_ov_t*, unsigned long, unsigned long)
uint64_t gen_sub_ov(const ul_idx_t *udb, overlap_region* o, kv_ul_ov_t *res, uint64_t xs, uint64_t xe)
{
	uint64_t ts, te, i, l, rn = res->n, rev = o->y_pos_strand; ul_ov_t *z;
	utg_ct_t p; ma_utg_t *u = &(udb->ug->u.a[o->y_id]);
    if(!rev){
        ts = o->y_pos_s; te = o->y_pos_e + 1;
    } else {
        ts = u->len - (o->y_pos_e+1); te = u->len - o->y_pos_s;
    }

    for (i = l = 0; i < u->n; i++) {
        p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
        l += (uint32_t)u->a[i];
        if(p.e <= ts) continue; 
        if(p.s >= te) break;
        if(gen_contain_ov(udb, &p, o, res)) {
            z = &(res->a[res->n-1]);
            if(z->qs >= xe) break;
            if(z->qe <= xs) res->n--; 
        }
    }
    return res->n-rn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x8ae97
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0x8aecc
movq -0x78(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movq -0x78(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x78(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x8afe2
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rax
leaq 0x33a3b7(%rip), %rcx    # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x78(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x40(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x64(%rbp)
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x64(%rbp), %eax
cmpq -0x30(%rbp), %rax
ja 0x8af5d
jmp 0x8afd1
movl -0x68(%rbp), %eax
cmpq -0x38(%rbp), %rax
jb 0x8af68
jmp 0x8afe2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x6c(%rbp), %rsi
callq 0x8aa50
cmpq $0x0, %rax
je 0x8afcf
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
cmpq -0x28(%rbp), %rax
jb 0x8afb0
jmp 0x8afe2
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
cmpq -0x20(%rbp), %rax
ja 0x8afcd
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x8afcf
jmp 0x8afd1
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x8aedc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)