// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_conta_ov_cigar(ul_idx_t const*, unsigned long, overlap_region*, utg_ct_t*, unsigned long, double, kv_ul_ov_t*)
uint64_t gen_conta_ov_cigar(const ul_idx_t *udb, uint64_t ql, overlap_region* o, utg_ct_t *ct_a, uint64_t ct_n, double o_rate, kv_ul_ov_t *res)
{
	uint64_t ts, te, i, tl, id = o->y_id, rn = res->n, rev = o->y_pos_strand; utg_ct_t p, *z; 
    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 = 0; i < ct_n; i++) {
        z = &(ct_a[i]);
        if(z->e <= ts) continue; 
        if(z->s >= te) break;
        p = *z;
        if(!rev) {
            p.s = z->s; p.e = z->e;
        } else {
            p.s = tl - z->e; p.e = tl - z->s;
        }
        
        if(get_win_off(ql, &p, o, o_rate, &rr)) {
            rr.el = 1; 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 $0x58, %rsp
movsd %xmm0, 0x30(%rsp)
movq %rcx, %r15
movq %rsi, 0x28(%rsp)
movq 0x48(%rdx), %rcx
testq %rcx, %rcx
jle 0x7cccb
movq %r9, %rbx
movq %r8, %r14
movq %rdx, %r12
movl 0x10(%rdx), %eax
movl 0x1c(%rdx), %edx
movl %edx, 0x4(%rsp)
movq 0x8(%r9), %rdx
movq %rdx, 0x18(%rsp)
movq (%rdi), %rdx
movq 0x10(%rdx), %rdx
leaq (%rax,%rax,4), %rax
movl (%rdx,%rax,8), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x58(%r12), %rdx
leaq 0x1c(%rdx), %rsi
xorl %eax, %eax
movq %rcx, %rdi
cmpw $0x7fff, -0x8(%rsi)     # imm = 0x7FFF
jne 0x7cb63
cmpl $0x0, (%rsi)
jne 0x7cb63
cmpw $0x0, -0xa(%rsi)
jns 0x7cb63
addq $0x20, %rsi
decq %rdi
jne 0x7cb41
jmp 0x7cccd
movslq -0x1c(%rsi), %rbp
movq %r13, %rdi
subq %rbp, %rdi
leaq 0x1(%rcx), %rsi
shlq $0x5, %rcx
addq %rcx, %rdx
addq $-0x4, %rdx
xorl %eax, %eax
decq %rsi
testq %rsi, %rsi
jle 0x7cccd
movq %rdx, %rcx
cmpw $0x7fff, -0x8(%rdx)     # imm = 0x7FFF
jne 0x7cba5
cmpl $0x0, (%rcx)
jne 0x7cba5
leaq -0x20(%rcx), %rdx
cmpw $0x0, -0xa(%rcx)
js 0x7cb7e
movslq -0x18(%rcx), %rax
cmpl $0x0, 0x4(%rsp)
je 0x7cbba
notl %eax
movslq %eax, %rbp
addq %r13, %rbp
jmp 0x7cbc0
incq %rax
movq %rax, %rdi
cmpq %rdi, %rbp
jae 0x7cccb
movq 0x18(%rsp), %rax
testq %r14, %r14
je 0x7ccc4
addq $0x8, %r15
movq %rdi, 0x20(%rsp)
movl (%r15), %eax
cmpq %rax, %rbp
jae 0x7ccb3
movl -0x4(%r15), %ecx
cmpq %rcx, %rdi
jbe 0x7ccc0
movq -0x8(%r15), %rdx
movq %rdx, 0x8(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x7cc19
movl %r13d, %edx
subl %eax, %edx
movl %edx, 0xc(%rsp)
movl %r13d, %eax
subl %ecx, %eax
jmp 0x7cc1d
movl %ecx, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r12, %rdx
movsd 0x30(%rsp), %xmm0
leaq 0x3c(%rsp), %rcx
callq 0x7c6bb
testq %rax, %rax
movq 0x20(%rsp), %rdi
je 0x7ccb3
orb $0x40, 0x57(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x7cc8d
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 0x20(%rsp), %rdi
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 0x3c(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0xc, %r15
decq %r14
jne 0x7cbe0
movq 0x8(%rbx), %rax
subq 0x18(%rsp), %rax
jmp 0x7cccd
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq