// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl 0x58(%rbp), %eax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movsd %xmm0, -0x50(%rbp)
movq 0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
subq -0x30(%rbp), %rdx
movl 0x58(%rbp), %ecx
callq 0x24c7d0
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
movq 0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x20, -0x80(%rbp)
movq $0x20, -0x88(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rdi
movq 0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x20(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x30(%rbp), %r10
movq -0x38(%rbp), %r11
xorl %eax, %eax
movl $0x1, %r9d
cmpq %r11, %r10
cmovel %r9d, %eax
movslq %eax, %r9
leaq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0x24e580
movq %rax, -0x60(%rbp)
movq 0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x25294a
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movq -0xb0(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq -0xd8(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0xd8(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0xd8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
addl %ecx, %eax
cltq
movq %rax, -0xc0(%rbp)
movq -0xe0(%rbp), %rax
movq 0x58(%rax), %rax
movq -0xd8(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0xd8(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
subl %ecx, %eax
cltq
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x252832
movq 0x20(%rbp), %rax
movq $0x1, 0x28(%rax)
movq -0xc0(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x25284f
movq -0xc0(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x25285a
movq -0x30(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xb8(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x252885
movq -0xb8(%rbp), %rax
movq %rax, -0xf0(%rbp)
jmp 0x252890
movq -0x38(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
ja 0x2528d2
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x252931
movq -0x30(%rbp), %rax
cmpq -0xc0(%rbp), %rax
jbe 0x252931
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x252931
movq -0xe0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0xd8(%rbp), %r14
movq 0x38(%rbp), %rbx
movq 0x30(%rbp), %r11
movq 0x40(%rbp), %r10
movl 0x58(%rbp), %eax
leaq -0xa8(%rbp), %r15
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl %eax, 0x28(%rsp)
callq 0x24d920
jmp 0x252933
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x252754
movq 0x38(%rbp), %rdi
movq 0x30(%rbp), %rsi
callq 0x250000
movq 0x38(%rbp), %rdi
movq 0x30(%rbp), %rsi
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl %eax, %edx
callq 0x2504b0
movq 0x48(%rbp), %rdi
movq 0x50(%rbp), %rsi
movq 0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
addq -0x30(%rbp), %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x30(%rbp), %r11
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl %eax, %r10d
movl 0x58(%rbp), %eax
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x252060
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)