// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %rsi, %r15
movq %rdi, %rsi
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %r14
movq 0x50(%rsp), %r12
movabsq $0x7fffffff00000000, %rdi # imm = 0x7FFFFFFF00000000
movq %rdi, 0x28(%r15)
movq $0x0, 0xa8(%r15)
subq %r8, %rbx
cmpq $0x1, %rax
je 0x650a4
movq 0x58(%rsp), %rdi
cmpq $0x2, %rax
je 0x6509c
cmpq $0x3, %rax
jne 0x650a8
movl 0x4(%rsi), %eax
movl 0x14(%rsi), %edi
movq %rdi, 0x10(%rsp)
movq %rbp, %r13
subq %rax, %r13
addq $0x38, %rsi
movq %rbp, %rdi
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
callq 0x48df6
movq %r12, %rdx
movq 0x8(%rsp), %rcx
movq %rax, %r12
addq 0x10(%rsp), %r12
addq %r13, %r12
leaq (%r12,%rbx), %rdi
jmp 0x650a8
movq %rdi, %r12
subq %rbx, %r12
jmp 0x650a8
leaq (%rbx,%r12), %rdi
xorl %eax, %eax
testq %r12, %r12
cmovleq %rax, %r12
cmpq %r14, %r12
cmovgeq %r14, %r12
cmpq %r14, %rdi
cmovlq %rdi, %r14
subq %r12, %r14
cmpq %r14, %rbx
jne 0x651fa
addq %rbp, %rdx
addq %r12, %rcx
movq %rdx, %rdi
movq %rcx, %rsi
movq %rbx, %rdx
callq 0x21a0
testl %eax, %eax
je 0x650ea
xorl %eax, %eax
jmp 0x651fa
movq %rbp, 0x8(%rsp)
movl $0x0, 0x2c(%r15)
movl %ebx, %ebp
cmpl $0x3fff, %ebx           # imm = 0x3FFF
jb 0x6516e
movl $0x2, %r13d
movl %ebx, %ebp
movq 0xb0(%r15), %rax
cmpq %rax, 0xa8(%r15)
jne 0x65141
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0xb0(%r15)
movq 0xb8(%r15), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%r15)
movq 0xa8(%r15), %rax
movq 0xb8(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%r15)
movw $0x3fff, (%rcx,%rax,2)  # imm = 0x3FFF
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
cmpl $0x3ffe, %ebp           # imm = 0x3FFE
ja 0x65109
testl %ebp, %ebp
movq 0x8(%rsp), %r13
je 0x651d1
movq 0xb0(%r15), %rax
cmpq %rax, 0xa8(%r15)
jne 0x651b4
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0xb0(%r15)
movq 0xb8(%r15), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%r15)
movq 0xa8(%r15), %rax
movq 0xb8(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%r15)
movw %bp, (%rcx,%rax,2)
movl %r14d, 0x18(%r15)
movl %ebx, 0x24(%r15)
movl %r12d, 0x10(%r15)
leal (%r14,%r12), %eax
decl %eax
movl %eax, 0x14(%r15)
movl %r13d, 0x1c(%r15)
leal (%rbx,%r13), %eax
decl %eax
movl %eax, 0x20(%r15)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq