// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xb8, %rsp
movq 0x90(%rbp), %rax
movq 0x88(%rbp), %rax
movq 0x80(%rbp), %rax
movq 0x78(%rbp), %rax
movq 0x70(%rbp), %rax
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
cmpq $0x0, 0x58(%rbp)
je 0xc6ae0
movq 0x58(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x30(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
sarl %eax
cltq
movq %rax, -0x50(%rbp)
jmp 0xc6b1f
cmpq $0x0, 0x60(%rbp)
je 0xc6b09
movq 0x60(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x30(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0xc6b1d
movq 0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
jmp 0xc6b1f
cmpq $0x0, -0x40(%rbp)
jne 0xc6b43
cmpq $0x0, 0x18(%rbp)
jle 0xc6b39
movl $0x0, -0xc(%rbp)
jmp 0xc6d85
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xc6b88
movq 0x10(%rbp), %rax
addq $0x1, %rax
cmpq 0x38(%rbp), %rax
jne 0xc6b7a
cmpq $0x0, 0x20(%rbp)
jle 0xc6b64
movl $0x0, -0xc(%rbp)
jmp 0xc6d85
movq -0x38(%rbp), %rax
addq 0x10(%rbp), %rax
subq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xc6b86
movl $0x0, -0xc(%rbp)
jmp 0xc6d85
jmp 0xc6b88
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x38(%rbp), %rcx
leaq -0x58(%rbp), %r8
leaq -0x60(%rbp), %r9
leaq -0x48(%rbp), %r10
leaq -0x68(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x33f90
cmpl $0x0, %eax
jne 0xc6bc7
movl $0x0, -0xc(%rbp)
jmp 0xc6d85
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xc6bdd
movl $0x0, -0xc(%rbp)
jmp 0xc6d85
cmpq $0x0, 0x50(%rbp)
je 0xc6c22
movq -0x20(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdx
movl 0x40(%rbp), %eax
movb %al, %cl
movq 0x50(%rbp), %r8
movq 0x30(%rbp), %r9
movq -0x58(%rbp), %rax
movl %eax, %r10d
movq -0x60(%rbp), %rax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0xc6c61
movq -0x20(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdx
movl 0x40(%rbp), %eax
movb %al, %cl
movq 0x58(%rbp), %r8
movq 0x60(%rbp), %r9
movq 0x30(%rbp), %r11
movq -0x58(%rbp), %r10
movq -0x60(%rbp), %rax
movzbl %cl, %ecx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xa71f0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq 0x38(%rbp), %rax
movl %eax, %esi
movq -0x78(%rbp), %rdx
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movw %ax, %r8w
movq 0x48(%rbp), %r10
addq $0xff0, %r10            # imm = 0xFF0
movq 0x48(%rbp), %rax
addq $0xc08, %rax            # imm = 0xC08
leaq -0x84(%rbp), %r9
leaq -0x88(%rbp), %rbx
leaq -0x8c(%rbp), %r11
movzwl %r8w, %r8d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
callq 0x9e3d0
cltq
movq %rax, -0x70(%rbp)
cmpl $-0x1, -0x84(%rbp)
je 0xc6d7e
movl -0x84(%rbp), %eax
cmpl 0x28(%rbp), %eax
jae 0xc6d7e
movq -0x48(%rbp), %rcx
movq 0x68(%rbp), %rax
movq %rcx, (%rax)
movl -0x88(%rbp), %ecx
movq 0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq 0x78(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rcx
movq 0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq 0x88(%rbp), %rax
movq %rcx, (%rax)
movl -0x84(%rbp), %ecx
movq 0x90(%rbp), %rax
movl %ecx, (%rax)
movl -0x8c(%rbp), %ecx
movq 0x48(%rbp), %rax
movl %ecx, 0x7d70(%rax)
movq 0x48(%rbp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq 0x48(%rbp), %rsi
addq $0xc08, %rsi            # imm = 0xC08
movslq -0x8c(%rbp), %rdx
callq 0x2180
movl $0x1, -0xc(%rbp)
jmp 0xc6d85
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)