// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdi, (%rsp)
movl (%rcx), %eax
movl 0xc(%rcx), %ebp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rax
movq $-0x1, %r14
cmovneq %rax, %r14
cmpq %rbp, %r14
jge 0x68322
movq %rcx, 0x30(%rsp)
leaq 0x4(%rcx), %rax
movq %rax, 0x40(%rsp)
negq %rbp
leaq 0x1(%r14), %rbx
movq %r14, %rax
shlq $0x4, %rax
movq %rsi, 0x10(%rsp)
leaq (%rax,%rsi), %r12
addq $0x10, %r12
movq %rbp, 0x38(%rsp)
movq %rbp, %rax
addq %rbx, %rax
je 0x68076
movl (%r12), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %ecx, %eax
je 0x68076
cmpl %eax, 0xc(%r12)
jae 0x68076
movq %r14, %rcx
jmp 0x682f8
movq $-0x1, %r15
movq 0x40(%rsp), %rcx
movq $-0x1, %rax
testq %r14, %r14
js 0x680a4
movq %r14, %rax
shlq $0x4, %rax
movq 0x10(%rsp), %rcx
addq %rax, %rcx
addq $0x8, %rcx
movl -0x4(%rcx), %eax
movq 0x30(%rsp), %rdx
cmpq 0x28(%rsp), %rbx
jge 0x680b8
movl 0x4(%r12), %r15d
movq %r12, %rdx
cmpq $-0x1, %rax
setne %sil
cmpq $-0x1, %r15
setne %dil
andb %sil, %dil
je 0x680da
xorl %esi, %esi
xorl %r9d, %r9d
xorl %r8d, %r8d
xorl %r13d, %r13d
jmp 0x6811b
cmpq $-0x1, %rax
je 0x680f6
cmpq $-0x1, %r15
jne 0x680f6
xorl %esi, %esi
movl $0x1, %r13d
movb $0x1, %r9b
xorl %r8d, %r8d
jmp 0x6811b
cmpq $-0x1, %r15
setne %sil
cmpq $-0x1, %rax
sete %r8b
andb %sil, %r8b
movl %r8d, %esi
xorb $0x1, %sil
movzbl %r8b, %r13d
xorq $0x3, %r13
xorl %r9d, %r9d
movl (%rcx), %r11d
movl 0x8(%rdx), %r10d
testb %dil, %dil
je 0x6817f
movq %r14, %rcx
shlq $0x4, %rcx
movq 0x10(%rsp), %rdx
movl (%rdx,%rcx), %ecx
movl %ecx, %edx
notl %edx
testl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jne 0x6817f
testl %ecx, %ecx
js 0x6817f
cmpl $-0x1, (%r12)
jne 0x6817f
decq %r10
decq %r15
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movl %r11d, %ecx
movq %r10, %r8
movq %rax, %r9
pushq $0x0
pushq %r15
callq 0x65f84
addq $0x10, %rsp
jmp 0x682f5
testb %sil, %sil
jne 0x6828d
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x681c6
cmpl $0x2, %r13d
movq 0xb8(%rsp), %rcx
je 0x681d0
cmpl $0x1, %r13d
movq 0xb0(%rsp), %rbp
jne 0x681f5
movq %rbp, %r15
subq %r11, %r15
movq %rcx, %r10
subq %rax, %r10
cmpq %r10, %r15
jle 0x681ea
addq %r11, %r10
movq %rcx, %r15
jmp 0x681f5
movq 0xb0(%rsp), %rbp
jmp 0x68216
movq %r15, %rax
subq %r10, %rax
movq 0xb0(%rsp), %rbp
jge 0x681f2
movq %r10, %r11
subq %r15, %r11
xorl %eax, %eax
jmp 0x681f5
addq %rax, %r15
movq %rbp, %r10
jmp 0x681f5
xorl %r11d, %r11d
testq %r11, %r11
movl $0x0, %esi
cmovleq %rsi, %r11
testq %rax, %rax
cmovleq %rsi, %rax
cmpq %rbp, %r10
cmovgeq %rbp, %r10
cmpq %rcx, %r15
cmovgeq %rcx, %r15
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
movq 0xa0(%rsp), %r9
movsd 0x28(%rsp), %xmm0
pushq 0xb0(%rsp)
pushq $-0x1
pushq $0x100                  # imm = 0x100
pushq $0x3ff                  # imm = 0x3FF
pushq $0xc00                  # imm = 0xC00
pushq %rbp
pushq 0xd8(%rsp)
pushq 0x48(%rsp)
pushq %r13
pushq %r15
pushq %rax
pushq %r10
pushq %r11
callq 0x661e6
addq $0x70, %rsp
movq %rbx, %rcx
testq %rax, %rax
movq 0x38(%rsp), %rbp
jne 0x682f8
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movq 0x18(%rsp), %r9
movsd 0x20(%rsp), %xmm0
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
pushq 0x18(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0x58(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
callq 0x67d53
addq $0x50, %rsp
movq %rbx, %rcx
leaq (%rbx,%rbp), %rax
incq %rax
incq %rbx
addq $0x10, %r12
movq %rcx, %r14
cmpq $0x1, %rax
jne 0x68050
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bec4a(%rip), %rdi    # 0x226f73
leaq 0x1bd313(%rip), %rsi    # 0x225643
leaq 0x1bec49(%rip), %rcx    # 0x226f80
movl $0x4148, %edx           # imm = 0x4148
callq 0x2110