// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_aln_all(overlap_region*, k_mer_hit*, long, long, long, ul_idx_t const*, hpc_t*, All_reads*, char*, UC_Read*, ul_ov_t*, long, long, long, bit_extz_t*, overlap_region*, double)
int64_t ovlp_base_aln_all(overlap_region *z, k_mer_hit *ch_a, int64_t ch_n, 
int64_t soff, int64_t eoff, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, 
char* qstr, UC_Read *tu, ul_ov_t *ov, int64_t ql, int64_t tl, int64_t wl, bit_extz_t *exz, 
overlap_region *aux_o, double e_rate)
{
    int64_t ibeg, iend, i, l, mode, q[2], t[2], is_done;
    ibeg = soff; iend = eoff;
    for (l = ibeg, i = ibeg + 1; i <= iend; i++) {
        l = i - 1;
        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] 
        }
        assert(mode != 3);
        if(mode == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
        ///at cns chain, the base alignment fails; there is no anchor between soff and eoff
        if((eoff-soff<=1) && (((q[1]-q[0])>>1) < MAX_CNS_E)) {
            is_done = 0;
        } else {
            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_SIN_L, MAX_SIN_E, FORCE_SIN_L, -1, aux_o);
        }

        if(!is_done) {
            push_unmap_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
            // chain_win_aln(z, dp, cl, q[0], q[1], t[0], t[1], ql, tl, wl, exz);
        }
        // if(aux_o->y_id == 109111) {
        //     fprintf(stderr, "<[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, is_done::%ld\n", 
        //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, is_done);
        // }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r9, 0x10(%rsp)
movq %rdx, 0x38(%rsp)
movq %rdi, 0x8(%rsp)
movq %r8, 0x30(%rsp)
subq %rcx, %r8
movq %r8, 0x28(%rsp)
jle 0x67faa
movq 0xa0(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x20(%rsp)
movq %rcx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %r15
addq $0x10, %r15
movq $-0x1, %rbx
movq 0x20(%rsp), %rax
movq $-0x1, %r13
testq %rcx, %rcx
js 0x67dc9
leaq -0x8(%r15), %rax
movl -0xc(%r15), %r13d
incq %rcx
movq 0xa0(%rsp), %r8
cmpq 0x38(%rsp), %rcx
jge 0x67de2
movl 0x4(%r15), %ebx
movq %r15, %r8
cmpq $-0x1, %r13
setne %dl
cmpq $-0x1, %rbx
setne %sil
testb %sil, %dl
je 0x67e00
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ebp, %ebp
jmp 0x67e43
cmpq $-0x1, %r13
setne %dl
cmpq $-0x1, %rbx
sete %sil
testb %sil, %dl
je 0x67e22
movl $0x1, %ebp
movb $0x1, %sil
xorl %edi, %edi
xorl %edx, %edx
jmp 0x67e43
cmpq $-0x1, %rbx
setne %sil
cmpq $-0x1, %r13
sete %dl
andb %sil, %dl
movl %edx, %edi
xorb $0x1, %dil
movzbl %dl, %ebp
xorq $0x3, %rbp
xorl %esi, %esi
testb %dil, %dil
jne 0x67fbb
movl (%rax), %r14d
movl 0x8(%r8), %r12d
orb %dl, %sil
cmpb $0x1, %sil
movq %rcx, 0x40(%rsp)
jne 0x67ee7
cmpl $0x2, %ebp
je 0x67e98
cmpl $0x1, %ebp
movq 0xb0(%rsp), %rax
jne 0x67ebe
movq 0xa8(%rsp), %rcx
movq %rcx, %rbx
subq %r14, %rbx
movq %rax, %r12
subq %r13, %r12
cmpq %r12, %rbx
jle 0x67eb3
addq %r14, %r12
movq %rax, %rbx
jmp 0x67ec6
movq %rbx, %r13
subq %r12, %r13
movq 0xb0(%rsp), %rax
jge 0x67ebb
movq %r12, %r14
subq %rbx, %r14
xorl %r13d, %r13d
jmp 0x67ebe
addq %r13, %rbx
movq %rcx, %r12
jmp 0x67ec6
xorl %r14d, %r14d
movq 0xa8(%rsp), %rcx
testq %r14, %r14
movl $0x0, %edx
cmovleq %rdx, %r14
testq %r13, %r13
cmovleq %rdx, %r13
cmpq %rcx, %r12
cmovgeq %rcx, %r12
cmpq %rax, %rbx
cmovgeq %rax, %rbx
cmpq $0x1, 0x28(%rsp)
jg 0x67efd
movq %r12, %rax
subq %r14, %rax
cmpq $0x7fe, %rax            # imm = 0x7FE
jl 0x67f74
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
movq 0xa0(%rsp), %r9
movsd 0x20(%rsp), %xmm0
pushq 0xd0(%rsp)
pushq $-0x1
pushq $0x200                  # imm = 0x200
pushq $0x7ff                  # imm = 0x7FF
pushq $0x2710                 # imm = 0x2710
pushq 0xd8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq %rbp
pushq %rbx
pushq %r13
pushq %r12
pushq %r14
callq 0x661e6
addq $0x70, %rsp
testq %rax, %rax
jne 0x67f96
decq %r12
decq %rbx
movq 0xc8(%rsp), %rdi
movl %r14d, %esi
movq %r12, %rdx
movq %r13, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x65e4a
addq $0x10, %r15
movq 0x40(%rsp), %rcx
cmpq %rcx, 0x30(%rsp)
jne 0x67da9
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1beeca(%rip), %rdi    # 0x226e8c
leaq 0x1bd67a(%rip), %rsi    # 0x225643
leaq 0x1beec6(%rip), %rcx    # 0x226e96
movl $0x412b, %edx           # imm = 0x412B
callq 0x2110