// File: /workspace/github_cpp_makefile_star2_O1/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
movl 0xe8(%rsp), %ecx
movq 0xc8(%rsp), %rdi
movq 0xa0(%rsp), %rbp
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 0x179d1f
xorl %r14d, %r14d
leaq 0x20(%rsp), %rax
movq %r14, (%rax)
movq 0xc0(%rsp), %rcx
movq %r14, (%rcx)
movq (%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq %rbp, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rsp)
movl $0x20, %ecx
movq %rcx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movups %xmm0, 0x58(%rsp)
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 %rax
callq 0x17b5ca
addq $0x10, %rsp
movq %r14, 0x28(%rbp)
testq %rax, %rax
je 0x17e112
movq %rax, %r13
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
xorl %r14d, %r14d
movq (%rbp), %rax
movq (%rsp), %rcx
movq (%rcx,%r14,8), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %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 0x17e099
movq $0x1, 0x28(%rbp)
addq %rdx, %r8
movq %r8, %rsi
cmpq %rbx, %r8
ja 0x17e0a7
movq %rbx, %rsi
movq %r9, %rdx
cmpq %r12, %r9
jb 0x17e0b2
movq %r12, %rdx
cmpq %rsi, %rdx
ja 0x17e0c6
cmpq %rbx, %r12
jne 0x17e106
cmpq %rbx, %r8
jae 0x17e106
cmpq %rbx, %r9
jbe 0x17e106
addq %rcx, %rax
addq %r15, %rdi
movq %rbx, %rcx
movq %r12, %r8
movq 0x18(%rsp), %r9
movl 0xe8(%rsp), %r10d
pushq %r10
pushq 0xd8(%rsp)
pushq 0xd0(%rsp)
pushq 0xe0(%rsp)
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x17af73
addq $0x30, %rsp
incq %r14
cmpq %r14, %r13
jne 0x17e041
movq 0xc8(%rsp), %r14
movq %r14, %rdi
movq 0xc0(%rsp), %rbx
movq %rbx, %rsi
callq 0x17c612
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %r15
movl %r15d, %edx
callq 0x17c978
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 0x17daed
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq