// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %r8, 0x80(%rsp)
movq %rdx, %r11
movq %rsi, 0x78(%rsp)
movl $0x0, 0x10(%rsp)
movslq (%rdi), %rax
movslq 0x4(%rdi), %rbp
movq %rax, 0x30(%rsp)
subq %rax, %rbp
movswl 0x16(%rdi), %eax
movl %eax, 0x18(%rsp)
cltq
movq %rax, 0x70(%rsp)
leaq 0x1(%rbp,%rax,2), %rdx
movslq 0x8(%rdi), %r8
movq %r8, 0x20(%rsp)
movswq 0x10(%rdi), %r15
movl %r15d, 0xc(%rsp)
movq %rdi, 0x48(%rsp)
movswl 0x12(%rdi), %eax
movslq %eax, %r12
movq %rdx, %r13
subq %r15, %r13
subq %r12, %r13
movl %r12d, 0x14(%rsp)
movl 0xc8(%rsp), %eax
movslq %eax, %r10
movl 0xc0(%rsp), %esi
leaq 0x1(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%r9), %rax
movq %rax, 0x58(%rsp)
movq %r9, 0x40(%rsp)
leaq (%r9,%r15), %r14
addq $0x50, %r14
testq %r11, %r11
movq %rdx, 0x38(%rsp)
movq %r10, 0x50(%rsp)
movq %rcx, 0x60(%rsp)
movq %r11, 0x68(%rsp)
je 0x9b72e
movzbl %sil, %ecx
movq %r14, %rdi
movq %r8, %rsi
movq %r13, %rdx
movq %r11, %r8
movq %r10, %r9
callq 0x337f7
jmp 0x9b758
movq (%rcx), %rax
leaq (%r10,%r10,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movzbl %sil, %ecx
xorl %edi, %edi
movq %r14, %rsi
movq %r13, %r9
pushq $0x0
callq 0x36b0d
addq $0x10, %rsp
movq 0x58(%rsp), %rbx
movq %rbx, %rdi
movl $0x4e, %esi
movq %r15, %rdx
callq 0x20e0
addq %r13, %r14
movq %r14, %rdi
movl $0x4e, %esi
movq %r12, %rdx
callq 0x20e0
movq 0x30(%rsp), %rdx
movq 0x80(%rsp), %rax
addq (%rax), %rdx
movq 0x40(%rsp), %rcx
leaq 0x7d70(%rcx), %r12
leaq 0xff0(%rcx), %rax
leaq 0xa14(%rcx), %r14
movq 0x48(%rsp), %r13
movswl 0x14(%r13), %r10d
movl 0xc(%r13), %r11d
subl 0x20(%rsp), %r11d
movzwl 0x18(%rsp), %r8d
leaq 0x8(%rsp), %r15
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movq %rdx, %rbx
movq 0x28(%rsp), %rcx
movq %r15, %r9
pushq %r11
pushq %r10
movq %r14, 0x40(%rsp)
pushq %r14
movq %r12, %r14
pushq %rax
pushq %r12
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x8607d
addq $0x30, %rsp
movl %eax, 0x1c(%rsp)
movl (%r15), %r11d
cmpl $-0x1, %r11d
je 0x9b8b5
movq 0x70(%rsp), %rcx
addq %rcx, %rcx
movslq %eax, %r9
addq %rcx, %rbp
cmpq %r9, %rbp
sete %cl
movl 0x10(%rsp), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
movq %rbx, %r12
jne 0x9b944
movq %r12, %rdi
movslq %eax, %r8
movq 0x20(%rsp), %rcx
movslq 0xc(%rsp), %rax
movslq 0x14(%rsp), %r10
movq 0x68(%rsp), %rbp
leaq 0x14(%rsp), %r12
leaq 0xc(%rsp), %r13
testq %rbp, %rbp
je 0x9b8c0
leaq 0x1c(%rsp), %rbx
movq 0x28(%rsp), %rsi
movl 0x18(%rsp), %edx
leaq 0x8(%rsp), %r15
pushq %r15
pushq %r12
movq %rdi, %r12
pushq %r13
pushq %rbx
leaq 0x30(%rsp), %rbx
pushq %rbx
leaq 0x48(%rsp), %rbx
pushq %rbx
pushq %r11
movl 0xf8(%rsp), %r11d
pushq %r11
pushq 0x80(%rsp)
pushq %rbp
pushq 0x88(%rsp)
pushq 0xa8(%rsp)
pushq %r10
pushq %rax
callq 0x98b36
jmp 0x9b919
xorl %eax, %eax
movw $0xffff, %cx            # imm = 0xFFFF
jmp 0x9b9aa
leaq 0x1c(%rsp), %rbp
movq 0x28(%rsp), %rsi
movl 0x18(%rsp), %edx
leaq 0x8(%rsp), %r15
pushq %r15
pushq %r12
movq %rdi, %r12
pushq %r13
pushq %rbp
leaq 0x30(%rsp), %rbx
pushq %rbx
leaq 0x48(%rsp), %rbx
pushq %rbx
pushq %r11
movl 0xf8(%rsp), %r11d
pushq %r11
pushq 0x80(%rsp)
pushq 0xa8(%rsp)
pushq 0x88(%rsp)
pushq 0xa8(%rsp)
pushq %r10
pushq %rax
callq 0x98f8f
addq $0x70, %rsp
testl %eax, %eax
movq 0x48(%rsp), %r13
je 0x9b944
movzwl 0x8(%rsp), %eax
movw %ax, 0x14(%r13)
movzwl 0xc(%rsp), %eax
movw %ax, 0x10(%r13)
movzwl 0x14(%rsp), %eax
movw %ax, 0x12(%r13)
movl (%r14), %esi
movq 0x78(%rsp), %rcx
addq $0x48, %rcx
leaq 0x10(%rsp), %r14
leaq 0x1c(%rsp), %r15
movq 0x30(%rsp), %rdi
movq %r13, %rdx
movq %r14, %r8
movq %r15, %r9
pushq 0x58(%rsp)
pushq 0x30(%rsp)
pushq %r12
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x8663c
addq $0x20, %rsp
movl 0x20(%rsp), %eax
movl 0xc(%rsp), %ecx
movl (%r14), %edx
addl %eax, %edx
subl %ecx, %edx
movl %edx, (%r14)
movl %edx, 0x8(%r13)
subl %ecx, %eax
addl (%r15), %eax
movl %eax, 0xc(%r13)
movzwl 0x8(%rsp), %ecx
movl $0x1, %eax
movw %cx, 0x14(%r13)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq