// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: cal_exact_non_retrieve_exz(overlap_region*, bit_extz_t*, char*, char*, long, long, long, long, long, long, long)
int64_t cal_exact_non_retrieve_exz(overlap_region *z, bit_extz_t *exz, char* qstr, char* tstr, int64_t qs, int64_t qe, int64_t ts, int64_t te, 
int64_t q_tot_l, int64_t t_tot_l, int64_t mode)
{
    clear_align(*exz); exz->thre = 0; exz->cigar.n = 0;
    int64_t ql, tl; 
    char *q_string, *t_string; ql = qe - qs;
    // if(hpc_g) t_tot_l = hpc_len(*hpc_g, id);
    // else if(uref) t_tot_l = uref->ug->u.a[id].len;
    // else t_tot_l = Get_READ_LENGTH((*rref), id);

    if(mode == 3) {//semi
        ts = (qs - z->x_pos_s) + z->y_pos_s; ts += y_start_offset(qs, &(z->f_cigar));
        te = ts + ql; 
    } else if(mode == 1) {///forward extension
        te = ts + ql; 
    } else if(mode == 2) {///backward extension
        ts = te - ql; 
    }
    if(ts < 0) ts = 0;
    if(ts > t_tot_l) ts = t_tot_l;
    if(te > t_tot_l) te = t_tot_l;
    ql = qe - qs; tl = te - ts; 
    if(ql != tl) return 0;

    q_string = qstr + qs; t_string = tstr + ts;

    if(memcmp(q_string, t_string, ql)) return 0;
    exz->err = 0; push_trace(&(exz->cigar), 0, ql);
    exz->pl = tl; exz->ps = 0; exz->pe = tl-1;
    exz->tl = ql; exz->ts = 0; exz->te = ql-1;
    // cigar_check(t_string, q_string, exz);
    // if(!cigar_check(t_string, q_string, exz)) {
    //     fprintf(stderr, "[M::%s::] cigar_n::%d\n", __func__, (int32_t)exz->cigar.n);
    //     fprintf(stderr, "[M::%s::] pstr::%.*s\n", __func__, (int32_t)tl, t_string);
    //     fprintf(stderr, "[M::%s::] tstr::%.*s\n", __func__, (int32_t)ql, q_string);
    // }
    exz->ps += ts; exz->pe += ts;
    exz->ts += qs; exz->te += qs;
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r13
movq %rsi, %r15
movq %rdi, %rsi
movq 0x70(%rsp), %rax
movabsq $0x7fffffff00000000, %rdi # imm = 0x7FFFFFFF00000000
movq %rdi, 0x28(%r15)
andq $0x0, 0xa8(%r15)
movq 0x68(%rsp), %r12
movq 0x50(%rsp), %rbp
subq %r8, %rbx
cmpq $0x1, %rax
je 0x3411a
movq 0x58(%rsp), %rdi
cmpq $0x2, %rax
je 0x34112
cmpq $0x3, %rax
jne 0x3411e
movl 0x4(%rsi), %eax
movl 0x14(%rsi), %edi
movq %rdi, 0x8(%rsp)
movq %r13, %r14
subq %rax, %r14
addq $0x38, %rsi
movq %r13, %rdi
movq %rcx, 0x10(%rsp)
movq %rdx, %rbp
callq 0x1bebf
movq %rbp, %rdx
movq 0x10(%rsp), %rcx
movq %rax, %rbp
addq 0x8(%rsp), %rbp
addq %r14, %rbp
leaq (%rbx,%rbp), %rdi
jmp 0x3411e
movq %rdi, %rbp
subq %rbx, %rbp
jmp 0x3411e
leaq (%rbx,%rbp), %rdi
xorl %eax, %eax
testq %rbp, %rbp
cmovleq %rax, %rbp
cmpq %r12, %rbp
cmovgeq %r12, %rbp
cmpq %r12, %rdi
cmovlq %rdi, %r12
subq %rbp, %r12
cmpq %r12, %rbx
jne 0x34193
addq %r13, %rdx
addq %rbp, %rcx
movq %rdx, %rdi
movq %rcx, %rsi
movq %rbx, %rdx
callq 0x21a0
testl %eax, %eax
je 0x34159
xorl %eax, %eax
jmp 0x34193
leaq 0xa8(%r15), %rdi
andl $0x0, 0x2c(%r15)
xorl %esi, %esi
movl %ebx, %edx
callq 0x62885
movl %ebx, 0x18(%r15)
movl %ebx, 0x24(%r15)
movl %ebp, 0x10(%r15)
leal (%rbx,%rbp), %eax
decl %eax
movl %eax, 0x14(%r15)
movl %r13d, 0x1c(%r15)
leal -0x1(%rbx,%r13), %eax
movl %eax, 0x20(%r15)
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq