// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: recal_boundary_exz(char*, char*, long, long, long, long, long, long, long, long, unsigned int, bit_extz_t*, All_reads*, hpc_t*, ul_idx_t const*, long*, long*, long*)
inline int recal_boundary_exz(char* qstr, char* tstr, int64_t ql0, int64_t tl0, int64_t thres,
int64_t toff, int64_t ts0, int64_t te0, int64_t err0, 
int64_t tid, uint32_t rev, bit_extz_t *exz,
All_reads* rref, hpc_t *hpc_g, const ul_idx_t *uref, 
int64_t *ts_r, int64_t *aux_beg_r, int64_t *aux_end_r)
{
    int64_t ts, tl, t_tot_l, aux_beg, aux_end, t_pri_l, aln_l = ql0 + (thres << 1);
    char *q_string = qstr, *t_string; 
    if(hpc_g) t_tot_l = hpc_len(*hpc_g, tid);
    else if(uref) t_tot_l = uref->ug->u.a[tid].len;
    else t_tot_l = Get_READ_LENGTH((*rref), tid);

    if(ts0 == 0) {//left boundary
        ts = toff;
    } else if((te0 + 1) == tl0) {//right boundary
        ts = toff + te0 - ql0 + 1;
    } else {
        return 0;
    }
    if(!init_waln(thres, ts, t_tot_l, aln_l, &aux_beg, &aux_end, &ts, &t_pri_l)) return 0;
    if(ts == toff && tl0 == t_pri_l) return 0;//unchanged, make no sense

    tl = t_pri_l;
    if(rref) {
        recover_UC_Read_sub_region(tstr, ts, tl, rev, rref, tid); t_string = tstr;
    } else {
        t_string = return_str_seq_exz(tstr, ts, tl, rev, hpc_g, uref, tid);
    }

    clear_align(*exz); 
    ed_band_cal_semi_64_w_absent_diag_trace(t_string, tl, q_string, ql0, thres, aux_beg, exz);

    if(is_align(*exz) && exz->err < err0) {
        (*aux_beg_r) = aux_beg;
        (*aux_end_r) = aux_end;
        (*ts_r) = ts;
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r14
movq %rsi, %r8
movq %rdi, %r13
movq 0xc0(%rsp), %rcx
movq 0xb8(%rsp), %rsi
movq 0xb0(%rsp), %rdi
movq 0x98(%rsp), %rdx
movq 0x80(%rsp), %rax
testq %rsi, %rsi
je 0x659a5
movq (%rsi), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rdx, %rdx
movl (%rcx,%rdx), %edx
shrl %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x659c8
testq %rcx, %rcx
je 0x659c0
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rdx, %rdx
movl (%rcx,%rdx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x659c8
movq 0x18(%rdi), %rcx
movq (%rcx,%rdx,8), %rdx
movq %r15, %rsi
testq %rax, %rax
je 0x659f5
movq 0x88(%rsp), %rax
leaq 0x1(%rax), %rcx
xorl %r12d, %r12d
cmpq %rbp, %rcx
jne 0x65b2d
movq %r15, %rcx
subq %r14, %rcx
leaq (%rcx,%rax), %rsi
incq %rsi
movq %r8, 0x10(%rsp)
leaq (%r14,%rbx,2), %rcx
leaq 0x40(%rsp), %rax
movq %rsi, (%rax)
leaq 0x28(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movq %rax, (%rsp)
leaq 0x38(%rsp), %r8
leaq 0x30(%rsp), %r9
movq %rbx, %rdi
callq 0x1c7e7
xorl %r12d, %r12d
testl %eax, %eax
je 0x65b2d
movq %r13, 0x20(%rsp)
movq 0x40(%rsp), %rsi
xorq %rsi, %r15
movq 0x28(%rsp), %r13
xorq %r13, %rbp
orq %r15, %rbp
je 0x65b2d
movq 0xa8(%rsp), %rbp
movl 0xa0(%rsp), %eax
movq 0xb0(%rsp), %r8
testq %r8, %r8
movq %rsi, 0x18(%rsp)
je 0x65a90
movzbl %al, %ecx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r13, %rdx
movq 0x98(%rsp), %r9
callq 0x6c9e
movq %r15, %rdi
jmp 0x65abf
movq 0x98(%rsp), %rcx
movq %rcx, (%rsp)
movzbl %al, %ecx
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movq 0xb8(%rsp), %r8
movq 0xc0(%rsp), %r9
callq 0x578d7
movq %rax, %rdi
movl $0x7fffffff, 0x2c(%rbp) # imm = 0x7FFFFFFF
movq 0x38(%rsp), %r15
movq %rbp, (%rsp)
movl %r13d, %esi
movq 0x20(%rsp), %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x59275
movslq 0x2c(%rbp), %rax
cmpl 0x28(%rbp), %eax
setg %cl
cmpq 0x90(%rsp), %rax
setge %al
orb %cl, %al
jne 0x65b2d
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq 0xc8(%rsp), %rdx
movq %r15, (%rcx)
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq %rax, (%rdx)
pushq $0x1
popq %r12
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq