// File: chhylp123[P]hifiasm/Correct.cpp
// Function: aln_wlst(overlap_region*, All_reads*, ul_idx_t const*, UC_Read*, Correct_dumy*, int, int, long, long, long long, long, double, int)
inline uint32_t aln_wlst(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, int64_t x_end, long long y_start, int64_t block_s, double e_rate, int32_t is_cigar)
{
    int64_t x_len, Window_Len; window_list *p = NULL; long long o_len;
    int32_t threshold; int real_y_start = 0, end_site, extra_begin, extra_end;
    char *x_string, *y_string; unsigned int error;
    x_len = x_end + 1 - x_start;
    ///there are two potiential reasons for unmatched window:
    ///1. this window has a large number of differences
    ///2. DP does not start from the right offset
    if(rref) {
        threshold = double_error_threshold(get_init_err_thres(x_len, e_rate, block_s, THRESHOLD), x_len);
    } else {
        threshold = double_ul_error_threshold(get_init_err_thres(x_len, e_rate, block_s, THRESHOLD_MAX_SIZE), x_len);
    }
    Window_Len = x_len + (threshold << 1);
    ///y_start might be less than 0
    if(!determine_overlap_region(threshold, y_start, y_id, Window_Len, (rref?(Get_READ_LENGTH((*rref), y_id)):(uref->ug->u.a[y_id].len)), 
    &extra_begin, &extra_end, &y_start, &o_len)) {
        return 0;
    }

    if(o_len + threshold < x_len) return 0;
    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;

    if(is_cigar) {
        ///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, -1, -1);
    } else {
        ///note!!! need notification
        end_site = Reserve_Banded_BPM(y_string, Window_Len, x_string, x_len, threshold, &error);    
    }
    if(error!=(unsigned int)-1) {
        if(is_cigar) {
            ///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) {
                    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);
                } else {
                    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);
                }
            }
        }

        kv_pushp(window_list, z->w_list, &p);
        p->x_start = x_start; p->x_end = x_end; ///must set x_start/x_end here
        if(is_cigar) {
            generate_cigar(dumy->path, dumy->path_length, p, &(z->w_list), &real_y_start, &end_site, &error, x_string, x_len, y_string);  
        } else {
            p->cidx = p->clen = 0;
        }
        p->y_start = y_start + real_y_start;///difference
        p->y_end = y_start + end_site;
        p->error = error;
        p->extra_begin = extra_begin;
        p->extra_end = extra_end;
        p->error_threshold = threshold;
        z->align_length += x_len; 
        
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movl %r9d, -0x5c(%rbp)
movsd %xmm0, -0x68(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x90(%rbp)
movq 0x20(%rbp), %rax
addq $0x1, %rax
subq 0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xc5cfc
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movq 0x30(%rbp), %rsi
movl $0xf, %edx
callq 0x9e1c0
movl %eax, %edi
movq -0x70(%rbp), %rax
movl %eax, %esi
callq 0x9e370
movl %eax, -0x8c(%rbp)
jmp 0xc5d26
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movq 0x30(%rbp), %rsi
movl $0x1f, %edx
callq 0x9e1c0
movl %eax, %edi
movq -0x70(%rbp), %rax
movl %eax, %esi
callq 0x9f400
movl %eax, -0x8c(%rbp)
movq -0x70(%rbp), %rax
movl -0x8c(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq 0x28(%rbp), %rax
movq %rax, -0xd0(%rbp)
movslq 0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xc5d89
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
jmp 0xc5daf
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x10(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0xe0(%rbp)
movq -0xc0(%rbp), %rcx
movq -0xc8(%rbp), %rdx
movq -0xd0(%rbp), %rsi
movl -0xd4(%rbp), %edi
movq -0xe0(%rbp), %r8
leaq -0x98(%rbp), %r9
leaq -0x9c(%rbp), %r11
leaq 0x28(%rbp), %r10
leaq -0x88(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x32290
cmpl $0x0, %eax
jne 0xc5e0e
movl $0x0, -0x2c(%rbp)
jmp 0xc63ec
movq -0x88(%rbp), %rax
movslq -0x8c(%rbp), %rcx
addq %rcx, %rax
cmpq -0x70(%rbp), %rax
jge 0xc5e31
movl $0x0, -0x2c(%rbp)
jmp 0xc63ec
cmpq $0x0, -0x40(%rbp)
je 0xc5e77
movq -0x58(%rbp), %rdi
addq $0x50, %rdi
movq 0x28(%rbp), %rsi
movq -0x88(%rbp), %rdx
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %r8
movslq 0x10(%rbp), %r9
movl -0x98(%rbp), %r10d
movl -0x9c(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
jmp 0xc5eb4
movq -0x58(%rbp), %rdi
addq $0x50, %rdi
movq 0x28(%rbp), %rsi
movq -0x88(%rbp), %rdx
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %r8
movslq 0x10(%rbp), %r9
movl -0x98(%rbp), %r10d
movl -0x9c(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x321f0
movq -0x50(%rbp), %rax
movq (%rax), %rax
addq 0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x58(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb0(%rbp)
cmpl $0x0, 0x38(%rbp)
je 0xc5f65
movq -0xb0(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %esi
movq -0xa8(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movl -0x8c(%rbp), %eax
movw %ax, %r8w
movq -0x58(%rbp), %r11
addq $0x7d70, %r11           # imm = 0x7D70
movq -0x58(%rbp), %r10
addq $0xff0, %r10            # imm = 0xFF0
movq -0x58(%rbp), %rax
addq $0xa14, %rax            # imm = 0xA14
leaq -0xb4(%rbp), %r9
leaq -0x90(%rbp), %rbx
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
movl %eax, -0x94(%rbp)
jmp 0xc5f9b
movq -0xb0(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %esi
movq -0xa8(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movl -0x8c(%rbp), %eax
leaq -0xb4(%rbp), %r9
movzwl %ax, %r8d
callq 0x9c2b0
movl %eax, -0x94(%rbp)
cmpl $-0x1, -0xb4(%rbp)
je 0xc63e5
cmpl $0x0, 0x38(%rbp)
je 0xc6225
movslq -0x94(%rbp), %rax
movq -0x78(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0xc5fd3
cmpl $0x0, -0x90(%rbp)
jne 0xc6223
cmpq $0x0, -0x40(%rbp)
je 0xc6102
movq -0xa8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x8c(%rbp), %edx
movq 0x28(%rbp), %rcx
movslq -0x90(%rbp), %r8
movslq -0x94(%rbp), %r9
movslq -0x98(%rbp), %rax
movq %rax, -0x118(%rbp)
movslq -0x9c(%rbp), %rax
movq %rax, -0x110(%rbp)
movslq 0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl -0x5c(%rbp), %r13d
movl -0xb4(%rbp), %r12d
leaq 0x28(%rbp), %r15
leaq -0x90(%rbp), %r14
leaq -0x94(%rbp), %rbx
leaq -0x98(%rbp), %r11
leaq -0x9c(%rbp), %r10
leaq -0xb4(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x118(%rbp), %rax
movq %rax, (%rsp)
movq -0x110(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x108(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x100(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0xf8(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0xf0(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0xe8(%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
jmp 0xc6221
movq -0xa8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x8c(%rbp), %edx
movq 0x28(%rbp), %rcx
movslq -0x90(%rbp), %r8
movslq -0x94(%rbp), %r9
movslq -0x98(%rbp), %rax
movq %rax, -0x150(%rbp)
movslq -0x9c(%rbp), %rax
movq %rax, -0x148(%rbp)
movslq 0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0x5c(%rbp), %r13d
movl -0xb4(%rbp), %r12d
leaq 0x28(%rbp), %r15
leaq -0x90(%rbp), %r14
leaq -0x94(%rbp), %rbx
leaq -0x98(%rbp), %r11
leaq -0x9c(%rbp), %r10
leaq -0xb4(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x150(%rbp), %rax
movq %rax, (%rsp)
movq -0x148(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x140(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x138(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x130(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x128(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x120(%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
jmp 0xc6223
jmp 0xc6225
jmp 0xc6227
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0xc6299
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0xc6258
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0x158(%rbp)
jmp 0xc6266
movl $0x2, %eax
movq %rax, -0x158(%rbp)
jmp 0xc6266
movq -0x158(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rdx
movq 0x48(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rdx)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq 0x18(%rbp), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, (%rax)
movq 0x20(%rbp), %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x0, 0x38(%rbp)
je 0xc6343
movq -0x58(%rbp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq -0x58(%rbp), %rax
movl 0x7d70(%rax), %esi
movq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
addq $0x48, %rcx
movq -0xa8(%rbp), %r11
movq -0x70(%rbp), %rax
movl %eax, %r10d
movq -0xb0(%rbp), %rax
leaq -0x90(%rbp), %r8
leaq -0x94(%rbp), %r9
leaq -0xb4(%rbp), %rbx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x9f0f0
jmp 0xc6359
movq -0x80(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x80(%rbp), %rax
movl $0x0, 0x18(%rax)
movq 0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x28(%rbp), %rax
movslq -0x94(%rbp), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0xb4(%rbp), %eax
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, 0x14(%rax)
movl -0x98(%rbp), %eax
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, 0x10(%rax)
movl -0x9c(%rbp), %eax
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, 0x12(%rax)
movl -0x8c(%rbp), %eax
movw %ax, %cx
movq -0x80(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x70(%rbp), %rdx
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x28(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0xc63ec
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)