// File: /workspace/github_cpp_makefile_star2_O2/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
movsd %xmm0, 0x40(%rsp)
movq %rdx, %r14
movq %rsi, 0x38(%rsp)
movl 0x10(%rdx), %eax
movl 0x1c(%rdx), %ecx
movl %ecx, 0x8(%rsp)
movq 0x8(%rbx), %r9
movq (%rdi), %rcx
movq 0x10(%rcx), %rdx
imulq $0x28, %rax, %rax
leaq (%rdx,%rax), %r12
movq 0x48(%r14), %rcx
movl (%rdx,%rax), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorl %eax, %eax
testq %rcx, %rcx
movl $0x0, %edx
cmovgq %rcx, %rdx
incq %rdx
pushq $0x1c
popq %r8
decq %rdx
je 0x4993b
movq %r8, %rdi
movq 0x58(%r14), %rsi
cmpw $0x7fff, -0x8(%rsi,%r8) # imm = 0x7FFF
jne 0x497ab
cmpl $0x0, (%rsi,%rdi)
jne 0x497ab
leaq 0x20(%rdi), %r8
cmpw $0x0, -0xa(%rsi,%rdi)
js 0x4977f
movslq -0x1c(%rsi,%rdi), %r8
movq %r10, %rdi
subq %r8, %rdi
leaq 0x1(%rcx), %rdx
shlq $0x5, %rcx
addq %rcx, %rsi
addq $-0x4, %rsi
xorl %eax, %eax
decq %rdx
testq %rdx, %rdx
jle 0x4993b
movq %rsi, %rcx
cmpw $0x7fff, -0x8(%rsi)     # imm = 0x7FFF
jne 0x497ee
cmpl $0x0, (%rcx)
jne 0x497ee
leaq -0x20(%rcx), %rsi
cmpw $0x0, -0xa(%rcx)
js 0x497c7
movslq -0x18(%rcx), %rax
cmpl $0x0, 0x8(%rsp)
je 0x49803
notl %eax
movslq %eax, %r8
addq %r10, %r8
jmp 0x49809
incq %rax
movq %rax, %rdi
cmpq %rdi, %r8
jae 0x4992e
movq %rdi, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movq %r9, 0x20(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r8, 0x18(%rsp)
movl 0x10(%r12), %eax
cmpq %rax, %r13
jae 0x49932
movq 0x18(%r12), %rax
movq (%rax,%r13,8), %rbp
movq %rbp, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rsp)
leaq 0x20a9db(%rip), %rax    # 0x254230
movq 0x18(%rax), %rax
movq %rbp, %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
addq %r15, %rax
cmpq %r8, %rax
jbe 0x49921
cmpq 0x30(%rsp), %r15
jae 0x49932
cmpl $0x0, 0x8(%rsp)
je 0x49896
movq 0x28(%rsp), %rdx
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%rsp)
movl %edx, %eax
subl %r15d, %eax
jmp 0x4989b
movl %r15d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq 0x38(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r14, %rdx
movsd 0x40(%rsp), %xmm0
leaq 0x4c(%rsp), %rcx
callq 0x49571
testq %rax, %rax
movq 0x18(%rsp), %r8
je 0x49921
andb $-0x41, 0x67(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x49902
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %r8
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movups 0x4c(%rsp), %xmm0
movups 0x58(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl %ebp, %eax
addq %rax, %r15
incq %r13
jmp 0x4982c
xorl %eax, %eax
jmp 0x4993b
movq 0x8(%rbx), %rax
subq 0x20(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq