// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: iter_cc_idx_t(overlap_region*, cc_idx_t*, long, long, unsigned long, unsigned long, unsigned long**)
uint64_t iter_cc_idx_t(overlap_region* ol, cc_idx_t *z, int64_t s, int64_t e, uint64_t is_reduce, uint64_t is_insert, uint64_t **ra)
{
    int64_t rm_n, q[2], os, oe; ul_ov_t *cp; uint64_t m; *ra = NULL;

    // if(s == 15816 && e == 15819) {
    //     fprintf(stderr, "[M::%s] is_reduce::%lu\n", __func__, is_reduce);
    // }
    if(z->ru == 0) {
        if(is_reduce) {
            for (m = rm_n = z->srt_n; m < z->idx->n; m++) {
                cp = &(z->c_idx[z->idx->a[m]]);
                // if(s == 15816 && e == 15819) {
                //     fprintf(stderr, "-0-[M::%s] ii::%lu, ii0::%ld\n", __func__, z->idx->a[m], z->i0);
                // }
                
                q[0] = ol[ovlp_id(*cp)].w_list.a[ovlp_cur_wid(*cp)].x_start+ovlp_bd(*cp);
                q[1] = ol[ovlp_id(*cp)].w_list.a[ovlp_cur_wid(*cp)].x_end+1-ovlp_bd(*cp);
                os = MAX(q[0], s); oe = MIN(q[1], e);
                if((oe > os) || ((is_insert) && (s == e) && (s >= q[0]) && (s <= q[1]))) {
                    z->idx->a[rm_n++] = z->idx->a[m];
                }
            }
            z->idx->n = rm_n;
        }

        for (; z->i < z->srt_n; ++z->i) {
            cp = &(z->c_idx[(uint32_t)z->idx->a[z->i]]);
            // if(s == 15816 && e == 15819) {
            //     fprintf(stderr, "-1-[M::%s] ii::%u, ii0::%ld\n", __func__, (uint32_t)z->idx->a[z->i], z->i0);
            // }
            q[0] = ol[ovlp_id(*cp)].w_list.a[ovlp_cur_wid(*cp)].x_start+ovlp_bd(*cp);
            q[1] = ol[ovlp_id(*cp)].w_list.a[ovlp_cur_wid(*cp)].x_end+1-ovlp_bd(*cp);
            if(q[0] > e) break;
            if((!is_insert) && (q[0] >= e)) break;
            os = MAX(q[0], s); oe = MIN(q[1], e);
            if((oe > os) || ((is_insert) && (s == e) && (s >= q[0]) && (s <= q[1]))) {
                kv_push(uint64_t, *(z->idx), ((uint32_t)z->idx->a[z->i]));
            }
        }
    } else {
        z->ru = 0;
    }

    (*ra) = z->idx->a + z->srt_n; 
    return z->idx->n - z->srt_n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x50(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, %rbx
cmpq $0x0, 0x30(%rsi)
je 0x13eae5
andq $0x0, 0x30(%rbx)
movq 0x20(%rbx), %rdi
movq 0x8(%rbx), %rax
leaq (,%rdi,8), %rcx
addq 0x10(%rax), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rbx), %rax
movq (%rax), %rax
subq %rdi, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %r13
movq %r9, 0x10(%rsp)
testq %r8, %r8
je 0x13eba9
movq 0x8(%rbx), %rax
movq 0x20(%rbx), %rcx
cmpq $0x0, 0x10(%rsp)
sete %sil
cmpq %r15, %r12
setne %dl
orb %sil, %dl
movq %rcx, %rsi
cmpq (%rax), %rsi
jae 0x13eba6
movq (%rbx), %r10
movq 0x10(%rax), %rdi
movq (%rdi,%rsi,8), %r8
imulq $0x1c, %r8, %r11
movl (%r10,%r11), %r14d
movl 0xc(%r10,%r11), %r9d
imulq $0xa8, %r9, %r9
movq 0x58(%r13,%r9), %rbp
shlq $0x5, %r14
movslq (%rbp,%r14), %r9
movl 0x18(%r10,%r11), %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
addq %r10, %r9
movl 0x4(%rbp,%r14), %r11d
subl %r10d, %r11d
incl %r11d
movslq %r11d, %r10
cmpq %r12, %r9
movq %r12, %r11
cmovgq %r9, %r11
cmpq %r15, %r10
movq %r15, %r14
cmovlq %r10, %r14
cmpq %r11, %r14
jg 0x13eb97
cmpq %r12, %r9
setg %r9b
orb %dl, %r9b
jne 0x13eb9e
cmpq %r12, %r10
jl 0x13eb9e
movq %r8, (%rdi,%rcx,8)
incq %rcx
incq %rsi
jmp 0x13eb1a
movq %rcx, (%rax)
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
sete %al
cmpq %r15, %r12
setne %dl
orb %al, %dl
movb %dl, 0xf(%rsp)
movq 0x10(%rbx), %rdx
movq 0x20(%rbx), %rdi
cmpq %rdi, %rdx
jge 0x13eab4
testq %rcx, %rcx
setne %r9b
movq (%rbx), %r14
movq 0x8(%rbx), %rcx
movq 0x10(%rcx), %rax
movl (%rax,%rdx,8), %esi
imulq $0x1c, %rsi, %rbp
movl (%r14,%rbp), %r10d
movl 0xc(%r14,%rbp), %r8d
imulq $0xa8, %r8, %r8
movq 0x58(%r13,%r8), %r11
shlq $0x5, %r10
movslq (%r11,%r10), %r8
movl 0x18(%r14,%rbp), %ebp
andl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
addq %rbp, %r8
cmpq %r15, %r8
setl %r14b
jg 0x13eab4
orb %r14b, %r9b
je 0x13eab4
movl 0x4(%r11,%r10), %edi
subl %ebp, %edi
incl %edi
movslq %edi, %rdi
cmpq %r12, %r8
movq %r12, %r9
cmovgq %r8, %r9
cmpq %r15, %rdi
movq %r15, %r10
cmovlq %rdi, %r10
cmpq %r9, %r10
jg 0x13ec63
cmpq %r12, %r8
setg %r8b
orb 0xf(%rsp), %r8b
jne 0x13ecab
cmpq %r12, %rdi
jl 0x13ecab
movq (%rcx), %rdx
cmpq 0x8(%rcx), %rdx
jne 0x13ec9c
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rsi
movq %rsi, 0x8(%rcx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%rbx), %rdx
movl (%rax,%rdx,8), %esi
movq (%rcx), %rdx
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx)
movq %rsi, (%rax,%rdx,8)
movq 0x10(%rbx), %rdx
incq %rdx
movq %rdx, 0x10(%rbx)
movq 0x10(%rsp), %rcx
jmp 0x13ebc4