// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_cns_anchor(overlap_region*, All_reads*, unsigned long, unsigned long, char*, unsigned long, UC_Read*, bit_extz_t*, cc_idx_t*, overlap_region*, unsigned long, unsigned long, double, asg32_v*, cns_gfa*, unsigned int)
uint64_t push_cns_anchor(overlap_region* ol, All_reads *rref, uint64_t s, uint64_t e, char* qstr, uint64_t ql, UC_Read* tu, bit_extz_t *exz, cc_idx_t *idx, overlap_region *aux_o, uint64_t is_tail, uint64_t occ_tot, double occ_max, asg32_v* b32, cns_gfa *cns, uint32_t rid)
{
    if((!is_tail) && (s >= e)) return 0;//if s >= e && is_tail = 1, gen the cns of the last a few bases -> s == e == ql
    // fprintf(stderr, "\n****************[M::%s::M] [%lu, %lu)****************\n", __func__, s, e);
    window_list *p = NULL; uint64_t e0 = 0, nec = 0; uint32_t rc;
    if(aux_o->w_list.n > 0) {
        p = &(aux_o->w_list.a[aux_o->w_list.n-1]);
        e0 = p->x_end+1;
        ///make sure e > s
    }
    assert(s >= e0);
    if((s == e) && (is_tail == 1) && (s == e0)) return 0;///in this case, s == e == ql

    if(aux_o->w_list.n == 0) {
        kv_pushp(window_list, aux_o->w_list, &p);
        p->x_start = -1; p->x_end = -1;
        p->clen = p->cidx = 0;
    }

    if(((!is_tail) && (s > 0)) || ((is_tail) && (s > e0))) {
        // fprintf(stderr, ">>>>>>[M::%s::M] [%lu, %lu), ec::%u\n", __func__, e0, s, cal_cigar_xlen_fhc(aux_o));
        // fprintf(stderr, ">>>>>>[M::%s::M] [%lu, %lu)\n", __func__, e0, s);
        if (cns_gen0(ol, rref, e0, s, ql, tu, idx, occ_tot, occ_max, b32, &rc)) {
            if(p->x_start == -1 || p->x_end == -1) {///hasn't neem set
                p->x_start = e0; p->x_end = s-1;
            }
            // nec += push_correct0(p, &(aux_o->w_list), (uint32_t)-1, rc);
            nec += push_correct0_fhc(p, &(aux_o->w_list), (uint32_t)-1, rc, qstr + e0);
            // fprintf(stderr, "-0-[M::%s::M]\n", __func__);
        } else {
            nec += cns_gen_full(ol, rref, e0, s, cns->cns_g_wl, qstr, tu, exz, idx, occ_tot, occ_max, b32, cns, ql, p, &(aux_o->w_list), rid);
            // output_cns_g(cns, e0, s); exit(1);
            // fprintf(stderr, "-1-[M::%s::M]\n", __func__);
        }
        p->x_end = s-1;

        // if((uint32_t)p->x_end + 1 != cal_cigar_xlen_fhc(aux_o)) {
        //     fprintf(stderr, "sb1::%u\n", cal_cigar_xlen_fhc(aux_o));
        // }
    }

    
    // fprintf(stderr, "------[M::%s::M] [%lu, %lu), ec::%u\n", __func__, s, e, cal_cigar_xlen_fhc(aux_o));
    // fprintf(stderr, "------[M::%s::M] [%lu, %lu)\n", __func__, s, e);
    if(p->x_start == -1 || p->x_end == -1) {///hasn't neem set
        p->x_start = s; p->x_end = e-1;
    }
    // nec += push_correct0(p, &(aux_o->w_list), e-s, (uint32_t)-1);    
    nec += push_correct0_fhc(p, &(aux_o->w_list), e-s, (uint32_t)-1, NULL);    
    p->x_end = e-1;
    // if((uint32_t)p->x_end + 1 != cal_cigar_xlen_fhc(aux_o)) {
    //     fprintf(stderr, "ta2::%u\n", cal_cigar_xlen_fhc(aux_o));
    // }
    return nec;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq 0x80(%rsp), %rbp
testq %rbp, %rbp
sete %al
cmpq %rdx, %rcx
setbe %cl
testb %al, %cl
jne 0x17eb85
movq %rdx, %r14
movq 0x78(%rsp), %r15
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x17eb66
movq 0x58(%r15), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
leaq (%rcx,%rdx), %r12
addq $-0x20, %r12
movslq 0x4(%r12), %r13
incq %r13
jmp 0x17eb6c
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq %r14, %r13
ja 0x17ed92
cmpq %r14, %rbx
jne 0x17eb8c
cmpq $0x1, %rbp
jne 0x17eb8c
cmpq %r14, %r13
jne 0x17eb8c
xorl %eax, %eax
jmp 0x17ed83
testq %rax, %rax
jne 0x17ec09
cmpq $0x0, 0x50(%r15)
jne 0x17ebe0
movq $0x2, 0x50(%r15)
movq %rdi, 0x10(%rsp)
movq 0x58(%r15), %rdi
movq %rsi, 0x8(%rsp)
movl $0x40, %esi
movq %r8, (%rsp)
movq %r9, %r12
movsd %xmm0, 0x20(%rsp)
callq 0x2370
movsd 0x20(%rsp), %xmm0
movq %r12, %r9
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq (%rsp), %r8
movq %rax, 0x58(%r15)
movq 0x48(%r15), %rax
movq 0x58(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x48(%r15)
shlq $0x5, %rax
leaq (%rcx,%rax), %r12
movq $-0x1, (%rcx,%rax)
movq $0x0, 0x18(%rcx,%rax)
addq $0x48, %r15
xorl %eax, %eax
testq %r14, %r14
setne %al
xorl %ecx, %ecx
cmpq %r14, %r13
setb %cl
testq %rbp, %rbp
cmovnel %ecx, %eax
cmpb $0x1, %al
jne 0x17ecb2
movq %r8, (%rsp)
movq 0x60(%rsp), %r10
leaq 0x1c(%rsp), %rax
movq %rdi, 0x10(%rsp)
movq %rsi, %rbp
movq %r13, %rdx
movq %r14, %rcx
movq %r9, %r8
movq %r9, 0x8(%rsp)
movq %r10, %r9
pushq %rax
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq 0x88(%rsp)
callq 0x17ba87
addq $0x20, %rsp
testq %rax, %rax
je 0x17ecba
cmpl $-0x1, (%r12)
je 0x17ec85
cmpl $-0x1, 0x4(%r12)
jne 0x17ec92
movl %r13d, (%r12)
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
movl 0x1c(%rsp), %ecx
movq (%rsp), %r8
addq %r13, %r8
movq %r12, %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x17e45d
jmp 0x17ed3a
xorl %r13d, %r13d
jmp 0x17ed46
movl 0xa0(%rsp), %eax
movq 0x98(%rsp), %rcx
movq 0x68(%rsp), %rdx
movl 0x30(%rcx), %r8d
subq $0x50, %rsp
movl %eax, 0x48(%rsp)
movq %r15, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, (%rsp)
movq 0x60(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq 0x50(%rsp), %r9
callq 0x17e186
addq $0x50, %rsp
movq %rax, %r13
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
cmpl $-0x1, (%r12)
je 0x17ed55
cmpl $-0x1, 0x4(%r12)
jne 0x17ed61
movl %r14d, (%r12)
leal -0x1(%rbx), %eax
movl %eax, 0x4(%r12)
movl %ebx, %edx
subl %r14d, %edx
movq %r12, %rdi
movq %r15, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x17e45d
addq %r13, %rax
decl %ebx
movl %ebx, 0x4(%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb34d1(%rip), %rdi     # 0x23226a
leaq 0xb304b(%rip), %rsi     # 0x231deb
leaq 0xb34cb(%rip), %rcx     # 0x232272
movl $0x847, %edx            # imm = 0x847
callq 0x2110