// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %r9, %rax
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq 0xa0(%rsp), %r11
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %r10
movq 0x78(%rsp), %r9
movq 0x60(%rsp), %r15
testq %rsi, %rsi
je 0x9c55c
movq %r11, %r8
movq %r10, %rdx
movq (%rsi), %r10
movq 0x10(%r10), %r10
leaq (%r9,%r9,4), %r11
movl (%r10,%r11,8), %r12d
shrl %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
jmp 0x9c58d
testq %r11, %r11
je 0x9c57f
movq %r10, %rdx
movq %r11, %r8
movq (%r11), %r10
movq 0x10(%r10), %r10
leaq (%r9,%r9,4), %r11
movl (%r10,%r11,8), %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
jmp 0x9c58d
movq %r11, %r8
movq %r10, %rdx
movq 0x18(%r10), %r10
movq (%r10,%r9,8), %r12
movq %rax, %r13
testq %r15, %r15
je 0x9c5b6
movq 0x68(%rsp), %r11
leaq 0x1(%r11), %r10
xorl %ebp, %ebp
cmpq %rcx, %r10
jne 0x9c740
movq %rax, %r10
subq %r14, %r10
leaq (%r10,%r11), %r13
incq %r13
xorl %ebp, %ebp
testq %r13, %r13
js 0x9c740
cmpq %r12, %r13
jge 0x9c740
leaq (%rbx,%rbx), %r10
leaq (%r14,%rbx,2), %r11
addq %r12, %r10
subq %r13, %r10
addq $0x1f, %r10
cmpq %r11, %r10
jl 0x9c740
movq %rdi, 0x20(%rsp)
subq %rbx, %r13
subq %r13, %r12
cmpq %r11, %r12
cmovgeq %r11, %r12
xorl %ebp, %ebp
testq %r13, %r13
movl $0x0, %r10d
cmovgq %r13, %r10
movl $0x0, %r15d
cmovsq %r13, %r15
addq %r12, %r15
cmpq %rax, %r10
jne 0x9c621
cmpq %rcx, %r15
je 0x9c740
movl 0x80(%rsp), %edi
movq %r13, %rcx
negq %rcx
sarq $0x3f, %r13
andq %rcx, %r13
testq %rdx, %rdx
movq %r11, 0x18(%rsp)
movq %r10, 0x10(%rsp)
je 0x9c665
movq %rdx, %rax
movzbl %dil, %ecx
movq 0x8(%rsp), %rdi
movq %r10, %rsi
movq %r15, %rdx
movq %rax, %r8
callq 0x32ef8
movq 0x8(%rsp), %rdi
jmp 0x9c6c6
testq %rsi, %rsi
je 0x9c68f
movq (%rsi), %rcx
movq 0x10(%rcx), %rcx
leaq (%r9,%r9,4), %rdx
movl %edi, %eax
movq 0x20(%rcx,%rdx,8), %rdi
testb %al, %al
je 0x9c6be
leaq (%rcx,%rdx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x9c6c0
movq (%r8), %rcx
leaq (%r9,%r9,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
movq $0x0, (%rsp)
movzbl %dil, %ecx
xorl %edi, %edi
movq 0x8(%rsp), %rsi
movq %r10, %r8
movq %r15, %r9
callq 0x36049
jmp 0x9c65e
xorl %eax, %eax
addq %r10, %rax
addq %rax, %rdi
movq 0x88(%rsp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq %rax, (%rsp)
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x8d32c
movq 0x88(%rsp), %rcx
movslq 0x2c(%rcx), %rax
cmpl 0x28(%rcx), %eax
setg %cl
cmpq 0x70(%rsp), %rax
setge %al
orb %cl, %al
movq 0x18(%rsp), %rsi
jne 0x9c740
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
subq %r12, %rsi
movq %r13, (%rcx)
movq %rsi, (%rax)
movq 0x10(%rsp), %rax
movq %rax, (%rdx)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq