// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq 0xe0(%rsp), %r11
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rbx
movl 0xc0(%rsp), %ebp
movl $0x0, 0x4(%rsp)
subq 0xc8(%rsp), %rbx
leaq 0x1(%rbx), %r14
testq %rsi, %rsi
je 0x9b8c2
movl $0xf, %r10d
cmpq %r11, %r14
jge 0x9b872
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r10
cmpq $0x1f, %r10
movl $0x1f, %r11d
cmovlq %r10, %r11
testq %r10, %r10
movl $0x1, %r10d
cmovnel %r11d, %r10d
cmpq $0x4, %r14
cmovll %r11d, %r10d
leal (%r10,%r10), %r11d
testl %r10d, %r10d
movl $0x2, %r10d
cmovnel %r11d, %r10d
cmpl $0x4, %r14d
cmovll %r11d, %r10d
cmpl $0x20, %r10d
movl $0x1f, %r12d
cmovgel %r10d, %r12d
cmpl $0x12c, %r14d           # imm = 0x12C
cmovll %r10d, %r12d
movl $0x1f, %r10d
cmpl $0x1f, %r12d
cmovgel %r10d, %r12d
movslq %ebp, %r11
movq 0x18(%rsi), %r10
movq (%r10,%r11,8), %rbp
jmp 0x9b955
movl $0x1f, %r12d
movl $0x1f, %r10d
cmpq %r11, %r14
jge 0x9b904
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r10
cmpq $0x1f, %r10
movl $0x1f, %r11d
cmovlq %r10, %r11
testq %r10, %r10
movl $0x1, %r10d
cmovnel %r11d, %r10d
cmpq $0x4, %r14
cmovll %r11d, %r10d
testl %r10d, %r10d
movl $0x1, %r11d
cmovnel %r10d, %r11d
cmpl $0x4, %r14d
cmovll %r10d, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x195c57(%rip), %xmm0   # 0x231580
cvttsd2si %xmm0, %r10d
cmpl %r10d, %r11d
cmovlel %r10d, %r11d
cmpl $0x1f, %r11d
cmovll %r11d, %r12d
movslq %ebp, %r11
movq (%rdx), %r10
movq 0x10(%r10), %r15
leaq (%r11,%r11,4), %r10
movl (%r15,%r10,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
testq %rax, %rax
js 0x9bdbd
movq %rbp, %r10
subq %rax, %r10
jle 0x9bdbd
movq %rcx, 0x30(%rsp)
movq %r11, 0x40(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %r9, 0x48(%rsp)
leal (%r12,%r12), %edx
movslq %edx, %r13
leaq (%r14,%r13), %rdx
leaq (%r10,%r13), %rcx
addq $0x1f, %rcx
cmpq %rdx, %rcx
jl 0x9bdbd
movslq %r12d, %rcx
subq %rcx, %rax
subq %rax, %rbp
cmpq %rdx, %rbp
cmovgeq %rdx, %rbp
movq %rdx, 0x38(%rsp)
movq %rdx, %rsi
subq %rbp, %rsi
movl %eax, %edx
negl %edx
xorl %r15d, %r15d
testq %rax, %rax
movl $0x0, %r9d
cmovgq %rax, %r9
sarq $0x3f, %rax
andl %edx, %eax
subq %rax, %rbp
movl %eax, 0x1c(%rsp)
movq %rsi, 0x70(%rsp)
movl %esi, 0x18(%rsp)
movq %r9, 0x60(%rsp)
addq %rbp, %rcx
cmpq %r14, %rcx
jl 0x9bdbd
movq %rdi, 0x10(%rsp)
leaq 0x50(%r8), %rcx
movq %rcx, 0x28(%rsp)
cltq
movq %r8, 0x20(%rsp)
movq %rax, 0x58(%rsp)
leaq (%r8,%rax), %rsi
addq $0x50, %rsi
movq 0x80(%rsp), %r8
testq %r8, %r8
movq %r9, 0x68(%rsp)
movq %rsi, 0x50(%rsp)
je 0x9ba4e
movzbl 0x48(%rsp), %ecx
movq %rsi, %rdi
movq %r9, %rsi
movq %rbp, %rdx
movq 0x40(%rsp), %r9
callq 0x32ef8
jmp 0x9ba83
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movzbl 0x50(%rsp), %ecx
xorl %edi, %edi
movq %r9, %r8
movq %rbp, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
movq 0x28(%rsp), %rdi
movl $0x4e, %esi
movq 0x58(%rsp), %rdx
callq 0x20e0
movq 0x50(%rsp), %rdi
addq %rbp, %rdi
movslq 0x70(%rsp), %rdx
movl $0x4e, %esi
callq 0x20e0
movq 0x30(%rsp), %rax
movq (%rax), %rdx
addq 0xc8(%rsp), %rdx
cmpl $0x0, 0xe8(%rsp)
movq %rdx, 0x30(%rsp)
je 0x9bbfe
movq 0x20(%rsp), %rbp
leaq 0x7d70(%rbp), %rax
movq %rax, 0x50(%rsp)
leaq 0xff0(%rbp), %r10
leaq 0xa14(%rbp), %r11
movzwl %r12w, %r8d
leaq 0xc(%rsp), %r9
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %r14d, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
pushq %r11
pushq %r10
pushq 0x70(%rsp)
leaq 0x2c(%rsp), %rax
pushq %rax
callq 0x85726
movq %rbp, %rdi
addq $0x30, %rsp
movl %eax, 0x8(%rsp)
leaq 0xc(%rsp), %rcx
movq %rcx, %rbp
movl (%rcx), %r10d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl %ecx, %r10d
movq 0x10(%rsp), %r8
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %r11
je 0x9bdbd
movslq %eax, %r9
addq %r13, %rbx
cmpq %r9, %rbx
sete %cl
movl 0x4(%rsp), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x9bcb5
movslq %eax, %r8
movslq 0x70(%rsp), %rax
movq 0x80(%rsp), %r13
leaq 0x18(%rsp), %r11
leaq 0x1c(%rsp), %rbx
leaq 0x8(%rsp), %r15
testq %r13, %r13
je 0x9bc44
movq 0x30(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %edx
movq 0x68(%rsp), %rcx
pushq %rbp
pushq %r11
pushq %rbx
pushq %r15
leaq 0x24(%rsp), %r11
pushq %r11
leaq 0x88(%rsp), %r11
pushq %r11
pushq %r10
pushq 0x80(%rsp)
movq 0x60(%rsp), %rbx
pushq %rbx
pushq %r13
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq %rax
pushq 0xc0(%rsp)
callq 0x996a0
jmp 0x9bc99
movzwl %r12w, %r8d
leaq 0xc(%rsp), %rbx
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %r14d, %ecx
movq %rbx, %r9
callq 0x84e99
movl %eax, 0x8(%rsp)
cmpl $-0x1, (%rbx)
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %r11
jne 0x9bcb5
jmp 0x9bdbd
leaq 0x60(%rsp), %r13
movq 0x30(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %edx
movq 0x68(%rsp), %rcx
pushq %rbp
pushq %r11
pushq %rbx
pushq %r15
leaq 0x24(%rsp), %r11
pushq %r11
pushq %r13
pushq %r10
pushq 0x80(%rsp)
movq 0x60(%rsp), %rbx
pushq %rbx
pushq 0xc0(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq %rax
pushq 0xc0(%rsp)
callq 0x99943
movq %rbx, %rdi
addq $0x70, %rsp
movq 0x10(%rsp), %r8
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %r11
leaq 0x48(%r8), %rbx
movq 0x48(%r8), %rcx
cmpq 0x50(%r8), %rcx
jne 0x9bd0d
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%r8)
movq 0x10(%rsp), %rax
movq 0x58(%rax), %rdi
shlq $0x5, %rsi
callq 0x2370
movq 0xc8(%rsp), %r11
movq 0xd0(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
movq %rax, 0x58(%r8)
movq 0x48(%r8), %rcx
jmp 0x9bd11
movq 0x58(%r8), %rax
movq 0x28(%rsp), %r10
leaq 0x1(%rcx), %rdx
shlq $0x5, %rcx
leaq (%rax,%rcx), %r15
movq %rdx, (%rbx)
movl %r11d, (%rax,%rcx)
movl %esi, 0x4(%rax,%rcx)
cmpl $0x0, 0xe8(%rsp)
je 0x9bd72
movl 0x7d70(%rdi), %esi
addq $0xa14, %rdi            # imm = 0xA14
leaq 0xc(%rsp), %rax
leaq 0x4(%rsp), %r8
leaq 0x8(%rsp), %r9
movq %r15, %rdx
movq %rbx, %rcx
pushq %r10
pushq %r14
pushq 0x40(%rsp)
pushq %rax
callq 0x85cd2
movq 0x30(%rsp), %r8
addq $0x20, %rsp
jmp 0x9bd7a
movq $0x0, 0x18(%r15)
movl 0x60(%rsp), %eax
movl 0x4(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0x8(%r15)
addl 0x8(%rsp), %eax
movl %eax, 0xc(%r15)
movzwl 0xc(%rsp), %eax
movw %ax, 0x14(%r15)
movzwl 0x1c(%rsp), %eax
movw %ax, 0x10(%r15)
movzwl 0x18(%rsp), %eax
movw %ax, 0x12(%r15)
movw %r12w, 0x16(%r15)
addl %r14d, 0x28(%r8)
movl $0x1, %r15d
movl %r15d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq