// File: /workspace/github_cpp_makefile_star2_O3/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), %r15
testq %r15, %r15
sete %al
cmpq %rdx, %rcx
setbe %cl
testb %al, %cl
jne 0x186025
movq %r9, %r13
movq %rdx, %r14
movq %rsi, %r10
movq 0x78(%rsp), %r12
leaq 0x48(%r12), %rsi
movq 0x48(%r12), %rax
testq %rax, %rax
je 0x186013
movq 0x58(%r12), %r12
shlq $0x5, %rax
movslq -0x1c(%r12,%rax), %rbp
incq %rbp
cmpq %r14, %rbp
ja 0x18623a
addq %rax, %r12
addq $-0x20, %r12
cmpq %r14, %rbx
jne 0x1860af
cmpq $0x1, %r15
jne 0x1860af
cmpq %r14, %rbp
je 0x186025
jmp 0x1860af
movq %r15, %rax
xorq $0x1, %rax
movq %rbx, %rcx
orq %r14, %rcx
orq %rax, %rcx
jne 0x18602c
xorl %eax, %eax
jmp 0x18622b
cmpq $0x0, 0x50(%r12)
je 0x18603d
movq 0x58(%r12), %rax
xorl %ecx, %ecx
jmp 0x18608d
movq $0x2, 0x50(%r12)
movq %rdi, 0x8(%rsp)
movq 0x58(%r12), %rdi
movq %rsi, (%rsp)
movl $0x40, %esi
movq %r8, %rbp
movq %r10, 0x10(%rsp)
movsd %xmm0, 0x20(%rsp)
callq 0x2370
movsd 0x20(%rsp), %xmm0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r10
movq %rbp, %r8
movq (%rsp), %rsi
movq %rax, 0x58(%r12)
movq 0x48(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
shlq $0x5, %rcx
leaq (%rax,%rcx), %r12
movq $-0x1, (%rax,%rcx)
movq $0x0, 0x18(%rax,%rcx)
xorl %ebp, %ebp
xorl %eax, %eax
testq %r14, %r14
setne %al
xorl %ecx, %ecx
cmpq %r14, %rbp
setb %cl
testq %r15, %r15
cmovnel %ecx, %eax
cmpb $0x1, %al
jne 0x186156
movq %r8, 0x8(%rsp)
movq %rsi, (%rsp)
movq 0x60(%rsp), %r9
leaq 0x1c(%rsp), %rax
movq %rdi, %r15
movq %r10, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r13, %r8
movq %r10, 0x10(%rsp)
pushq %rax
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq 0x88(%rsp)
callq 0x182760
addq $0x20, %rsp
testq %rax, %rax
je 0x18615e
cmpl $-0x1, (%r12)
movq (%rsp), %rsi
je 0x18612b
cmpl $-0x1, 0x4(%r12)
jne 0x186138
movl %ebp, (%r12)
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
movl 0x1c(%rsp), %ecx
movq 0x8(%rsp), %r8
addq %rbp, %r8
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1858ae
jmp 0x1861de
xorl %r15d, %r15d
jmp 0x1861ee
movl 0xa0(%rsp), %eax
movq 0x98(%rsp), %rcx
movq 0x68(%rsp), %rdx
movl 0x30(%rcx), %r8d
subq $0x50, %rsp
movl %eax, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %r13, 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 %r15, %rdi
movq 0x60(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq 0x58(%rsp), %r9
callq 0x1855d7
addq $0x50, %rsp
movq %rax, %r15
leal -0x1(%r14), %eax
movl %eax, 0x4(%r12)
movq (%rsp), %rsi
cmpl $-0x1, (%r12)
je 0x186202
cmpl $-0x1, 0x4(%r12)
je 0x186202
leal -0x1(%rbx), %ebp
jmp 0x18620e
movl %r14d, (%r12)
leal -0x1(%rbx), %ebp
movl %ebp, 0x4(%r12)
subl %r14d, %ebx
movq %r12, %rdi
movl %ebx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x1858ae
addq %r15, %rax
movl %ebp, 0x4(%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb8279(%rip), %rdi     # 0x23e4ba
leaq 0xb7df3(%rip), %rsi     # 0x23e03b
leaq 0xb8273(%rip), %rcx     # 0x23e4c2
movl $0x847, %edx            # imm = 0x847
callq 0x2110