// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_sub_ov_cigar(ul_idx_t const*, unsigned long, overlap_region*, double, kv_ul_ov_t*)
uint64_t gen_sub_ov_cigar(const ul_idx_t *udb, uint64_t ql, overlap_region* o, double o_rate, kv_ul_ov_t *res)
{
	uint64_t ts, te, i, l, tl, id = o->y_id, rn = res->n, s, e, rev = o->y_pos_strand; utg_ct_t p; 
    ma_utg_t *u = &(udb->ug->u.a[id]); ul_ov_t rr; int64_t wn, k;

    wn = o->w_list.n; tl = u->len;
    for (k = 0; (k < wn) && (is_ualn_win(o->w_list.a[k])); k++);
    if(k >= wn) return 0;
    if(!rev) {
        ts = o->w_list.a[k].x_start;
    } else {
        te = tl-o->w_list.a[k].x_start;
    }
    for (k = wn-1; (k >= 0) && (is_ualn_win(o->w_list.a[k])); k--);
    if(k < 0) return 0;
    if(!rev) {
        te = o->w_list.a[k].x_end+1;
    } else {
        ts = tl-o->w_list.a[k].x_end-1;
    }
    if(ts >= te) return 0;///[ts, te)
    

    for (i = l = 0; i < u->n; i++) {
        p.x = u->a[i]>>32; s = l; e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
        l += (uint32_t)u->a[i];
        if(e <= ts) continue; if(s >= te) break;
        if(!rev) {
            p.s = s; p.e = e;
        }
        else {
            p.s = tl - e; p.e = tl - s;
        }

        if(get_win_off(ql, &p, o, o_rate, &rr)) {
            rr.el = 0; kv_push(ul_ov_t, *res, rr);
        }
    }
    return res->n-rn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq 0x48(%rdx), %rcx
testq %rcx, %rcx
setg %dl
jle 0x7cfa2
movl 0x10(%r14), %eax
movl 0x1c(%r14), %ebp
movq 0x8(%rbx), %r15
movq (%rdi), %rdi
movq 0x10(%rdi), %r11
leaq (%rax,%rax,4), %rdi
movl (%r11,%rdi,8), %r12d
movq 0x58(%r14), %r10
cmpw $0x7fff, 0x14(%r10)     # imm = 0x7FFF
jne 0x7cdaa
addq $0x12, %r10
movl $0x1, %r9d
xorl %eax, %eax
xorl %r8d, %r8d
cmpl $0x0, 0xa(%r10)
jne 0x7cda2
cmpw $0x0, (%r10)
jns 0x7cdad
cmpq %r9, %rcx
je 0x7cfa4
setg %dl
incq %r9
incq %r8
cmpw $0x7fff, 0x22(%r10)     # imm = 0x7FFF
leaq 0x20(%r10), %r10
je 0x7cd75
decq %r9
movq %r9, %r8
jmp 0x7cdad
xorl %r8d, %r8d
testb $0x1, %dl
je 0x7cfa2
leaq (%r11,%rdi,8), %r13
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq 0x58(%r14), %rax
shlq $0x5, %r8
movslq (%rax,%r8), %r9
movq %r12, %r8
subq %r9, %r8
movq %rcx, %rdx
shlq $0x5, %rdx
addq $-0xe, %rdx
testq %rcx, %rcx
jle 0x7ce0a
movq %rcx, %rax
decq %rcx
movq 0x58(%r14), %rdi
cmpw $0x7fff, 0x2(%rdi,%rdx) # imm = 0x7FFF
jne 0x7ce13
cmpl $0x0, 0xa(%rdi,%rdx)
jne 0x7ce13
cmpw $0x0, (%rdi,%rdx)
leaq -0x20(%rdx), %rdx
js 0x7cdde
jmp 0x7ce13
movq $-0x1, %rcx
xorl %eax, %eax
testq %rax, %rax
jle 0x7cfa2
shlq $0x5, %rcx
movq 0x58(%r14), %rax
movslq 0x4(%rax,%rcx), %rax
testl %ebp, %ebp
movq %r15, 0x30(%rsp)
je 0x7ce3c
notl %eax
movslq %eax, %r9
addq %r12, %r9
jmp 0x7ce42
incq %rax
movq %rax, %r8
cmpq %r8, %r9
jae 0x7cfa2
movq %r12, 0x38(%rsp)
movl %ebp, 0x8(%rsp)
movq %rsi, 0x40(%rsp)
cmpl $0x0, 0x10(%r13)
je 0x7cf97
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movsd %xmm0, 0x28(%rsp)
movq 0x18(%r13), %rax
movq (%rax,%rbp,8), %r15
movq %r15, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rsp)
leaq 0x20e39d(%rip), %rax    # 0x28b230
movq 0x18(%rax), %rax
movq %r15, %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
addq %r12, %rax
cmpq %r9, %rax
jbe 0x7cf81
cmpq %r8, %r12
jae 0x7cf97
cmpl $0x0, 0x8(%rsp)
je 0x7ced6
movq 0x38(%rsp), %rdx
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
movl %edx, %eax
subl %r12d, %eax
movl %eax, 0x14(%rsp)
jmp 0x7cedf
movl %r12d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq 0x40(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r14, %rdx
leaq 0x4c(%rsp), %rcx
callq 0x7cb63
movsd 0x28(%rsp), %xmm0
testq %rax, %rax
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
je 0x7cf81
andb $-0x41, 0x67(%rsp)
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7cf54
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movsd 0x28(%rsp), %xmm0
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x4c(%rsp), %xmm2
movups 0x58(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm2, (%rax,%rdx)
movl %r15d, %eax
addq %rax, %r12
incq %rbp
movl 0x10(%r13), %eax
cmpq %rax, %rbp
jb 0x7ce79
movq 0x8(%rbx), %rax
subq 0x30(%rsp), %rax
jmp 0x7cfa4
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq