// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movl $0x0, -0x9c(%rbp)
movq -0x38(%rbp), %rax
movslq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movslq 0x4(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movswl 0x16(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x78(%rbp), %rax
movl -0x8c(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movslq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movswl 0x10(%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x38(%rbp), %rax
movswl 0x12(%rax), %eax
movl %eax, -0xa8(%rbp)
movq -0x80(%rbp), %rax
movslq -0xa8(%rbp), %rcx
subq %rcx, %rax
movslq -0xa4(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xc652a
movq -0x60(%rbp), %rdi
addq $0x50, %rdi
movq -0x98(%rbp), %rsi
movq -0x88(%rbp), %rdx
movl 0x10(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %r8
movslq 0x18(%rbp), %r9
movl -0xa4(%rbp), %r10d
movl -0xa8(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
jmp 0xc656a
movq -0x60(%rbp), %rdi
addq $0x50, %rdi
movq -0x98(%rbp), %rsi
movq -0x88(%rbp), %rdx
movl 0x10(%rbp), %eax
movb %al, %cl
movq -0x50(%rbp), %r8
movslq 0x18(%rbp), %r9
movl -0xa4(%rbp), %r10d
movl -0xa8(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x321f0
movq -0x58(%rbp), %rax
movq (%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x60(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x80(%rbp), %rax
movl %eax, %esi
movq -0xb0(%rbp), %rdx
movq -0x78(%rbp), %rax
movl %eax, %ecx
movl -0x8c(%rbp), %eax
movw %ax, %r8w
movq -0x60(%rbp), %r14
addq $0x7d70, %r14           # imm = 0x7D70
movq -0x60(%rbp), %rbx
addq $0xff0, %rbx            # imm = 0xFF0
movq -0x60(%rbp), %r11
addq $0xa14, %r11            # imm = 0xA14
movq -0x38(%rbp), %rax
movswl 0x14(%rax), %r10d
movq -0x38(%rbp), %rax
movslq 0xc(%rax), %rax
subq -0x98(%rbp), %rax
leaq -0xbc(%rbp), %r9
leaq -0x9c(%rbp), %r15
movzwl %r8w, %r8d
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
callq 0x9e3d0
movl %eax, -0xa0(%rbp)
cmpl $-0x1, -0xbc(%rbp)
je 0xc69ec
movslq -0xa0(%rbp), %rax
movq -0x80(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0xc664f
cmpl $0x0, -0x9c(%rbp)
jne 0xc691d
cmpq $0x0, -0x48(%rbp)
je 0xc67bc
movq -0xb0(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x8c(%rbp), %edx
movq -0x98(%rbp), %rcx
movslq -0x9c(%rbp), %r8
movslq -0xa0(%rbp), %r9
movslq -0xa4(%rbp), %rax
movq %rax, -0xf8(%rbp)
movslq -0xa8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movslq 0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl 0x10(%rbp), %r13d
movl -0xbc(%rbp), %r12d
leaq -0x98(%rbp), %r15
leaq -0x9c(%rbp), %r14
leaq -0xa0(%rbp), %rbx
leaq -0xa4(%rbp), %r11
leaq -0xa8(%rbp), %r10
leaq -0xbc(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, (%rsp)
movq -0xf0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xe8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0xe0(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0xd8(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0xd0(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0xc8(%rbp), %rax
movl %r13d, 0x30(%rsp)
movl %r12d, 0x38(%rsp)
movq %r15, 0x40(%rsp)
movq %r14, 0x48(%rsp)
movq %rbx, 0x50(%rsp)
movq %r11, 0x58(%rsp)
movq %r10, 0x60(%rsp)
movq %rax, 0x68(%rsp)
callq 0xc35b0
cmpl $0x0, %eax
je 0xc67b7
movl -0xbc(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x14(%rax)
movl -0xa4(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x10(%rax)
movl -0xa8(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x12(%rax)
jmp 0xc691b
movq -0xb0(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x8c(%rbp), %edx
movq -0x98(%rbp), %rcx
movslq -0x9c(%rbp), %r8
movslq -0xa0(%rbp), %r9
movslq -0xa4(%rbp), %rax
movq %rax, -0x130(%rbp)
movslq -0xa8(%rbp), %rax
movq %rax, -0x128(%rbp)
movslq 0x18(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x108(%rbp)
movl 0x10(%rbp), %r13d
movl -0xbc(%rbp), %r12d
leaq -0x98(%rbp), %r15
leaq -0x9c(%rbp), %r14
leaq -0xa0(%rbp), %rbx
leaq -0xa4(%rbp), %r11
leaq -0xa8(%rbp), %r10
leaq -0xbc(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x130(%rbp), %rax
movq %rax, (%rsp)
movq -0x128(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x120(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x118(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x110(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x108(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x100(%rbp), %rax
movl %r13d, 0x30(%rsp)
movl %r12d, 0x38(%rsp)
movq %r15, 0x40(%rsp)
movq %r14, 0x48(%rsp)
movq %rbx, 0x50(%rsp)
movq %r11, 0x58(%rsp)
movq %r10, 0x60(%rsp)
movq %rax, 0x68(%rsp)
callq 0xc3a10
cmpl $0x0, %eax
je 0xc6919
movl -0xbc(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x14(%rax)
movl -0xa4(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x10(%rax)
movl -0xa8(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x12(%rax)
jmp 0xc691b
jmp 0xc691d
movq -0x60(%rbp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq -0x60(%rbp), %rax
movl 0x7d70(%rax), %esi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
addq $0x48, %rcx
movq -0xb0(%rbp), %r11
movq -0x78(%rbp), %rax
movl %eax, %r10d
movq -0xb8(%rbp), %rax
leaq -0x9c(%rbp), %r8
leaq -0xa0(%rbp), %r9
leaq -0xbc(%rbp), %rbx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x9f0f0
movq -0x98(%rbp), %rax
movslq -0x9c(%rbp), %rcx
addq %rcx, %rax
movslq -0xa4(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x98(%rbp), %rax
movslq -0xa0(%rbp), %rcx
addq %rcx, %rax
movslq -0xa4(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0xbc(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x14(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0xc69fd
movq -0x38(%rbp), %rax
movw $0xffff, 0x14(%rax)     # imm = 0xFFFF
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)