// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r8
movq %rsi, %r12
movq 0xe0(%rsp), %rax
movq 0xd8(%rsp), %r13
movq 0xd0(%rsp), %rdx
orl $-0x1, 0xc(%rsp)
movq 0xb0(%rsp), %rcx
andl $0x0, 0x8(%rsp)
andl $0x0, 0x4(%rsp)
testq %r13, %r13
je 0x656a9
movq (%r13), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %edx
shrl %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x656cc
testq %rax, %rax
je 0x656c4
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x656cc
movq 0x18(%rdx), %rax
movq (%rax,%rcx,8), %rdx
movq 0xb8(%rsp), %rbp
testq %r9, %r9
je 0x6570c
movq 0x90(%rsp), %rax
leaq 0x1(%rax), %rcx
cmpq %rbp, %rcx
setne %cl
cmpq $0x0, 0xa0(%rsp)
setg %sil
orb %cl, %sil
jne 0x6571a
movq %rbx, %rcx
subq %r8, %rcx
leaq (%rcx,%rax), %rsi
incq %rsi
jmp 0x65722
cmpq $0x0, 0x98(%rsp)
movq %rbx, %rsi
jle 0x65722
xorl %r14d, %r14d
jmp 0x658c5
movq %rdi, 0x30(%rsp)
movq %r8, 0x38(%rsp)
leaq 0x50(%rsp), %rax
movq %rsi, (%rax)
leaq 0x40(%rsp), %r10
leaq 0x48(%rsp), %r8
leaq 0x18(%rsp), %r9
movq %r15, %rdi
movq %rbp, %rcx
pushq %r10
pushq %rax
callq 0x1c7e7
popq %rcx
popq %rdx
xorl %r14d, %r14d
testl %eax, %eax
je 0x658c5
movq 0x50(%rsp), %rsi
cmpq %rbx, %rsi
je 0x658c5
movq 0xc8(%rsp), %rbx
movl 0xc0(%rsp), %eax
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %r10
movq 0xd0(%rsp), %r8
testq %r8, %r8
movq %rsi, 0x28(%rsp)
movq %r10, 0x20(%rsp)
je 0x657c3
movq 0x18(%rsp), %r11
movzbl %al, %ecx
movq %r12, %rdi
movq 0xb0(%rsp), %r9
movq %r11, 0x10(%rsp)
pushq %r11
pushq %r10
callq 0x1b475
addq $0x10, %rsp
jmp 0x657f9
movq 0x18(%rsp), %r11
subq $0x8, %rsp
movzbl %al, %ecx
movq %r12, %rdi
movq %r13, %r8
movq 0xe8(%rsp), %r9
movq %r11, 0x18(%rsp)
pushq %r11
pushq %r10
pushq 0xc8(%rsp)
callq 0x56ba5
addq $0x20, %rsp
movq %rax, %r12
leaq 0xff0(%rbx), %rax
movq %rbx, %r13
addq $0xc08, %rbx            # imm = 0xC08
leaq 0x4(%rsp), %r10
leaq 0x8(%rsp), %r11
movzwl %r15w, %r8d
leaq 0xc(%rsp), %r15
movq %r12, %rdi
movl %ebp, %esi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r15, %r9
pushq $-0x1
pushq $-0x1
pushq %rbx
pushq %rax
pushq %r10
pushq %r11
callq 0x51ff9
addq $0x30, %rsp
movl (%r15), %ecx
cmpl 0xa8(%rsp), %ecx
jae 0x658c5
movq 0x110(%rsp), %rdx
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdi
movq 0xf8(%rsp), %r8
movq 0xf0(%rsp), %r9
movq 0xe8(%rsp), %r10
movq 0x28(%rsp), %r11
movq %r11, (%r10)
movl 0x8(%rsp), %r10d
movl %r10d, (%r9)
movl %eax, (%r8)
movq 0x20(%rsp), %rax
movq %rax, (%rdi)
movq 0x10(%rsp), %rax
movq %rax, (%rsi)
movl %ecx, (%rdx)
movslq 0x4(%rsp), %rdx
movl %edx, 0x7d70(%r13)
addq $0xa14, %r13            # imm = 0xA14
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2160
pushq $0x1
popq %r14
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq