// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rcx, %rbx
movq 0x90(%rsp), %r13
testq %r13, %r13
sete %al
cmpq %rdx, %rcx
setbe %cl
testb %al, %cl
jne 0x141a0d
movq %r9, %r10
movq %rdx, %r14
movq %rsi, %r11
movq 0x88(%rsp), %r15
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x1419f8
movq 0x58(%r15), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
movslq -0x1c(%rcx,%rdx), %rbp
incq %rbp
cmpq %r14, %rbp
ja 0x141c29
leaq (%rcx,%rdx), %r12
addq $-0x20, %r12
jmp 0x1419fd
xorl %ebp, %ebp
xorl %r12d, %r12d
cmpq %r14, %rbx
jne 0x141a14
cmpq $0x1, %r13
jne 0x141a14
cmpq %r14, %rbp
jne 0x141a14
xorl %eax, %eax
jmp 0x141c1a
leaq 0x48(%r15), %rsi
testq %rax, %rax
jne 0x141a9c
cmpq $0x0, 0x50(%r15)
je 0x141a2c
movq 0x58(%r15), %rax
xorl %ecx, %ecx
jmp 0x141a82
movq $0x2, 0x50(%r15)
movq %rdi, 0x10(%rsp)
movq 0x58(%r15), %rdi
movq %rsi, 0x8(%rsp)
pushq $0x40
popq %rsi
movq %r8, %r12
movq %r11, 0x18(%rsp)
movq %r10, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
callq 0x2370
movsd 0x28(%rsp), %xmm0
movq 0x30(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r11
movq %r12, %r8
movq 0x8(%rsp), %rsi
movq %rax, 0x58(%r15)
movq 0x48(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
shlq $0x5, %rcx
orq $-0x1, (%rax,%rcx)
leaq (%rax,%rcx), %r12
andq $0x0, 0x18(%rax,%rcx)
xorl %eax, %eax
testq %r14, %r14
setne %al
xorl %ecx, %ecx
cmpq %r14, %rbp
setb %cl
testq %r13, %r13
cmovnel %ecx, %eax
cmpb $0x1, %al
jne 0x141b46
movq %r8, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x70(%rsp), %r9
leaq 0x24(%rsp), %rax
movq %rdi, %r15
movq %r11, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r10, %r8
movq %r11, 0x18(%rsp)
pushq %rax
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
pushq 0x98(%rsp)
movq %r10, %r13
callq 0x13ef13
addq $0x20, %rsp
testq %rax, %rax
je 0x141b4e
cmpl $-0x1, (%r12)
movq 0x8(%rsp), %rsi
je 0x141b1d
cmpl $-0x1, 0x4(%r12)
jne 0x141b2a
movl %ebp, (%r12)
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
movl 0x24(%rsp), %ecx
movq 0x10(%rsp), %r8
addq %rbp, %r8
pushq $-0x1
popq %rdx
movq %r12, %rdi
callq 0x141455
jmp 0x141bce
xorl %r15d, %r15d
jmp 0x141bdf
movl 0xb0(%rsp), %eax
movq 0xa8(%rsp), %rcx
movq 0x78(%rsp), %rdx
movl 0x30(%rcx), %r8d
subq $0x50, %rsp
movl %eax, 0x48(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq 0x68(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq 0x60(%rsp), %r9
callq 0x1411ac
addq $0x50, %rsp
movq %rax, %r15
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
movq 0x8(%rsp), %rsi
cmpl $-0x1, (%r12)
je 0x141bf3
cmpl $-0x1, 0x4(%r12)
je 0x141bf3
leal -0x1(%rbx), %ebp
jmp 0x141bff
movl %r14d, (%r12)
leal -0x1(%rbx), %ebp
movl %ebp, 0x4(%r12)
subl %r14d, %ebx
pushq $-0x1
popq %rcx
movq %r12, %rdi
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x141455
addq %r15, %rax
movl %ebp, 0x4(%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xae74a(%rip), %rdi     # 0x1f037a
leaq 0xae2c4(%rip), %rsi     # 0x1efefb
leaq 0xae744(%rip), %rcx     # 0x1f0382
movl $0x847, %edx            # imm = 0x847
callq 0x2110