// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0xa8(%rax)
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x3, 0x30(%rbp)
jne 0x5fc7f
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0x10(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
callq 0x331a0
addq 0x10(%rbp), %rax
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, 0x18(%rbp)
jmp 0x5fcab
cmpq $0x1, 0x30(%rbp)
jne 0x5fc94
movq 0x10(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, 0x18(%rbp)
jmp 0x5fca9
cmpq $0x2, 0x30(%rbp)
jne 0x5fca7
movq 0x18(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, 0x10(%rbp)
jmp 0x5fca9
jmp 0x5fcab
cmpq $0x0, 0x10(%rbp)
jge 0x5fcba
movq $0x0, 0x10(%rbp)
movq 0x10(%rbp), %rax
cmpq 0x28(%rbp), %rax
jle 0x5fccc
movq 0x28(%rbp), %rax
movq %rax, 0x10(%rbp)
movq 0x18(%rbp), %rax
cmpq 0x28(%rbp), %rax
jle 0x5fcde
movq 0x28(%rbp), %rax
movq %rax, 0x18(%rbp)
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x18(%rbp), %rax
subq 0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x5fd0d
movq $0x0, -0x8(%rbp)
jmp 0x5fe0d
movq -0x20(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20b0
cmpl $0x0, %eax
je 0x5fd48
movq $0x0, -0x8(%rbp)
jmp 0x5fe0d
movq -0x18(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x18(%rbp), %rdi
addq $0xa8, %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
xorl %esi, %esi
callq 0xc1070
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x48(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x40(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq 0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq 0x10(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x10(%rax)
movq 0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x14(%rax)
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq 0x1c(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1c(%rax)
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq 0x20(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x20(%rax)
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)