// File: /workspace/github_cpp_makefile_star2_O1/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 %rcx, %r15
movq %rdx, %r12
movq 0x48(%rdx), %rcx
testq %rcx, %rcx
setg %dl
jle 0x7d205
movq %r9, %rbx
movq %r8, %r14
movl 0x10(%r12), %eax
movl 0x1c(%r12), %r8d
movl %r8d, 0x4(%rsp)
movq 0x8(%r9), %r10
movq (%rdi), %rdi
movq 0x10(%rdi), %rdi
leaq (%rax,%rax,4), %rax
movl (%rdi,%rax,8), %ebp
movq 0x58(%r12), %r8
cmpw $0x7fff, 0x14(%r8)      # imm = 0x7FFF
jne 0x7d04f
addq $0x12, %r8
movl $0x1, %edi
xorl %eax, %eax
xorl %r9d, %r9d
cmpl $0x0, 0xa(%r8)
jne 0x7d047
cmpw $0x0, (%r8)
jns 0x7d052
cmpq %rdi, %rcx
je 0x7d207
setg %dl
incq %rdi
incq %r9
cmpw $0x7fff, 0x22(%r8)      # imm = 0x7FFF
leaq 0x20(%r8), %r8
je 0x7d01a
decq %rdi
movq %rdi, %r9
jmp 0x7d052
xorl %r9d, %r9d
testb $0x1, %dl
je 0x7d205
movq %r10, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq 0x58(%r12), %rax
shlq $0x5, %r9
movslq (%rax,%r9), %r13
movq %rbp, 0x18(%rsp)
subq %r13, %rbp
movq %rcx, %rdx
shlq $0x5, %rdx
addq $-0xe, %rdx
testq %rcx, %rcx
jle 0x7d0b8
movq %rcx, %rax
decq %rcx
movq 0x58(%r12), %rsi
cmpw $0x7fff, 0x2(%rsi,%rdx) # imm = 0x7FFF
jne 0x7d0c1
cmpl $0x0, 0xa(%rsi,%rdx)
jne 0x7d0c1
cmpw $0x0, (%rsi,%rdx)
leaq -0x20(%rdx), %rdx
js 0x7d08b
jmp 0x7d0c1
movq $-0x1, %rcx
xorl %eax, %eax
testq %rax, %rax
jle 0x7d205
shlq $0x5, %rcx
movq 0x58(%r12), %rax
movslq 0x4(%rax,%rcx), %rax
cmpl $0x0, 0x4(%rsp)
je 0x7d0eb
notl %eax
movslq %eax, %r13
addq 0x18(%rsp), %r13
jmp 0x7d0f1
incq %rax
movq %rax, %rbp
cmpq %rbp, %r13
jae 0x7d205
testq %r14, %r14
je 0x7d1fa
addq $0x8, %r15
movsd %xmm0, 0x20(%rsp)
movl (%r15), %eax
cmpq %rax, %r13
jae 0x7d1ed
movl -0x4(%r15), %ecx
cmpq %rcx, %rbp
jbe 0x7d1fa
leaq -0x8(%r15), %rdx
movl 0x8(%rdx), %esi
movl %esi, 0x10(%rsp)
movq (%rdx), %rdx
movq %rdx, 0x8(%rsp)
cmpl $0x0, 0x4(%rsp)
je 0x7d157
movq 0x18(%rsp), %rsi
movl %esi, %edx
subl %eax, %edx
movl %edx, 0xc(%rsp)
movl %esi, %eax
subl %ecx, %eax
movl %eax, 0x10(%rsp)
jmp 0x7d15f
movl %ecx, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r12, %rdx
leaq 0x3c(%rsp), %rcx
callq 0x7cb63
movsd 0x20(%rsp), %xmm0
testq %rax, %rax
je 0x7d1ed
orb $0x40, 0x57(%rsp)
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x7d1c0
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
movsd 0x20(%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 0x3c(%rsp), %xmm2
movups 0x48(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm2, (%rax,%rdx)
addq $0xc, %r15
decq %r14
jne 0x7d10d
movq 0x8(%rbx), %rax
subq 0x28(%rsp), %rax
jmp 0x7d207
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq