// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rsi, %r15
movq 0x80(%rsp), %rax
movq 0x60(%rsp), %r13
movabsq $0x7fffffff00000000, %rsi # imm = 0x7FFFFFFF00000000
movq %rsi, 0x28(%r15)
movq $0x0, 0xa8(%r15)
subq %r8, %rbx
cmpq $0x1, %rax
je 0x64cfa
movq 0x68(%rsp), %rsi
cmpq $0x2, %rax
je 0x64cf2
cmpq $0x3, %rax
jne 0x64d49
movq %rdi, %r12
movq %rdx, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movl 0x4(%rdi), %eax
movq %rax, 0x8(%rsp)
movl 0x14(%rdi), %eax
movq %rax, 0x10(%rsp)
leaq 0x38(%rdi), %rbp
movl 0x40(%rdi), %esi
decl %esi
movq %rbp, %rdi
callq 0x3d110
cltq
movl 0x40(%r12), %r13d
cmpq %r14, %rax
je 0x64d17
testl %r13d, %r13d
je 0x64ea6
xorl %r13d, %r13d
movq %rbp, %rdi
movl %r13d, %esi
callq 0x3d110
cltq
cmpq %r14, %rax
jg 0x64d00
incq %r13
movl 0x40(%r12), %eax
cmpq %rax, %r13
jb 0x64cd1
jmp 0x64d0e
movq %rsi, %r13
subq %rbx, %r13
jmp 0x64d49
leaq (%rbx,%r13), %rsi
jmp 0x64d49
testq %r13, %r13
je 0x64ea6
movl 0x40(%r12), %eax
cmpq %rax, %r13
je 0x64ea6
movq %r14, %rax
subq 0x8(%rsp), %rax
movq 0x10(%rsp), %r12
addq %rax, %r12
decl %r13d
movq %rbp, %rdi
movl %r13d, %esi
callq 0x3d11b
movslq %eax, %r13
addq %r12, %r13
leaq (%rbx,%r13), %rsi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x78(%rsp), %rdi
xorl %eax, %eax
testq %r13, %r13
cmovleq %rax, %r13
cmpq %rdi, %r13
cmovgeq %rdi, %r13
cmpq %rdi, %rsi
cmovlq %rsi, %rdi
subq %r13, %rdi
cmpq %rdi, %rbx
jne 0x64e97
addq %r14, %rdx
addq %r13, %rcx
movq %rdx, %rdi
movq %rcx, %rsi
movq %rbx, %rdx
callq 0x21a0
testl %eax, %eax
je 0x64d90
xorl %eax, %eax
jmp 0x64e97
movl $0x0, 0x2c(%r15)
movl %ebx, %ebp
cmpl $0x3fff, %ebx           # imm = 0x3FFF
jb 0x64e0e
movq 0xa8(%r15), %rcx
movq 0xb8(%r15), %rax
movl $0x2, %r12d
movl %ebx, %ebp
cmpq 0xb0(%r15), %rcx
jne 0x64dec
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0xb0(%r15)
addq %rsi, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xb8(%r15)
movq 0xa8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0xa8(%r15)
movw $0x3fff, (%rax,%rcx,2)  # imm = 0x3FFF
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
movq %rdx, %rcx
cmpl $0x3ffe, %ebp           # imm = 0x3FFE
ja 0x64db8
testl %ebp, %ebp
je 0x64e6e
movq 0xa8(%r15), %rcx
cmpq 0xb0(%r15), %rcx
jne 0x64e58
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0xb0(%r15)
movq 0xb8(%r15), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%r15)
movq 0xa8(%r15), %rcx
jmp 0x64e5f
movq 0xb8(%r15), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0xa8(%r15)
movw %bp, (%rax,%rcx,2)
movl %ebx, 0x18(%r15)
movl %ebx, 0x24(%r15)
movl %r13d, 0x10(%r15)
leal (%rbx,%r13), %eax
decl %eax
movl %eax, 0x14(%r15)
movl %r14d, 0x1c(%r15)
leal (%rbx,%r14), %eax
decl %eax
movl %eax, 0x20(%r15)
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6058