// File: chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_direct(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_direct(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);
    // if(z->x_id == 57 && z->y_id == 2175) {
    //     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++) {
        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 == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
        // if(z->x_id == 57 && z->y_id == 2175) {
        //     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_SIN_L, MAX_SIN_E, FORCE_SIN_L, -1, aux_o);

        // if(z->x_id == 57 && z->y_id == 2175) {
        //     fprintf(stderr, "-is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
        //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
        // }
                
        if(!is_done) {///postprocess
            push_unmap_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
        }
        l = i;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movsd %xmm0, -0x60(%rbp)
movq -0x48(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x67d28
movq $-0x1, -0x68(%rbp)
jmp 0x67d32
movq -0x48(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jl 0x67d50
jmp 0x67d6f
leaq 0x31bef4(%rip), %rdi    # 0x383c4b
leaq 0x31a5bd(%rip), %rsi    # 0x38231b
movl $0x43df, %edx           # imm = 0x43DF
leaq 0x31c619(%rip), %rcx    # 0x384383
callq 0x2130
movq -0x68(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0x68057
movq $-0x1, -0x88(%rbp)
movq $-0x1, -0xa8(%rbp)
movq $-0x1, -0xb0(%rbp)
movq $-0x1, -0x98(%rbp)
movq $-0x1, -0xa0(%rbp)
movq $0x0, -0xb8(%rbp)
cmpq $0x0, -0x80(%rbp)
jl 0x67e0e
movq -0x38(%rbp), %rax
movq -0x80(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movq -0x80(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0xb0(%rbp)
jmp 0x67e1c
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x67e5a
movq -0x38(%rbp), %rax
movq -0x78(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq -0x78(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0xa8(%rbp)
jmp 0x67e68
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x98(%rbp)
cmpq $-0x1, -0xb0(%rbp)
je 0x67e89
cmpq $-0x1, -0xa8(%rbp)
je 0x67e89
movq $0x0, -0x88(%rbp)
jmp 0x67eda
cmpq $-0x1, -0xb0(%rbp)
je 0x67eaa
cmpq $-0x1, -0xa8(%rbp)
jne 0x67eaa
movq $0x1, -0x88(%rbp)
jmp 0x67ed8
cmpq $-0x1, -0xb0(%rbp)
jne 0x67ecb
cmpq $-0x1, -0xa8(%rbp)
je 0x67ecb
movq $0x2, -0x88(%rbp)
jmp 0x67ed6
movq $0x3, -0x88(%rbp)
jmp 0x67ed8
jmp 0x67eda
cmpq $0x1, -0x88(%rbp)
je 0x67eee
cmpq $0x2, -0x88(%rbp)
jne 0x67f36
leaq -0xa0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
addq $0x8, %rsi
leaq -0xb0(%rbp), %rdx
leaq -0xb0(%rbp), %rcx
addq $0x8, %rcx
movq 0x40(%rbp), %r8
movq 0x48(%rbp), %r9
movq -0x88(%rbp), %rax
xorl %r10d, %r10d
movq $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x581e0
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x20(%rbp), %r8
movq 0x28(%rbp), %r9
movq -0xa0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x98(%rbp), %r13
movq -0xb0(%rbp), %r12
movq -0xa8(%rbp), %r15
movq -0x88(%rbp), %r14
movq -0x50(%rbp), %rbx
movq 0x30(%rbp), %r11
movq 0x40(%rbp), %r10
movsd -0x60(%rbp), %xmm0
movq 0x38(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, (%rsp)
movq -0xc0(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq $0x2710, 0x40(%rsp)     # imm = 0x2710
movq $0x7ff, 0x48(%rsp)      # imm = 0x7FF
movq $0x200, 0x50(%rsp)      # imm = 0x200
movq $-0x1, 0x58(%rsp)
movq %rax, 0x60(%rsp)
callq 0x613a0
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x6803e
movq 0x38(%rbp), %rdi
movq -0xa0(%rbp), %rax
movl %eax, %esi
movq -0x98(%rbp), %rdx
subq $0x1, %rdx
movq -0xb0(%rbp), %rcx
movq -0xa8(%rbp), %r8
subq $0x1, %r8
movq -0x88(%rbp), %r9
callq 0x60ce0
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x67d83
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)