// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_backtrace(window_list*, overlap_region*, All_reads*, ul_idx_t const*, UC_Read*, Correct_dumy*, int, int)
inline uint32_t gen_backtrace(window_list *p, overlap_region *z, All_reads *rref, const ul_idx_t *uref, UC_Read* g_read, Correct_dumy* dumy,
int32_t y_strand, int32_t y_id)
{
    int64_t x_start, x_end, x_len, Window_Len, o_len; 
    int32_t threshold; long long y_start; 
    int real_y_start = 0, end_site, extra_begin, extra_end;
    char *x_string, *y_string; unsigned int error;
    ///there is no problem for x
    x_start = p->x_start; x_end = p->x_end; x_len = x_end - x_start + 1;
    threshold = p->error_threshold; Window_Len = x_len + (threshold << 1);


    ///y_start is the real y_start
    ///for the window with cigar, y_start has already reduced extra_begin
    y_start = p->y_start; extra_begin = p->extra_begin; extra_end = p->extra_end;
    o_len = Window_Len - extra_end - extra_begin;
    if(rref) {
        fill_subregion(dumy->overlap_region, y_start, o_len, y_strand, rref, y_id, extra_begin, extra_end);
    } else {
        fill_subregion_ul(dumy->overlap_region, y_start, o_len, y_strand, uref, y_id, extra_begin, extra_end);
    }
    x_string = g_read->seq + x_start; y_string = dumy->overlap_region;


    ///note!!! need notification
    end_site = Reserve_Banded_BPM_PATH(y_string, Window_Len, x_string, x_len, threshold, &error, &real_y_start,
    &(dumy->path_length), dumy->matrix_bit, dumy->path, p->error, p->y_end - y_start);
    // assert(error != (unsigned int)-1);
    if(error != (unsigned int)-1) {
        ///this condition is always wrong
        ///in best case, real_y_start = threshold, end_site = Window_Len - threshold - 1
        if (end_site == Window_Len - 1 || real_y_start == 0) {
            if(rref) {
                if(fix_boundary(x_string, x_len, threshold, y_start, real_y_start, end_site,
                extra_begin, extra_end, y_id, Window_Len, rref, dumy, y_strand, error,
                &y_start, &real_y_start, &end_site, &extra_begin, &extra_end, &error)) {
                    p->error = error; p->extra_begin = extra_begin; p->extra_end = extra_end;
                }
            } else {
                if(fix_ul_boundary(x_string, x_len, threshold, y_start, real_y_start, 
                end_site, extra_begin, extra_end, y_id, Window_Len, uref, dumy, 
                y_strand, error, &y_start, &real_y_start, &end_site, &extra_begin, 
                &extra_end, &error)) {
                    p->error = error; p->extra_begin = extra_begin; p->extra_end = extra_end;
                }
            }
        }

        generate_cigar(dumy->path, dumy->path_length, p, &(z->w_list), &real_y_start, &end_site, &error, x_string, x_len, y_string);    

        ///note!!! need notification
        real_y_start = y_start + real_y_start - extra_begin;
        p->y_start = real_y_start;  
        p->y_end = y_start + end_site - extra_begin;
        p->error = error;         
        return 1;                     
    }
    p->error = -1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %r15
movq %rdx, %r8
movq %rsi, 0x90(%rsp)
movl $0x0, 0x1c(%rsp)
movslq (%rdi), %rax
movslq 0x4(%rdi), %rbp
movq %rax, 0x28(%rsp)
subq %rax, %rbp
movswl 0x16(%rdi), %eax
movl %eax, 0x10(%rsp)
cltq
movq %rax, 0x88(%rsp)
leaq 0x1(%rbp,%rax,2), %r12
movslq 0x8(%rdi), %rbx
movq %rbx, 0x58(%rsp)
movswq 0x10(%rdi), %rsi
movl %esi, 0xc(%rsp)
movq %rdi, 0x50(%rsp)
movswq 0x12(%rdi), %rdx
movq %r12, 0x38(%rsp)
subq %rsi, %r12
subq %rdx, %r12
movq %rdx, 0x40(%rsp)
movl %edx, 0x14(%rsp)
movl 0xd8(%rsp), %eax
movslq %eax, %r10
movl 0xd0(%rsp), %edi
leaq 0x1(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq 0x50(%r9), %rax
movq %rax, 0x70(%rsp)
movq %rsi, 0x48(%rsp)
movq %r9, 0x30(%rsp)
leaq (%r9,%rsi), %r14
addq $0x50, %r14
testq %r8, %r8
movq %r10, 0x68(%rsp)
movq %rcx, 0x78(%rsp)
movq %r8, 0x80(%rsp)
je 0x9beb2
movzbl %dil, %ecx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r10, %r9
callq 0x32ef8
jmp 0x9bedf
movq (%rcx), %rax
leaq (%r10,%r10,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movzbl %dil, %ecx
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %r8
movq %r12, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
movq 0x70(%rsp), %r13
movq %r13, %rdi
movl $0x4e, %esi
movq 0x48(%rsp), %rdx
callq 0x20e0
addq %r12, %r14
movq %r14, %rdi
movl $0x4e, %esi
movq 0x40(%rsp), %rdx
callq 0x20e0
movq 0x28(%rsp), %rdx
addq (%r15), %rdx
movq 0x30(%rsp), %rcx
leaq 0x7d70(%rcx), %r15
leaq 0xff0(%rcx), %rax
leaq 0xa14(%rcx), %r14
movq 0x50(%rsp), %rcx
movswl 0x14(%rcx), %r10d
movl 0xc(%rcx), %r11d
movq %rbx, 0x60(%rsp)
subl %ebx, %r11d
leaq 0x1c(%rsp), %rbx
movzwl 0x10(%rsp), %r8d
leaq 0x8(%rsp), %r12
movq %r13, %rdi
movq 0x38(%rsp), %rsi
movq %rdx, %r13
movq 0x20(%rsp), %rcx
movq %r12, %r9
pushq %r11
pushq %r10
movq %r14, 0x38(%rsp)
pushq %r14
movq %r15, %r14
pushq %rax
pushq %r15
pushq %rbx
callq 0x85726
addq $0x30, %rsp
movl %eax, 0x18(%rsp)
movl (%r12), %r10d
cmpl $-0x1, %r10d
je 0x9c03e
movq %rbx, %r15
movq 0x88(%rsp), %rcx
addq %rcx, %rcx
movslq %eax, %r9
addq %rcx, %rbp
cmpq %r9, %rbp
sete %cl
movl 0x1c(%rsp), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
movq 0x50(%rsp), %rbx
jne 0x9c0d3
movslq %eax, %r8
movq 0x80(%rsp), %rbp
leaq 0x14(%rsp), %rax
leaq 0xc(%rsp), %r11
testq %rbp, %rbp
je 0x9c04e
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movl 0x10(%rsp), %edx
movq 0x60(%rsp), %rcx
leaq 0x8(%rsp), %r12
pushq %r12
pushq %rax
pushq %r11
leaq 0x30(%rsp), %rax
pushq %rax
pushq %r15
leaq 0x80(%rsp), %rax
pushq %rax
pushq %r10
movl 0x108(%rsp), %eax
pushq %rax
pushq 0x70(%rsp)
pushq %rbp
pushq 0x88(%rsp)
pushq 0xc0(%rsp)
pushq 0xa0(%rsp)
pushq 0xb0(%rsp)
callq 0x996a0
jmp 0x9c0b0
xorl %eax, %eax
movw $0xffff, %cx            # imm = 0xFFFF
movq 0x50(%rsp), %rbx
jmp 0x9c137
leaq 0x18(%rsp), %rbp
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movl 0x10(%rsp), %edx
movq 0x60(%rsp), %rcx
leaq 0x8(%rsp), %r12
pushq %r12
pushq %rax
pushq %r11
pushq %rbp
pushq %r15
leaq 0x80(%rsp), %rax
pushq %rax
pushq %r10
movl 0x108(%rsp), %eax
pushq %rax
pushq 0x70(%rsp)
pushq 0xc0(%rsp)
pushq 0x88(%rsp)
pushq 0xc0(%rsp)
pushq 0xa0(%rsp)
pushq 0xb0(%rsp)
callq 0x99943
addq $0x70, %rsp
testl %eax, %eax
je 0x9c0d3
movzwl 0x8(%rsp), %eax
movw %ax, 0x14(%rbx)
movzwl 0xc(%rsp), %eax
movw %ax, 0x10(%rbx)
movzwl 0x14(%rsp), %eax
movw %ax, 0x12(%rbx)
movl (%r14), %esi
movq 0x90(%rsp), %rcx
addq $0x48, %rcx
leaq 0x1c(%rsp), %r14
leaq 0x18(%rsp), %r15
movq 0x28(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %r8
movq %r15, %r9
pushq 0x70(%rsp)
pushq 0x28(%rsp)
pushq %r13
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x85cd2
addq $0x20, %rsp
movl 0x58(%rsp), %eax
movl 0xc(%rsp), %ecx
movl (%r14), %edx
addl %eax, %edx
subl %ecx, %edx
movl %edx, 0x8(%rbx)
subl %ecx, %eax
addl (%r15), %eax
movl %eax, 0xc(%rbx)
movzwl 0x8(%rsp), %ecx
movl $0x1, %eax
movw %cx, 0x14(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq