// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rsi, %r12
movq 0xd0(%rsp), %rbp
movq 0xc8(%rsp), %rcx
movq 0xc0(%rsp), %r8
movq 0xa0(%rsp), %r11
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
xorl %esi, %esi
movl %esi, 0x14(%rsp)
movl %esi, 0x10(%rsp)
testq %rcx, %rcx
je 0x9ba2a
movq (%rcx), %rsi
movq 0x10(%rsi), %r10
leaq (%r11,%r11,4), %rsi
movl (%r10,%rsi,8), %r10d
shrl %r10d
andl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
jmp 0x9ba50
testq %rbp, %rbp
je 0x9ba48
movq (%rbp), %rsi
movq 0x10(%rsi), %r10
leaq (%r11,%r11,4), %rsi
movl (%r10,%rsi,8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jmp 0x9ba50
movq 0x18(%r8), %rsi
movq (%rsi,%r11,8), %r10
movq 0xa8(%rsp), %rbx
testq %r9, %r9
je 0x9ba90
movq 0x80(%rsp), %rsi
leaq 0x1(%rsi), %r9
cmpq %rbx, %r9
setne %r11b
cmpq $0x0, 0x90(%rsp)
setg %r9b
orb %r11b, %r9b
jne 0x9ba9e
movq %rax, %r9
subq %rdx, %r9
addq %r9, %rsi
incq %rsi
jmp 0x9baa6
cmpq $0x0, 0x88(%rsp)
movq %rax, %rsi
jle 0x9baa6
xorl %r13d, %r13d
jmp 0x9bdae
movb $0x1, %r11b
movq $-0x1, %r9
testq %rsi, %rsi
js 0x9bb0d
cmpq %r10, %rsi
jge 0x9bb0d
leaq (%r10,%r14,2), %r9
subq %rsi, %r9
addq $0x1f, %r9
movq $-0x1, %r13
movq $-0x1, 0x8(%rsp)
movq $-0x1, %r15
cmpq %rbx, %r9
movq $-0x1, %r9
jl 0x9bb35
subq %r14, %rsi
subq %rsi, %r10
cmpq %rbx, %r10
movq %r10, %r15
cmovgeq %rbx, %r15
subq %r15, %rbx
movq %rbx, 0x8(%rsp)
testq %rsi, %rsi
js 0x9bb26
xorl %r13d, %r13d
movq %rsi, %r9
jmp 0x9bb32
movq $-0x1, %r13
movq $-0x1, 0x8(%rsp)
movq $-0x1, %r15
jmp 0x9bb35
addq %rsi, %r15
negq %rsi
xorl %r9d, %r9d
movq %rsi, %r13
xorl %r11d, %r11d
movq %r13, 0x18(%rsp)
cmpq %rax, %r9
sete %al
xorl %r13d, %r13d
orb %r11b, %al
jne 0x9bdae
movq 0xb8(%rsp), %rsi
movl 0xb0(%rsp), %r10d
testq %r8, %r8
movq %rdx, 0x40(%rsp)
movq %rdi, 0x38(%rsp)
movq %r9, 0x28(%rsp)
je 0x9bbc1
movslq 0x18(%rsp), %rbp
movq %r14, %rbx
leaq (%r12,%rbp), %r14
movzbl %r10b, %ecx
movq %r14, %rdi
movq %r9, %rsi
movq %r15, %rdx
movq 0xa0(%rsp), %r9
callq 0x337f7
movq %r12, %rdi
movl $0x4e, %esi
movq %rbp, %rdx
callq 0x20e0
addq %r15, %r14
movq 0x8(%rsp), %rbp
movslq %ebp, %rdx
movq %r14, %rdi
movq %rbx, %r14
movl $0x4e, %esi
jmp 0x9bccb
testq %rcx, %rcx
je 0x9bbf6
movq (%rcx), %rax
movq 0x10(%rax), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rax,%rcx,8), %rbx
testb %r10b, %r10b
je 0x9bc69
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x9bc6b
movq %r12, %rdi
movl $0x4e, %esi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
callq 0x20e0
movq %r14, 0x20(%rsp)
leaq (%r12,%rbx), %r14
movq (%rbp), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movl 0xb8(%rsp), %eax
movzbl %al, %ecx
xorl %edi, %edi
movq %r14, %rsi
movq 0x30(%rsp), %r8
movq %r15, %r9
pushq $0x0
callq 0x36b0d
addq $0x10, %rsp
addq %r15, %r14
movq %r14, %rdi
movq 0x20(%rsp), %r14
movl $0x4e, %esi
movq 0x8(%rsp), %rbp
jmp 0x9bcc8
xorl %eax, %eax
movq 0x8(%rsp), %rbp
addq %rax, %rbx
movq %rbp, %rax
movq 0x18(%rsp), %rcx
orq %rcx, %rax
je 0x9bdc0
movq %r12, %rdi
movl $0x4e, %esi
movq %rcx, %rbp
movq %rcx, %rdx
callq 0x20e0
movq %r14, 0x20(%rsp)
leaq (%r12,%rbp), %r14
addq 0x28(%rsp), %rbx
movq 0x8(%rsp), %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2160
addq %r15, %r14
movq %r14, %rdi
movq 0x20(%rsp), %r14
movl $0x4e, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0xb8(%rsp), %rsi
leaq 0xff0(%rsi), %rax
leaq 0xc08(%rsi), %rbx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %r11
leaq 0x14(%rsp), %r15
movzwl %r14w, %r8d
leaq 0x34(%rsp), %r14
movq %r12, %rdi
movq %rsi, %r12
movq 0xa8(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %r14, %r9
pushq %r10
pushq %r10
pushq %rbx
pushq %rax
pushq %r11
pushq %r15
callq 0x8607d
addq $0x30, %rsp
movl (%r14), %ecx
cmpl 0x98(%rsp), %ecx
jae 0x9bdae
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 0x28(%rsp), %r11
movq %r11, (%r10)
movl 0x14(%rsp), %r10d
movl %r10d, (%r9)
movl %eax, (%r8)
movq 0x18(%rsp), %rax
movq %rax, (%rdi)
movq %rbp, (%rsi)
movl %ecx, (%rdx)
movslq 0x10(%rsp), %rdx
movl %edx, 0x7d70(%r12)
addq $0xa14, %r12            # imm = 0xA14
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2160
movl $0x1, %r13d
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r9, %rbx
movq %rbx, %r12
jmp 0x9bcd8