// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_aln(overlap_region*, k_mer_hit*, long, ul_ov_t*, long, ul_idx_t const*, hpc_t*, All_reads*, char*, UC_Read*, bit_extz_t*, overlap_region*, double, long, long, unsigned long)
void ovlp_base_aln(overlap_region *z, k_mer_hit *ch_a, int64_t ch_n, 
ul_ov_t *ov, int64_t wl, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, UC_Read *tu, 
bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t ql, int64_t tl, uint64_t rid)
{
    int64_t ibeg, iend, i, l, mode, q[2], t[2], is_done;
    if(ov->qn == ((uint32_t)-1)) ibeg = -1;
    else ibeg = ov->qn;
    iend = ov->tn;
    assert(iend>=ibeg+1);
    // fprintf(stderr, "\n***[M::%s::rid->%lu] utg%.6dl(%c), s::%u, e::%u, z::[%u, %u), ibeg::%ld, iend::%ld, ch_n::%ld\n", 
    // __func__, rid, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], ov->qs, ov->qe, z->x_pos_s, z->x_pos_e+1, ibeg, iend, ch_n);
    for (l = ibeg, i = ibeg + 1; i <= iend; i++) {
        if(i == iend || is_pri_aln(ch_a[i])) {
            q[0] = q[1] = t[0] = t[1] = mode = -1; is_done = 0;
            if(l >= 0) {
                q[0] = ch_a[l].self_offset; t[0] = ch_a[l].offset;
            } else {
                q[0] = ov->qs;
            }

            if(i < ch_n) {
                q[1] = ch_a[i].self_offset; t[1] = ch_a[i].offset;
            } else {
                q[1] = ov->qe;
            }

            if((t[0] != -1) && (t[1] != -1)) {
                mode = 0;//global
            } else if((t[0] != -1) && (t[1] == -1)) {
                mode = 1;///forward extension
            } else if((t[0] == -1) && (t[1] != -1)) {
                mode = 2;///backward extension
            } else {
                mode = 3;///no primary hit within [ibeg, iend] 
            }
            
            if((mode == 0) && is_alnw(ch_a[l]) && is_alnw(ch_a[i]) 
                                            && (ch_a[l].strand == 0) && (ch_a[i].strand == 1)) {
                is_done = 1;
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     fprintf(stderr, "*[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
                //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
                // }
                // push_replace_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);///no need this
                push_replace_alnw_adv(z, wl, aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
            } else if(mode != 3) {
                if(mode == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     fprintf(stderr, "#[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
                //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
                // }
                is_done = hc_aln_exz_adv(z, uref, hpc_g, rref, qstr, tu, q[0], q[1], t[0], t[1], mode, wl, exz, ql, e_rate, MAX_CNS_L, MAX_CNS_E, FORCE_CNS_L, -1, aux_o);
            }
            
            if(!is_done) {///postprocess
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     fprintf(stderr, ">[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
                //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
                // }
                is_done = ovlp_base_aln_all(z, ch_a, ch_n, l, i, uref, hpc_g, rref, qstr, tu, ov, ql, tl, wl, exz, aux_o, e_rate);
            }
            // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
            //     fprintf(stderr, "-is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, l::%ld, i::%ld, ch_n::%ld\n", 
            //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, l, i, ch_n);
            // }
            // if(rid == (uint64_t)-1) {
            //     fprintf(stderr, "+is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, l::%ld, i::%ld, ch_n::%ld\n", 
            //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, l, i, ch_n);
            // }
            l = i;
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %xmm0, 0x60(%rsp)
movq %r9, 0x58(%rsp)
movq %r8, 0x28(%rsp)
movq %rdx, 0x68(%rsp)
movq %rdi, 0x18(%rsp)
movl (%rcx), %ebx
movq %rcx, 0x20(%rsp)
movl 0xc(%rcx), %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rbx
pushq $-0x1
popq %rax
cmoveq %rax, %rbx
cmpq %rbp, %rbx
jge 0x36d4a
movq %rsi, %r8
movq 0xd0(%rsp), %r13
negq %rbp
leaq 0x10(%rsi), %rax
movq %rax, 0x70(%rsp)
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %rsi, 0x10(%rsp)
movq %rbx, %r14
leaq 0x1(%rbx), %rax
movq %rbx, %rdx
shlq $0x4, %rdx
movq 0x70(%rsp), %rcx
leaq (%rcx,%rdx), %rsi
movq %rax, %rbx
addq %rbp, %rax
cmpq $0x1, %rax
je 0x36d3b
movq %rsi, %rcx
testq %rax, %rax
je 0x36b06
movl (%rcx), %edi
andl %r12d, %edi
cmpl %r12d, %edi
je 0x36b06
leaq 0x1(%rbx), %rax
leaq 0x10(%rcx), %rsi
cmpl %edi, 0xc(%rcx)
jb 0x36ad7
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
testq %r14, %r14
js 0x36b26
movl 0x4(%r8,%rdx), %eax
movl 0x8(%r8,%rdx), %esi
movq %rax, 0x30(%rsp)
jmp 0x36b31
movq 0x20(%rsp), %rax
movl 0x4(%rax), %esi
pushq $-0x1
popq %rax
movl %esi, %r10d
movq %r10, 0x40(%rsp)
cmpq 0x68(%rsp), %rbx
jge 0x36b4e
movl 0x4(%rcx), %r15d
movl 0x8(%rcx), %esi
movq %r15, 0x38(%rsp)
jmp 0x36b5a
movq 0x20(%rsp), %rsi
movl 0x8(%rsi), %esi
pushq $-0x1
popq %r15
movl %esi, %r11d
movq %r11, 0x48(%rsp)
cmpq $-0x1, %rax
je 0x36bcb
cmpq $-0x1, %r15
je 0x36bcb
movl (%r8,%rdx), %edx
movl %edx, %esi
notl %esi
testl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
jne 0x36c40
testl %edx, %edx
js 0x36c40
cmpl $-0x1, (%rcx)
jne 0x36c40
decq %r11
decq %r15
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0xd8(%rsp), %rdx
movl %r10d, %ecx
movq %r11, %r8
movq %rax, %r9
pushq $0x0
pushq %r15
callq 0x34b88
addq $0x10, %rsp
movq 0x10(%rsp), %r8
jmp 0x36ac0
cmpq $-0x1, %rax
je 0x36bdb
pushq $0x1
popq %r10
cmpq $-0x1, %r15
je 0x36bf3
cmpq $-0x1, %rax
jne 0x36ccf
pushq $0x2
popq %r10
cmpq $-0x1, %r15
je 0x36ccf
leaq 0x40(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq 0xe0(%rsp), %r13
movq %r13, %r8
movq 0xe8(%rsp), %r9
movq %r10, 0x8(%rsp)
pushq %r10
pushq $0x0
callq 0x3023a
popq %rax
popq %rcx
movq 0x40(%rsp), %r10
movq 0x48(%rsp), %r11
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %r15
jmp 0x36c51
movq $0x0, 0x8(%rsp)
movq 0xe0(%rsp), %r13
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq 0xc8(%rsp), %r8
movq 0xd0(%rsp), %r9
movq 0x68(%rsp), %xmm0
pushq 0xe0(%rsp)
pushq $-0x1
pushq $0x100                  # imm = 0x100
pushq $0x3ff                  # imm = 0x3FF
pushq $0xc00                  # imm = 0xC00
pushq %r13
movq 0x108(%rsp), %r13
pushq %r13
pushq 0x68(%rsp)
pushq 0x50(%rsp)
pushq %r15
pushq %rax
pushq %r11
pushq %r10
callq 0x34db7
addq $0x70, %rsp
testq %rax, %rax
movq 0x10(%rsp), %r8
jne 0x36ac0
movq 0x18(%rsp), %rdi
movq %r8, %rsi
movq 0x68(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movq 0x58(%rsp), %r9
movq 0x60(%rsp), %xmm0
pushq 0xd8(%rsp)
pushq %r13
pushq 0x38(%rsp)
pushq 0x100(%rsp)
pushq 0x100(%rsp)
pushq 0x48(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
callq 0x36824
movq 0x60(%rsp), %r8
addq $0x50, %rsp
jmp 0x36ac0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ae282(%rip), %rdi    # 0x1e4fd3
leaq 0x1ac94b(%rip), %rsi    # 0x1e36a3
leaq 0x1ae281(%rip), %rcx    # 0x1e4fe0
movl $0x4148, %edx           # imm = 0x4148
callq 0x2110