// File: /workspace/github_cpp_makefile_star2_O2/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, 0x30(%rsp)
movq %rcx, %r8
movq %rdx, %r11
andl $0x0, 0xc(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdi, %rbx
movslq (%rdi), %rax
movslq 0x4(%rdi), %r14
movq %rax, 0x20(%rsp)
subq %rax, %r14
movswl 0x16(%rdi), %eax
movl %eax, 0x14(%rsp)
cltq
movq %rax, 0x78(%rsp)
leaq 0x1(%r14,%rax,2), %rdx
movslq 0x8(%rdi), %rbp
movq %rbp, 0x40(%rsp)
movswq 0x10(%rdi), %r12
movl %r12d, 0x10(%rsp)
movswq 0x12(%rdi), %r13
movq %r12, %rax
addq %r13, %rax
movq %rdx, 0x90(%rsp)
subq %rax, %rdx
movl %r13d, 0x18(%rsp)
movl 0xd8(%rsp), %eax
movslq %eax, %r10
movl 0xd0(%rsp), %ecx
leaq 0x1(%r14), %rax
movq %rax, 0x28(%rsp)
movq %r9, 0x38(%rsp)
leaq 0x50(%r9), %r15
testq %r11, %r11
movq %r10, 0x50(%rsp)
movq %r8, 0x58(%rsp)
movq %r11, 0x70(%rsp)
movq %r12, 0x68(%rsp)
movq %r13, 0x60(%rsp)
movzbl %cl, %ecx
movq %r15, %rdi
movq %rbp, %rsi
je 0x653f0
movq %r11, %r8
movq %r10, %r9
pushq %r13
pushq %r12
callq 0x1b475
jmp 0x653fc
movq %r10, %r9
pushq %r13
pushq %r12
callq 0x1b4ca
popq %rax
popq %rcx
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rax
addq (%rax), %rdx
movq 0x38(%rsp), %rcx
leaq 0x7d70(%rcx), %r13
leaq 0xff0(%rcx), %rax
leaq 0xa14(%rcx), %r12
movswl 0x14(%rbx), %r10d
movl 0xc(%rbx), %r11d
movq %rbp, 0x48(%rsp)
subl %ebp, %r11d
movzwl 0x14(%rsp), %r8d
leaq 0x8(%rsp), %rbp
movq %r15, 0x30(%rsp)
movq %r15, %rdi
movq 0x90(%rsp), %r15
movl %r15d, %esi
movq %rdx, 0x20(%rsp)
movq 0x28(%rsp), %rcx
movq %rbp, %r9
pushq %r11
pushq %r10
movq %r12, 0x90(%rsp)
pushq %r12
pushq %rax
movq %r13, %r12
pushq %r13
leaq 0x34(%rsp), %rax
pushq %rax
callq 0x51ff9
addq $0x30, %rsp
movl %eax, 0x1c(%rsp)
movl (%rbp), %r11d
cmpl $-0x1, %r11d
je 0x65536
movq 0x78(%rsp), %rcx
addq %rcx, %rcx
movslq %eax, %r9
addq %rcx, %r14
cmpq %r9, %r14
sete %cl
movl 0xc(%rsp), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x655c3
movslq %eax, %r8
movslq 0x68(%rsp), %rax
movslq 0x60(%rsp), %r10
movq 0x70(%rsp), %rbp
leaq 0x18(%rsp), %r14
testq %rbp, %rbp
je 0x65541
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x14(%rsp), %edx
movq 0x48(%rsp), %rcx
leaq 0x8(%rsp), %r13
pushq %r13
pushq %r14
leaq 0x20(%rsp), %r14
pushq %r14
leaq 0x34(%rsp), %r14
pushq %r14
leaq 0x2c(%rsp), %r14
pushq %r14
leaq 0x68(%rsp), %r14
pushq %r14
pushq %r11
movl 0x108(%rsp), %r11d
pushq %r11
pushq 0x78(%rsp)
pushq %rbp
pushq %r15
pushq 0xa8(%rsp)
pushq %r10
pushq %rax
callq 0x6380f
jmp 0x655a0
xorl %eax, %eax
movw $0xffff, %cx            # imm = 0xFFFF
jmp 0x6562c
leaq 0x10(%rsp), %r13
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x14(%rsp), %edx
movq 0x48(%rsp), %rcx
leaq 0x8(%rsp), %rbp
pushq %rbp
pushq %r14
pushq %r13
leaq 0x34(%rsp), %r14
pushq %r14
leaq 0x2c(%rsp), %r14
pushq %r14
leaq 0x68(%rsp), %r14
pushq %r14
pushq %r11
movl 0x108(%rsp), %r11d
pushq %r11
pushq 0x78(%rsp)
pushq 0xa0(%rsp)
pushq %r15
pushq 0xa8(%rsp)
pushq %r10
pushq %rax
callq 0x63a35
addq $0x70, %rsp
testl %eax, %eax
je 0x655c3
movzwl 0x8(%rsp), %eax
movw %ax, 0x14(%rbx)
movzwl 0x10(%rsp), %eax
movw %ax, 0x10(%rbx)
movzwl 0x18(%rsp), %eax
movw %ax, 0x12(%rbx)
movl (%r12), %esi
movq 0x88(%rsp), %rcx
addq $0x48, %rcx
leaq 0xc(%rsp), %r15
leaq 0x1c(%rsp), %r12
movq 0x80(%rsp), %rdi
movq %rbx, %rdx
movq %r15, %r8
movq %r12, %r9
pushq 0x30(%rsp)
pushq 0x30(%rsp)
pushq 0x30(%rsp)
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x52542
addq $0x20, %rsp
movl 0x40(%rsp), %eax
movl 0x10(%rsp), %ecx
movl (%r15), %edx
addl %eax, %edx
subl %ecx, %edx
movl %edx, 0x8(%rbx)
subl %ecx, %eax
addl (%r12), %eax
movl %eax, 0xc(%rbx)
movzwl 0x8(%rsp), %ecx
pushq $0x1
popq %rax
movw %cx, 0x14(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq