// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: ed_non_retrieve_cut(char*, char*, long, unsigned int, unsigned int, long, long, long, long, double, long, unsigned int, long*, long*, long*, long*)
inline uint32_t ed_non_retrieve_cut(char *qstr, char *tstr, int64_t t_tot_l, uint32_t rev, uint32_t id, 
int64_t qs, int64_t qe, int64_t t_s, int64_t block_s, double e_rate, int64_t max_err,
uint32_t aln_dir, int64_t* r_err, int64_t* qoff, int64_t* toff, int64_t* aln_qlen)
{
    (*aln_qlen) = 0; (*r_err) = INT32_MAX;
    if(qoff) (*qoff) = -1; if(toff) (*toff) = -1; 
    int64_t ql, aln_l, aux_beg, aux_end, t_pri_l, thres;
    char *q_string, *t_string; unsigned int error; int t_end, q_end;

    ql = qe + 1 - qs;
    ///there are two potiential reasons for unmatched window:
    ///1. this window has a large number of differences
    ///2. DP does not start from the right offset
    thres = double_error_threshold(get_init_err_thres(ql, e_rate, block_s, max_err), ql);
    
    aln_l = ql + (thres << 1);

    if(!init_waln(thres, t_s, t_tot_l, aln_l, &aux_beg, &aux_end, &t_s, &t_pri_l)) return 0;
    // if(t_pri_l + thres < ql) return 0;

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

    // if(id == 6) {
    //     fprintf(stderr, "-[M::%s::aln_dir->%u] qs->%ld, ts->%ld, thres->%ld, aux_beg->%ld, aux_end->%ld, t_pri_l->%ld\n", 
    //     __func__, aln_dir, qs, t_s, thres, aux_beg, aux_end, t_pri_l);
    // }
    if(aln_dir == 0) {
        Reserve_Banded_BPM_Extension(t_string, aln_l, q_string, ql, thres, &error, &t_end, &q_end);
    } else {
        Reserve_Banded_BPM_Extension_REV(t_string, aln_l, q_string, ql, thres, &error, &t_end, &q_end);
    }

    if(t_end != -1 && q_end != -1) (*aln_qlen) = (aln_dir?(ql-q_end):(q_end+1));
    if(qoff) (*qoff) = q_end; if(toff) (*toff) = t_end; (*r_err) = error;

    if((*aln_qlen) == 0) return 0;
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %rdx, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movq 0xb0(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq 0x78(%rsp), %rbp
andq $0x0, (%rax)
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rax
movq $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
testq %rdx, %rdx
je 0x57f4f
orq $-0x1, (%rdx)
movq 0x80(%rsp), %rax
movq 0x70(%rsp), %rbx
testq %rcx, %rcx
je 0x57f65
orq $-0x1, (%rcx)
subq %r12, %rbx
incq %rbx
cmpq %rax, %rbx
jge 0x57f9d
cvtsi2sd %rbx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cmpq $0x1f, %rax
pushq $0x1f
popq %rcx
cmovlq %rax, %rcx
testq %rax, %rax
pushq $0x1
popq %rdi
cmovneq %rcx, %rdi
cmpq $0x4, %rbx
cmovlq %rcx, %rdi
jmp 0x57fa5
movq 0x88(%rsp), %rdi
movl %ebx, %esi
callq 0x51fcd
movl %eax, %r14d
movslq %eax, %rdi
leaq (%rbx,%rdi,2), %r13
leaq 0x20(%rsp), %rax
leaq 0x78(%rsp), %r10
leaq 0x30(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
pushq %rax
pushq %r10
callq 0x1c7e7
popq %rcx
popq %rdx
testl %eax, %eax
je 0x58020
movl 0x90(%rsp), %ebp
movq 0x10(%rsp), %rdx
addq %r12, %rdx
addq 0x78(%rsp), %r15
leaq 0x4(%rsp), %rax
leaq 0x8(%rsp), %r10
movzwl %r14w, %r8d
leaq 0xc(%rsp), %r9
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %ecx
testl %ebp, %ebp
je 0x58024
pushq %rax
pushq %r10
callq 0x65c71
jmp 0x5802c
xorl %eax, %eax
jmp 0x580a1
pushq %rax
pushq %r10
callq 0x64b04
popq %rcx
popq %rdx
movslq 0x8(%rsp), %rax
cmpq $-0x1, %rax
setne %dl
movl 0x4(%rsp), %ecx
movslq %ecx, %rcx
cmpl $-0x1, %ecx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
movq 0xb0(%rsp), %rsi
jne 0x58069
subq %rcx, %rbx
leaq 0x1(%rcx), %rdx
testl %ebp, %ebp
cmovneq %rbx, %rdx
movq %rdx, (%rsi)
movq 0xa0(%rsp), %rdx
testq %rdx, %rdx
je 0x58079
movq %rcx, (%rdx)
movq 0xa8(%rsp), %rcx
testq %rcx, %rcx
je 0x58089
movq %rax, (%rcx)
movl 0xc(%rsp), %eax
movq 0x98(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpq $0x0, (%rsi)
setne %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq