// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: recal_boundary(char*, char*, long, long, long, long, long, long, long, unsigned int, long, long, unsigned int, Correct_dumy*, All_reads*, hpc_t*, ul_idx_t const*, long*, int*, int*, long*, long*, unsigned int*)
inline int recal_boundary(char* qstr, char* tstr1, int64_t ql, int64_t thres,
int64_t global_ts0, int64_t local_ts0, int64_t local_te0,
int64_t aux_beg0, int64_t aux_end0, unsigned int err0, 
int64_t tid, int64_t aln_l, uint32_t rev, 
Correct_dumy* dumy, All_reads* rref, hpc_t *hpc_g, const ul_idx_t *uref,
int64_t* global_ts1, int* local_ts1, int* local_te1,
int64_t* aux_beg1, int64_t* aux_end1, unsigned int* err1)
{
    int64_t ts, t_tot_l, aux_beg, aux_end, t_pri_l, t_end; 
    char *q_string = qstr, *t_string; unsigned int error = (unsigned int)-1; 
    int r_ts = 0, path_length = 0;
    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(local_ts0 == 0) {//left boundary
        if(aux_beg0 > 0) return 0;///shift to the left cannot get a new start pos
        ts = global_ts0;
    } else if((local_te0 + 1) == aln_l) {//right boundary
        if(aux_end0 > 0) return 0;///shift to the right cannot get a new start pos
        ts = global_ts0 + local_te0 - ql + 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 == global_ts0) return 0;//unchanged, make no sense

    if(rref) {
        fill_subregion(tstr1, ts, t_pri_l, rev, rref, tid, aux_beg, aux_end); t_string = tstr1;
    } else {
        t_string = return_str_seq(tstr1, ts, t_pri_l, rev, hpc_g, uref, tid, aux_beg, aux_end);
    }

    t_end = Reserve_Banded_BPM_PATH(t_string, aln_l, q_string, ql, thres, &error, &r_ts,
                &path_length, dumy->matrix_bit, dumy->path_fix, -1, -1);

    if (error != (unsigned int)-1 && error < err0) {
        (*global_ts1) = ts;
        (*local_ts1) = r_ts;
        (*local_te1) = t_end;
        (*aux_beg1) = aux_beg;
        (*aux_end1) = aux_end;
        (*err1) = error;

        dumy->path_length = path_length;
        memcpy(dumy->path, dumy->path_fix, path_length);
        // memcpy(tstr0, t_string, aln_l);
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rax
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r11
movq 0xd0(%rsp), %r14
movq 0xc8(%rsp), %rcx
movq 0xc0(%rsp), %r8
movq 0xa0(%rsp), %r12
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
xorl %edx, %edx
movl %edx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
testq %rcx, %rcx
je 0x9c1b6
movq (%rcx), %rdx
movq 0x10(%rdx), %rdx
leaq (%r12,%r12,4), %rsi
movl (%rdx,%rsi,8), %edx
shrl %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x9c1d9
testq %r14, %r14
je 0x9c1d1
movq (%r14), %rdx
movq 0x10(%rdx), %rdx
leaq (%r12,%r12,4), %rsi
movl (%rdx,%rsi,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x9c1d9
movq 0x18(%r8), %rdx
movq (%rdx,%r12,8), %rdx
movq 0xa8(%rsp), %r10
testq %r9, %r9
je 0x9c220
movq 0x80(%rsp), %rsi
leaq 0x1(%rsi), %r9
movq %r10, %rbp
cmpq %r10, %r9
setne %r10b
cmpq $0x0, 0x90(%rsp)
setg %r9b
orb %r10b, %r9b
jne 0x9c22e
movq %rax, %r9
subq %rbx, %r9
leaq (%r9,%rsi), %r13
incq %r13
movq %rbp, %r10
jmp 0x9c241
cmpq $0x0, 0x88(%rsp)
movq %rax, %r13
jle 0x9c241
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
testq %r13, %r13
js 0x9c230
cmpq %rdx, %r13
jge 0x9c230
leaq (%rdx,%r15,2), %rsi
subq %r13, %rsi
addq $0x1f, %rsi
cmpq %r10, %rsi
jl 0x9c230
subq %r15, %r13
subq %r13, %rdx
cmpq %r10, %rdx
cmovgeq %r10, %rdx
xorl %ebp, %ebp
testq %r13, %r13
movl $0x0, %r9d
cmovgq %r13, %r9
movl $0x0, %esi
cmovsq %r13, %rsi
cmpq %rax, %r9
je 0x9c230
subq %rdx, %r10
movq %r13, %rax
negq %rax
sarq $0x3f, %r13
andq %rax, %r13
addq %rdx, %rsi
testq %r8, %r8
movq %rdi, 0x40(%rsp)
movq %r9, 0x30(%rsp)
movq %r10, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
je 0x9c311
movq %rsi, %rax
movslq %r13d, %rcx
movq %rcx, 0x8(%rsp)
leaq (%r11,%rcx), %r14
movl 0xb0(%rsp), %ecx
movzbl %cl, %ecx
movq %r14, %rdi
movq %r9, %rsi
movq %rax, %rdx
movq %r12, %r9
movq %r11, %r12
callq 0x32ef8
movq %r12, %rdi
movl $0x4e, %esi
movq 0x8(%rsp), %rdx
callq 0x20e0
addq 0x20(%rsp), %r14
movslq 0x18(%rsp), %rdx
movq %r14, %rdi
movl $0x4e, %esi
callq 0x20e0
movq %r12, %rdi
jmp 0x9c40e
movq 0xb8(%rsp), %rsi
testq %rcx, %rcx
je 0x9c348
movq (%rcx), %rax
movq 0x10(%rax), %rax
leaq (%r12,%r12,4), %rcx
movq 0x20(%rax,%rcx,8), %r12
movl 0xb0(%rsp), %edx
testb %dl, %dl
je 0x9c3a8
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x9c3aa
movq %r11, %rdi
movl $0x4e, %esi
movq %r13, %rdx
movq %r11, 0x8(%rsp)
callq 0x20e0
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rsi
movq (%r14), %rax
leaq (%r12,%r12,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movl 0xb8(%rsp), %eax
movzbl %al, %ecx
xorl %edi, %edi
movq %rsi, %r12
movq 0x38(%rsp), %r8
movq 0x28(%rsp), %r14
movq %r14, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
addq %r14, %r12
movq %r12, %rdi
jmp 0x9c3fa
xorl %eax, %eax
addq %rax, %r12
movq %r10, %rax
orq %r13, %rax
je 0x9c4ea
movq %r11, %rdi
movl $0x4e, %esi
movq %r13, %rdx
movq %r11, 0x8(%rsp)
movq %r9, %r14
callq 0x20e0
movq 0x8(%rsp), %rax
leaq (%rax,%r13), %rdi
movq %rdi, 0x38(%rsp)
addq %r14, %r12
movq %r12, %rsi
movq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x2160
movq 0x38(%rsp), %rdi
addq %r14, %rdi
movl $0x4e, %esi
movq 0x18(%rsp), %rdx
callq 0x20e0
movq 0x8(%rsp), %rdi
movq 0xb8(%rsp), %r14
leaq 0xff0(%r14), %rax
leaq 0xc08(%r14), %r12
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %r11
movzwl %r15w, %r8d
leaq 0x2c(%rsp), %r15
movq 0xa8(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %ebx, %ecx
movq %r15, %r9
pushq %r10
pushq %r10
pushq %r12
pushq %rax
pushq %r11
leaq 0x3c(%rsp), %rax
pushq %rax
callq 0x85726
addq $0x30, %rsp
movl (%r15), %ecx
cmpl 0x98(%rsp), %ecx
jae 0x9c230
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rsi
movq 0xf0(%rsp), %rdi
movq 0xe8(%rsp), %r8
movq 0xe0(%rsp), %r9
movq 0xd8(%rsp), %r10
movq 0x30(%rsp), %r11
movq %r11, (%r10)
movl 0x14(%rsp), %r10d
movl %r10d, (%r9)
movl %eax, (%r8)
movq %r13, (%rdi)
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
movl %ecx, (%rdx)
movslq 0x10(%rsp), %rdx
movl %edx, 0x7d70(%r14)
addq $0xa14, %r14            # imm = 0xA14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2160
movl $0x1, %ebp
jmp 0x9c230
addq %r9, %r12
movq %r12, %rdi
movq %rsi, %r14
jmp 0x9c416