// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, %rbx
movsd %xmm0, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x48(%rdx), %rcx
testq %rcx, %rcx
jle 0x7cac7
movl 0x10(%rdx), %eax
movl 0x1c(%rdx), %esi
movl %esi, 0x8(%rsp)
movq 0x8(%rbx), %r9
movq (%rdi), %rsi
movq 0x10(%rsi), %rsi
leaq (%rax,%rax,4), %rax
leaq (%rsi,%rax,8), %r10
movl (%r10), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq 0x58(%rdx), %r8
leaq 0x1c(%r8), %rsi
xorl %eax, %eax
movq %rcx, %rdi
cmpw $0x7fff, -0x8(%rsi)     # imm = 0x7FFF
jne 0x7c8f1
cmpl $0x0, (%rsi)
jne 0x7c8f1
cmpw $0x0, -0xa(%rsi)
jns 0x7c8f1
addq $0x20, %rsi
decq %rdi
jne 0x7c8cf
jmp 0x7cac9
movslq -0x1c(%rsi), %rax
movq %r11, %r15
movq %rax, %r14
subq %rax, %r15
leaq 0x1(%rcx), %rsi
shlq $0x5, %rcx
leaq (%rcx,%r8), %rdi
addq $-0x4, %rdi
xorl %eax, %eax
decq %rsi
testq %rsi, %rsi
jle 0x7cac9
movq %rdi, %rcx
cmpw $0x7fff, -0x8(%rdi)     # imm = 0x7FFF
jne 0x7c937
cmpl $0x0, (%rcx)
jne 0x7c937
leaq -0x20(%rcx), %rdi
cmpw $0x0, -0xa(%rcx)
js 0x7c910
movslq -0x18(%rcx), %rax
cmpl $0x0, 0x8(%rsp)
je 0x7c94c
notl %eax
movslq %eax, %rsi
addq %r11, %rsi
jmp 0x7c955
incq %rax
movq %rax, %r15
movq %r14, %rsi
cmpq %r15, %rsi
jae 0x7cac7
movl 0x10(%r10), %r14d
movq %r9, %rax
testl %r14d, %r14d
je 0x7cac2
movq %r15, 0x40(%rsp)
movq %r11, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq %rdx, 0x38(%rsp)
leaq 0x2198a7(%rip), %rax    # 0x296230
movq 0x18(%rax), %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r10, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%r10), %rax
movq (%rax,%r15,8), %r12
movq %r12, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rsp)
movq %r12, %rax
shrq $0x21, %rax
movq (%rbp,%rax,8), %rax
addq %r13, %rax
cmpq %rsi, %rax
jbe 0x7caa4
cmpq 0x40(%rsp), %r13
jae 0x7cab9
cmpl $0x0, 0x8(%rsp)
je 0x7c9ee
movq 0x30(%rsp), %rdx
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
movl %edx, %eax
subl %r13d, %eax
jmp 0x7c9f3
movl %r13d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq 0x48(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq 0x38(%rsp), %rdx
movsd 0x50(%rsp), %xmm0
leaq 0x5c(%rsp), %rcx
callq 0x7c6bb
testq %rax, %rax
movq 0x20(%rsp), %r10
movq 0x18(%rsp), %rsi
je 0x7caa4
andb $-0x41, 0x77(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x7ca6f
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r10
movq %rax, (%rbx)
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 0x5c(%rsp), %xmm0
movups 0x68(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
leaq 0x219794(%rip), %rax    # 0x296230
movq 0x18(%rax), %rbp
movl 0x10(%r10), %r14d
movl %r12d, %eax
addq %rax, %r13
incq %r15
movl %r14d, %eax
cmpq %rax, %r15
jb 0x7c99d
movq 0x8(%rbx), %rax
movq 0x28(%rsp), %r9
subq %r9, %rax
jmp 0x7cac9
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq