// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: cns_gen_full0(overlap_region*, All_reads*, unsigned long, unsigned long, unsigned long, char*, UC_Read*, bit_extz_t*, cc_idx_t*, unsigned long, double, asg32_v*, cns_gfa*, unsigned long, window_list*, window_list_alloc*, unsigned int)
uint64_t cns_gen_full0(overlap_region* ol, All_reads *rref, uint64_t s, uint64_t e, uint64_t s_end, char* qstr, UC_Read* tu, bit_extz_t *exz, cc_idx_t *idx, uint64_t occ_tot, double occ_max, asg32_v* b32, cns_gfa *cns, uint64_t max_trace, window_list *ridx, window_list_alloc *res, uint32_t rid)
{
    init_cns_g(cns, qstr + s, e - s, rid);
    // if(e -s > 100) {
        // fprintf(stderr, "[M::%s]::[%lu, %lu), cns->n::%u, qstr::%.*s\n", __func__, s, e, (uint32_t)cns->n, (int)(e-s), qstr+s);
    // }
    // fprintf(stderr, "[M::%s]::[%lu, %lu)\n", __func__, s, e);
    
    uint64_t *id_a = NULL, id_n, nec = 0; b32->n = 0; 
    rr_seq_t ssq; ssq.rref = rref; ssq.tu = tu; ssq.s = ssq.e = 0; ssq.n0 = ssq.n1 = 32; ssq.id = ssq.rev = 0;
    id_n = iter_cc_idx_t(ol, idx, s, e, idx->rr, ((s==e)?1:0), &id_a);
    // debug_inter0(ol, idx->c_idx, idx->idx->a + idx->i0, idx->srt_n - idx->i0, id_a, id_n, s, e, ((s==e)?1:0), 0, "-1-");
    uint64_t k, q[2], os, oe; ul_ov_t *p; overlap_region *z; idx->rr = 0;
    // fprintf(stderr, "[M::%s] [%lu, %lu) id_n::%lu\n", __func__, s, e, id_n);
    for (k = 0; k < id_n; k++) {
        p = &(idx->c_idx[id_a[k]]); z = &(ol[ovlp_id(*p)]); 
        q[0] = z->w_list.a[ovlp_cur_wid(*p)].x_start+ovlp_bd(*p);
        q[1] = z->w_list.a[ovlp_cur_wid(*p)].x_end+1-ovlp_bd(*p);

        // fprintf(stderr, "[M::%s] tid::%u\t%.*s\twid::%u\tq::[%u, %u)\terr::%d\toerr::%u\n", __func__, ol[ovlp_id(*p)].y_id, (int)Get_NAME_LENGTH(R_INF, ol[ovlp_id(*p)].y_id), Get_NAME(R_INF, ol[ovlp_id(*p)].y_id),
        // ovlp_cur_wid(*p), ol[ovlp_id(*p)].w_list.a[ovlp_cur_wid(*p)].x_start, ol[ovlp_id(*p)].w_list.a[ovlp_cur_wid(*p)].x_end+1, ol[ovlp_id(*p)].w_list.a[ovlp_cur_wid(*p)].error, ol[ovlp_id(*p)].non_homopolymer_errors);

        if(q[1] <= e) idx->rr = 1;
        os = MAX(q[0], s); oe = MIN(q[1], e);
        // if((oe > os) || ((s == e) && (s >= q[0]) && (s <= q[1]))) {
        if((oe > os) || ((s == e) && (s > q[0]) && (s < q[1]))) {
        // if(oe >= os) {
            ///[-4-][-12-][-4-][-12-]
            ///[cigar_len][cigar][base_len][base]
            extract_sub_cigar_cns(z, os, oe, s, e, s_end, &ssq, p, cns, b32, max_trace, rid); 
            // if(m != ((uint32_t)-1)) {///no gap in both sides
            //     kv_push(uint32_t, *b32, m);
            // }
        }
    }

    // fprintf(stderr, "-2-[M::%s] cns->n::%u\n", __func__, (uint32_t)cns->n);

    // return;

    refine_cns_g(cns, b32);

    // fprintf(stderr, "-3-[M::%s] cns->n::%u\n", __func__, (uint32_t)cns->n);

    gseq_cns_g(cns, b32, e - s);

    // fprintf(stderr, "-4-[M::%s] cns->n::%u\n", __func__, (uint32_t)cns->n);

    // nec += push_correct1(ridx, res, cns, b32, e - s);
    nec += push_correct1_fhc(ridx, res, cns, qstr + s, tu, exz, b32, e - s, rid);

    // fprintf(stderr, "-5-[M::%s] cns->n::%u\n", __func__, (uint32_t)cns->n);
    return nec;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, (%rsp)
movq %rdi, %r15
movq 0xc0(%rsp), %rbp
movq 0xc8(%rsp), %rdi
movl 0xe8(%rsp), %ecx
addq %rdx, %r9
xorl %r13d, %r13d
movq %r12, %rdx
subq %rbx, %rdx
sete %r13b
movq %r9, 0x10(%rsp)
movq %r9, %rsi
movq %rdx, 0x8(%rsp)
callq 0x13dc0d
leaq 0x20(%rsp), %r14
andq $0x0, (%r14)
andq $0x0, (%rbp)
leaq 0x28(%rsp), %rcx
movq (%rsp), %rax
movq %rax, (%rcx)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
pushq $0x20
popq %rax
movq %rax, 0x28(%rcx)
movq %rax, 0x20(%rcx)
movups %xmm0, 0x30(%rcx)
movq 0xb0(%rsp), %rsi
movq 0x28(%rsi), %r8
subq $0x8, %rsp
movq %r15, %rdi
movq %rsi, %rbp
movq %rbx, %rdx
movq %r12, %rcx
movq %r13, %r9
pushq %r14
callq 0x13ea8a
movq %rbp, %r10
addq $0x10, %rsp
andq $0x0, 0x28(%rbp)
movq %rax, %r13
xorl %ebp, %ebp
movq (%r14), %rax
movq %rax, (%rsp)
cmpq %rbp, %r13
je 0x141138
movq (%r10), %rax
movq (%rsp), %rcx
imulq $0x1c, (%rcx,%rbp,8), %rcx
movl (%rax,%rcx), %esi
movl 0xc(%rax,%rcx), %edx
imulq $0xa8, %rdx, %rdi
movq 0x58(%r15,%rdi), %r9
shlq $0x5, %rsi
movslq (%r9,%rsi), %rdx
movl 0x18(%rax,%rcx), %r8d
andl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
movl 0x4(%r9,%rsi), %esi
subl %r8d, %esi
incl %esi
movslq %esi, %r9
cmpq %r12, %r9
ja 0x1410bd
movq $0x1, 0x28(%r10)
addq %rdx, %r8
movq %r8, %rsi
cmpq %rbx, %r8
ja 0x1410cb
movq %rbx, %rsi
movq %r9, %rdx
cmpq %r12, %r9
jb 0x1410d6
movq %r12, %rdx
cmpq %rsi, %rdx
ja 0x1410ea
cmpq %rbx, %r12
jne 0x141130
cmpq %rbx, %r8
jae 0x141130
cmpq %rbx, %r9
jbe 0x141130
addq %rcx, %rax
addq %r15, %rdi
movq %rbx, %rcx
movq %r12, %r8
movq 0x18(%rsp), %r9
movl 0xe8(%rsp), %r11d
pushq %r11
pushq 0xd8(%rsp)
pushq 0xd0(%rsp)
pushq 0xe0(%rsp)
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
movq %r10, %r14
callq 0x13e4cb
movq %r14, %r10
addq $0x30, %rsp
incq %rbp
jmp 0x141067
movq 0xc8(%rsp), %r14
movq %r14, %rdi
movq 0xc0(%rsp), %rbx
movq %rbx, %rsi
callq 0x13f99c
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %r15
movl %r15d, %edx
callq 0x13fcb7
subq $0x10, %rsp
movq 0xe8(%rsp), %rdi
movq 0xf0(%rsp), %rsi
movq %r14, %rdx
movq 0x20(%rsp), %rcx
movq 0xb0(%rsp), %r8
movq 0xb8(%rsp), %r9
pushq %r15
pushq %rbx
callq 0x140bec
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq