// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
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)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq 0x50(%rbp), %rax
movq $0x0, (%rax)
movq 0x38(%rbp), %rax
movq $0x7fffffff, (%rax)     # imm = 0x7FFFFFFF
cmpq $0x0, 0x40(%rbp)
je 0xa9412
movq 0x40(%rbp), %rax
movq $-0x1, (%rax)
cmpq $0x0, 0x48(%rbp)
je 0xa9424
movq 0x48(%rbp), %rax
movq $-0x1, (%rax)
movq 0x10(%rbp), %rax
addq $0x1, %rax
subq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
movq 0x20(%rbp), %rsi
movq 0x28(%rbp), %rdx
callq 0x9e1c0
movl %eax, %edi
movq -0x40(%rbp), %rax
movl %eax, %esi
callq 0x9e370
cltq
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x68(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x58(%rbp), %r9
leaq 0x18(%rbp), %r10
leaq -0x60(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x33f90
cmpl $0x0, %eax
jne 0xa94ae
movl $0x0, -0x4(%rbp)
jmp 0xa95e1
movq -0x10(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
addq 0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpl $0x0, 0x30(%rbp)
jne 0xa950b
movq -0x78(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %esi
movq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movw %ax, %r8w
leaq -0x7c(%rbp), %r9
leaq -0x80(%rbp), %r10
leaq -0x84(%rbp), %rax
movzwl %r8w, %r8d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xc54c0
jmp 0xa9548
movq -0x78(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %esi
movq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movw %ax, %r8w
leaq -0x7c(%rbp), %r9
leaq -0x80(%rbp), %r10
leaq -0x84(%rbp), %rax
movzwl %r8w, %r8d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xc72b0
cmpl $-0x1, -0x80(%rbp)
je 0xa9594
cmpl $-0x1, -0x84(%rbp)
je 0xa9594
cmpl $0x0, 0x30(%rbp)
je 0xa9574
movq -0x40(%rbp), %rax
movslq -0x84(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x90(%rbp)
jmp 0xa9586
movl -0x84(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rcx
movq 0x50(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x40(%rbp)
je 0xa95a9
movslq -0x84(%rbp), %rcx
movq 0x40(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x48(%rbp)
je 0xa95bb
movslq -0x80(%rbp), %rcx
movq 0x48(%rbp), %rax
movq %rcx, (%rax)
movl -0x7c(%rbp), %eax
movl %eax, %ecx
movq 0x38(%rbp), %rax
movq %rcx, (%rax)
movq 0x50(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xa95da
movl $0x0, -0x4(%rbp)
jmp 0xa95e1
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)