// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: set_herror_win(overlap_region_alloc*, Correct_dumy*, kvec_t_u64_warp*, double, long, long)
void set_herror_win(overlap_region_alloc* ovlp, Correct_dumy* du, kvec_t_u64_warp* v_idx, double max_ov_diff_ec, int64_t rLen, int64_t blockLen)
{
    Window_Pool w_inf; int32_t flag = 0; uint64_t cID, mm, fc, fw, idx_n, idx_i;
    init_Window_Pool(&w_inf, rLen, blockLen, (int)(1.0/max_ov_diff_ec));
    long long window_start, window_end; int64_t i, k, mLen, w_list_id, ws, we; 

    idx_n = get_num_wins(0, rLen, blockLen); idx_i = 0;
    kv_resize(uint64_t, v_idx->a, idx_n); v_idx->a.n = idx_n; 

    while(get_Window(&w_inf, &window_start, &window_end) && flag != -2) {
        du->length = du->lengthNT = 0;
        flag = get_interval(window_start, window_end, ovlp, du, w_inf.window_length);
        switch (flag) {
            case 1:    ///no match here
                break;
            case 0:    ///no match here
                break;
            case -2: ///if flag == -2, loop would be terminated
                break;
        }

        v_idx->a.a[idx_i++] = ((uint64_t)(v_idx->a.n))<<32;
        for (i = 0; i < (int64_t)du->length; i++) {
            cID = (uint32_t)du->overlapID[i];
            if(ovlp->list[cID].is_match!=3 && ovlp->list[cID].is_match!=4) continue;
            w_list_id = get_adjust_winid(&(ovlp->list[cID]), window_start, w_inf.window_length);
            if(w_list_id >= 0) break;///a matched window
        }
        if(i < (int64_t)du->length) continue;///if there is a matched window

        for (i = 0, mm = 0; i < (int64_t)du->length; i++) {///all windows are unmatched
            cID = (uint32_t)du->overlapID[i];
            if(ovlp->list[cID].is_match!=3 && ovlp->list[cID].is_match!=4) continue;
            ovlp->list[cID].is_match = 4; 
            ovlp->list[cID].align_length += window_end + 1 - window_start;
            mm++;
        }
        if(mm > 0) {
            kv_push(uint64_t, v_idx->a, (((uint64_t)window_start)<<32)|((uint64_t)window_end));
            v_idx->a.a[idx_i-1]++;
        }


        ///shorter than blockLen
        for (i = du->size-du->lengthNT, mLen = du->size-du->lengthNT, fc = 0; i < (int64_t)du->size; i++) {
            cID = (uint32_t)du->overlapID[i];
            if(ovlp->list[cID].is_match!=3 && ovlp->list[cID].is_match!=4) continue;
            get_win_se_by_normalize_xs(&(ovlp->list[cID]), window_start, blockLen, &ws, &we);
            w_list_id = get_adjust_winid(&(ovlp->list[cID]), ws, blockLen);
            if (w_list_id >= 0) {///matched
                cID = w_list_id; cID <<= 32; cID += (uint32_t)du->overlapID[i]; du->overlapID[i] = cID;
                if(mLen != i) {
                    mm = du->overlapID[i]; du->overlapID[i] = du->overlapID[mLen]; du->overlapID[mLen] = mm;
                }
                mLen++;
            } else {///unmatched
                cID = (uint32_t)-1; cID <<= 32; cID += (uint32_t)du->overlapID[i]; du->overlapID[i] = cID;
                fc++;
            }
        }
        // if(mLen == (int64_t)du->size) continue;///if all windows shorter than blockLen are matched
        if(fc == 0) continue;///no unmatched windows that are shorter than blockLen
        for (i = mLen; i < (int64_t)du->size; i++){///check the remaining unmatched windows that are shorter than blockLen
            cID = (uint32_t)du->overlapID[i];
            if(ovlp->list[cID].is_match!=3 && ovlp->list[cID].is_match!=4) continue;
            assert((du->overlapID[i]>>32)==(uint32_t)-1);
            get_win_se_by_normalize_xs(&(ovlp->list[cID]), window_start, blockLen, &ws, &we);
            for (k = du->size-du->lengthNT; k < mLen; k++) {///all matched windows
                fc = (uint32_t)du->overlapID[k]; fw = du->overlapID[k]>>32;
                assert(fw!=(uint32_t)-1); assert(ovlp->list[fc].is_match == 3 || ovlp->list[fc].is_match == 4);
                // if (ovlp->list[fc].w_list[fw].y_end == -1 || (ovlp->list[fc].is_match!=3 && ovlp->list[fc].is_match!=4)) fprintf(stderr, "ERROR\n");        
                ///if there is one matched window can cover the unmatched window
                if(ovlp->list[fc].w_list.a[fw].x_start<=ws && ovlp->list[fc].w_list.a[fw].x_end>=we) { 
                        break;
                }
            }

            if(k >= mLen) {///no matched window can cover the unmatched window
                ovlp->list[cID].is_match = 4; 
                ovlp->list[cID].align_length += we + 1 - ws;
                kv_push(uint64_t, v_idx->a, (((uint64_t)ws)<<32)|((uint64_t)we));
                v_idx->a.a[idx_i-1]++;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, %r11
movq %rcx, %rax
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
cmpq %r8, %rcx
movq %r8, %r15
cmovlq %rcx, %r15
movq %rdi, %rbp
movq %rcx, 0x48(%rsp)
cqto
idivq %r8
xorl %r14d, %r14d
testq %rdx, %rdx
setg %r14b
addq %rax, %r14
cmpq %r14, 0x8(%rbx)
movq %r8, 0x20(%rsp)
jae 0x4adbe
leaq -0x1(%r14), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x20(%rsp), %r11
movq %rax, 0x10(%rbx)
decq %r15
movq 0x48(%rsp), %rax
decq %rax
movq %rax, 0x80(%rsp)
movq %r14, (%rbx)
movq 0x8(%rsp), %r14
leaq 0x30(%r14), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x68(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbp, 0x50(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x80(%rsp), %rax
cmpq %rax, %r15
jne 0x4ae54
cmpq $0x0, 0x48(%rsp)
movq 0x60(%rsp), %r12
je 0x4b37d
cmpl $0x1, 0x34(%rsp)
movl $0x1, 0x34(%rsp)
jne 0x4ae59
jmp 0x4b37d
movq 0x60(%rsp), %r12
leaq (%r15,%r11), %rcx
cmpq 0x48(%rsp), %rcx
cmovgeq %rax, %rcx
cmpl $-0x2, 0x1c(%rsp)
je 0x4b37d
movq %rcx, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
cmpq $0x0, 0x10(%rsp)
je 0x4ae8c
movq 0x48(%r14), %rax
jmp 0x4ae96
movq $0x0, 0x48(%r14)
xorl %eax, %eax
movq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jae 0x4aecd
movq (%rbp), %rdx
imulq $0xa8, %rax, %rsi
movl 0x4(%rdx,%rsi), %ecx
cmpq %rcx, %r15
jge 0x4aee3
movq $0x0, 0x48(%r14)
movaps %xmm0, (%r12)
movl $0x0, 0x1c(%rsp)
jmp 0x4af87
movq %rcx, 0x48(%r14)
movaps %xmm0, (%r12)
movl $0xfffffffe, 0x1c(%rsp) # imm = 0xFFFFFFFE
jmp 0x4af87
movq %r15, %rcx
subq 0x10(%rsp), %rcx
incq %rcx
movaps %xmm0, (%r12)
addq %rsi, %rdx
addq $0x8, %rdx
xorl %esi, %esi
movl -0x4(%rdx), %edi
movl (%rdx), %r8d
cmpq %r15, %r8
cmovaeq %r15, %r8
movq 0x10(%rsp), %r9
cmpq %r9, %rdi
cmovgq %rdi, %r9
subq %r9, %r8
js 0x4af61
cmpq %r11, %rcx
jne 0x4af39
incq %r8
cmpq %r11, %r8
jne 0x4af39
movq 0x28(%r14), %r8
movq 0x30(%r14), %r9
movq %rax, (%r8,%r9,8)
incq 0x30(%r14)
jmp 0x4af53
movq 0x28(%r14), %r8
movq 0x38(%r14), %r9
incq %r9
movq %r9, 0x38(%r14)
movq 0x40(%r14), %r10
subq %r9, %r10
movq %rax, (%r8,%r10,8)
testq %rsi, %rsi
jne 0x4af5c
movq %rax, 0x48(%r14)
movl $0x1, %esi
cmpq %rdi, %r15
jl 0x4af76
incq %rax
addq $0xa8, %rdx
cmpq 0x10(%rbp), %rax
jb 0x4aefc
movq 0x30(%r14), %rax
xorl %ecx, %ecx
addq 0x38(%r14), %rax
setne %cl
movl %ecx, 0x1c(%rsp)
movq 0x10(%rsp), %rax
addq %r11, %rax
movq %rax, 0x70(%rsp)
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
shlq $0x20, %rax
movq 0x58(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x68(%rsp)
movq %rsi, 0x28(%rsp)
movq %rax, (%rsi,%rcx,8)
movq (%r12), %r14
testq %r14, %r14
jle 0x4b0ef
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rbx
movq (%rbp), %r12
xorl %r13d, %r13d
movl (%rbx,%r13,8), %eax
imulq $0xa8, %rax, %rdi
movb 0x2c(%r12,%rdi), %al
addb $-0x3, %al
cmpb $0x1, %al
ja 0x4b007
addq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r11, %rdx
callq 0x4ac93
movq 0x20(%rsp), %r11
testq %rax, %rax
jns 0x4b0d6
incq %r13
cmpq %r13, %r14
jne 0x4afd3
testq %r14, %r14
jle 0x4b0ea
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rbp), %rcx
movl %r15d, %edx
subl 0x10(%rsp), %edx
incl %edx
xorl %edi, %edi
xorl %esi, %esi
movq 0x38(%rsp), %rbx
movl (%rax,%rdi,8), %r8d
imulq $0xa8, %r8, %r8
movb 0x2c(%rcx,%r8), %r9b
addb $-0x3, %r9b
cmpb $0x1, %r9b
ja 0x4b063
addq %rcx, %r8
addq $0x2c, %r8
movb $0x4, (%r8)
addl %edx, -0x4(%r8)
incq %rsi
incq %rdi
cmpq %rdi, %r14
jne 0x4b037
testq %rsi, %rsi
movq 0x28(%rsp), %rdi
je 0x4b0ef
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
movq 0x8(%rsp), %r14
jne 0x4b0af
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
callq 0x2370
movq 0x20(%rsp), %r11
movq %rax, %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
shlq $0x20, %rcx
orq %r15, %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rcx, (%rdi,%rax,8)
movq 0x58(%rsp), %rax
movq %rdi, 0x28(%rsp)
incq (%rdi,%rax,8)
jmp 0x4b0f4
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %rbx
movq 0x8(%rsp), %r14
jmp 0x4ae0e
movq 0x38(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x40(%r14), %rax
movq %rax, %r12
subq 0x38(%r14), %r12
movq 0x40(%rsp), %r15
cmpq %rax, %r12
jge 0x4ae0e
movq 0x28(%r14), %r15
movq (%rbp), %rbp
movq %r12, %r14
movq $0x0, 0x78(%rsp)
movq (%r15,%r14,8), %r13
movl %r13d, %ebx
imulq $0xa8, %rbx, %rdi
movb 0x2c(%rbp,%rdi), %al
addb $-0x3, %al
cmpb $0x1, %al
ja 0x4b1b0
movl 0x4(%rbp,%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
subq %rcx, %rdx
movq 0x10(%rsp), %rsi
leaq (%rdx,%rsi), %rax
cqto
idivq %r11
subq %rdx, %rsi
cmpq %rcx, %rsi
jg 0x4b161
movq %rcx, %rsi
addq %rbp, %rdi
movq %r11, %rdx
callq 0x4ac93
testq %rax, %rax
js 0x4b192
shlq $0x20, %rax
orq %rbx, %rax
movq %rax, (%r15,%r14,8)
cmpq %r12, %r14
je 0x4b18d
movq (%r15,%r12,8), %rcx
movq %rcx, (%r15,%r14,8)
movq %rax, (%r15,%r12,8)
incq %r12
jmp 0x4b1ab
movabsq $-0x100000001, %rax     # imm = 0xFFFFFFFEFFFFFFFF
incq %rax
orq %rax, %r13
movq %r13, (%r15,%r14,8)
incq 0x78(%rsp)
movq 0x20(%rsp), %r11
incq %r14
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rsi
cmpq %rsi, %r14
jl 0x4b121
movq 0x40(%rsp), %rax
movq %rax, %r15
cmpq $0x0, 0x78(%rsp)
movq 0x38(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x50(%rsp), %rbp
je 0x4ae0e
movq %rax, %r15
cmpq %rsi, %r12
jge 0x4ae0e
movq %r12, %r15
movq 0x28(%r14), %rdi
movq (%rdi,%r15,8), %rax
movl %eax, %ecx
movq (%rbp), %r8
imulq $0xa8, %rcx, %r9
movb 0x2c(%r8,%r9), %cl
addb $-0x3, %cl
cmpb $0x1, %cl
ja 0x4b367
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rcx, %rax
jbe 0x4b3b7
movl 0x8(%r8,%r9), %r13d
movl 0x4(%r8,%r9), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
movq %rcx, %r10
subq %rdx, %r10
movq 0x10(%rsp), %rax
subq %r10, %rax
cqto
idivq %r11
movq %rax, %rbp
imulq %r11, %rbp
addq %r10, %rbp
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
incq %rax
imulq %r11, %rax
addq %r10, %rax
decq %rax
cmpq %r13, %rax
cmovlq %rax, %r13
movq %rsi, %rax
subq 0x38(%r14), %rax
cmpq %r12, %rax
jge 0x4b2e3
movq (%rdi,%rax,8), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
cmpq %r10, %rcx
je 0x4b38f
movl %edx, %edx
imulq $0xa8, %rdx, %rdx
movb 0x2c(%r8,%rdx), %r10b
addb $-0x3, %r10b
cmpb $0x2, %r10b
jae 0x4b398
movq 0x58(%r8,%rdx), %rdx
shlq $0x5, %rcx
movslq (%rdx,%rcx), %r10
cmpq %r10, %rbp
jl 0x4b2de
addq %rcx, %rdx
movslq 0x4(%rdx), %rcx
cmpq %rcx, %r13
jle 0x4b362
incq %rax
jmp 0x4b281
leaq (%r8,%r9), %rax
addq $0x2c, %rax
movb $0x4, (%rax)
movl %r13d, %ecx
subl %ebp, %ecx
movl -0x4(%rax), %edx
addl %edx, %ecx
incl %ecx
movl %ecx, -0x4(%rax)
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
jne 0x4b339
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq 0x28(%rsp), %rdi
callq 0x2370
movq 0x20(%rsp), %r11
movq %rax, %rdx
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
jmp 0x4b33e
movq 0x28(%rsp), %rdx
shlq $0x20, %rbp
orq %r13, %rbp
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movq %rbp, (%rdx,%rax,8)
movq 0x58(%rsp), %rax
movq %rdx, 0x28(%rsp)
incq (%rdx,%rax,8)
movq 0x40(%r14), %rsi
movq 0x50(%rsp), %rbp
incq %r15
cmpq %rsi, %r15
jl 0x4b1f7
movq 0x40(%rsp), %r15
jmp 0x4ae0e
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e6639(%rip), %rdi    # 0x2319cf
jmp 0x4b39f
leaq 0x1e6641(%rip), %rdi    # 0x2319e0
leaq 0x1e63ad(%rip), %rsi    # 0x231753
leaq 0x1e65b9(%rip), %rcx    # 0x231966
movl $0xc60, %edx            # imm = 0xC60
callq 0x2110
leaq 0x1e6583(%rip), %rdi    # 0x231941
leaq 0x1e638e(%rip), %rsi    # 0x231753
leaq 0x1e659a(%rip), %rcx    # 0x231966
movl $0xc5c, %edx            # imm = 0xC5C
callq 0x2110