// File: /workspace/github_cpp_makefile_star2_O1/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 0xa0(%rsp), %r10
movq 0x98(%rsp), %r14
movq 0x90(%rsp), %r8
movq 0x78(%rsp), %r9
movq 0x60(%rsp), %r11
testq %r14, %r14
je 0x9be21
movq (%r14), %r10
movq 0x10(%r10), %r15
leaq (%r9,%r9,4), %r10
movl (%r15,%r10,8), %r15d
shrl %r15d
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x9be46
testq %r10, %r10
je 0x9be3e
movq (%r10), %r10
movq 0x10(%r10), %r15
leaq (%r9,%r9,4), %r10
movl (%r15,%r10,8), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
jmp 0x9be46
movq 0x18(%r8), %r10
movq (%r10,%r9,8), %r15
movq %rax, %r10
testq %r11, %r11
je 0x9be6f
movq 0x68(%rsp), %r10
leaq 0x1(%r10), %r11
xorl %r12d, %r12d
cmpq %rcx, %r11
jne 0x9c021
movq %rax, %r11
subq %rdx, %r11
addq %r11, %r10
incq %r10
movb $0x1, %r11b
movq $-0x1, %r13
testq %r10, %r10
movq %rdi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
js 0x9bed8
cmpq %r15, %r10
jge 0x9bed8
leaq (%rbx,%rbx), %rdi
leaq (%rdx,%rbx,2), %r12
addq %r15, %rdi
subq %r10, %rdi
addq $0x1f, %rdi
movq $-0x1, %rdx
movq $-0x1, %rbp
cmpq %r12, %rdi
movq $-0x1, %rdi
jl 0x9bf01
subq %rbx, %r10
subq %r10, %r15
cmpq %r12, %r15
movq %r15, %rbp
cmovgeq %r12, %rbp
subq %rbp, %r12
testq %r10, %r10
js 0x9beef
xorl %edx, %edx
movq %r10, %r13
jmp 0x9befb
movq $-0x1, %rdx
movq $-0x1, %rdi
movq $-0x1, %rbp
jmp 0x9bf01
addq %r10, %rbp
negq %r10
xorl %r13d, %r13d
movq %r10, %rdx
movq %r12, %rdi
xorl %r11d, %r11d
xorl %r12d, %r12d
testb %r11b, %r11b
jne 0x9c021
cmpq %rax, %r13
jne 0x9bf1b
cmpq %rcx, %rbp
je 0x9c021
movl 0x80(%rsp), %eax
testq %r8, %r8
movq %rdx, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
je 0x9bf47
movzbl %al, %ecx
movq %rsi, %r15
movq %rsi, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x337f7
jmp 0x9bfab
testq %r14, %r14
je 0x9bf6f
movq (%r14), %rcx
movq 0x10(%rcx), %rcx
leaq (%r9,%r9,4), %rdx
movq 0x20(%rcx,%rdx,8), %r15
testb %al, %al
je 0x9bfa3
leaq (%rcx,%rdx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x9bfa5
movq %rsi, %r15
movq 0xa0(%rsp), %rcx
movq (%rcx), %rcx
leaq (%r9,%r9,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rcx), %rdx
movq $0x0, (%rsp)
movzbl %al, %ecx
xorl %edi, %edi
movq %r13, %r8
movq %rbp, %r9
callq 0x36b0d
jmp 0x9bfab
xorl %eax, %eax
addq %r13, %rax
addq %rax, %r15
movq 0x88(%rsp), %r14
movl $0x7fffffff, 0x2c(%r14) # imm = 0x7FFFFFFF
movq %r14, (%rsp)
movq %r15, %rdi
movl %ebp, %esi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movl %ebx, %r8d
movq 0x10(%rsp), %rbx
movl %ebx, %r9d
callq 0x8dd8a
movslq 0x2c(%r14), %rax
cmpl 0x28(%r14), %eax
setg %cl
cmpq 0x70(%rsp), %rax
setge %al
orb %cl, %al
jne 0x9c021
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
movq %rbx, (%rcx)
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq %r13, (%rdx)
movl $0x1, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq