// File: /workspace/github_cpp_makefile_star2_O2/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
movq %r9, %rbx
movsd %xmm0, 0x30(%rsp)
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x28(%rsp)
movl 0x10(%rdx), %eax
movl 0x1c(%rdx), %ecx
movl %ecx, 0x4(%rsp)
movq 0x8(%r9), %r9
movq (%rdi), %rcx
movq 0x10(%rcx), %rdx
imulq $0x28, %rax, %rax
movq 0x48(%r12), %rcx
movl (%rdx,%rax), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
testq %rcx, %rcx
movl $0x0, %edx
cmovgq %rcx, %rdx
incq %rdx
pushq $0x1c
popq %r8
decq %rdx
je 0x49b2d
movq %r8, %rdi
movq 0x58(%r12), %rsi
cmpw $0x7fff, -0x8(%rsi,%r8) # imm = 0x7FFF
jne 0x499da
cmpl $0x0, (%rsi,%rdi)
jne 0x499da
leaq 0x20(%rdi), %r8
cmpw $0x0, -0xa(%rsi,%rdi)
js 0x499ad
movq %r9, 0x18(%rsp)
movslq -0x1c(%rsi,%rdi), %rbp
movq %r13, %rax
subq %rbp, %rax
movq %rax, %rdi
leaq 0x1(%rcx), %rdx
shlq $0x5, %rcx
addq %rcx, %rsi
addq $-0x4, %rsi
xorl %eax, %eax
decq %rdx
testq %rdx, %rdx
jle 0x49b2d
movq %rsi, %rcx
cmpw $0x7fff, -0x8(%rsi)     # imm = 0x7FFF
jne 0x49a25
cmpl $0x0, (%rcx)
jne 0x49a25
leaq -0x20(%rcx), %rsi
cmpw $0x0, -0xa(%rcx)
js 0x499fe
movslq -0x18(%rcx), %rax
cmpl $0x0, 0x4(%rsp)
je 0x49a3a
notl %eax
movslq %eax, %rbp
addq %r13, %rbp
jmp 0x49a40
incq %rax
movq %rax, %rdi
cmpq %rdi, %rbp
jae 0x49b20
movq %rdi, 0x20(%rsp)
addq $0x8, %r15
subq $0x1, %r14
jb 0x49b24
movl (%r15), %eax
cmpq %rax, %rbp
jae 0x49b17
movl -0x4(%r15), %ecx
cmpq %rcx, 0x20(%rsp)
jbe 0x49b24
movq -0x8(%r15), %rdx
movq %rdx, 0x8(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x49a97
movl %r13d, %edx
subl %eax, %edx
movl %edx, 0xc(%rsp)
movl %r13d, %eax
subl %ecx, %eax
jmp 0x49a9b
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 0x49571
testq %rax, %rax
je 0x49b17
orb $0x40, 0x57(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x49af8
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 %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movups 0x3c(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq $0xc, %r15
jmp 0x49a52
xorl %eax, %eax
jmp 0x49b2d
movq 0x8(%rbx), %rax
subq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq