// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %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, 0x20(%rsp)
movq %rcx, 0x38(%rsp)
cqto
idivq %r8
xorl %r14d, %r14d
testq %rdx, %rdx
setg %r14b
addq %rax, %r14
cmpq %r14, 0x8(%rbx)
movq %r8, 0x18(%rsp)
jae 0x4b735
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 0x18(%rsp), %r11
movq %rax, 0x10(%rbx)
decq %r15
movq %r15, 0x68(%rsp)
movq 0x38(%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
movq %rbx, 0x28(%rsp)
movq %r14, (%rbx)
movq 0x8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x48(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x68(%rsp), %r13
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
cmpq 0x50(%rsp), %r13
jne 0x4b7d5
cmpq $0x0, 0x38(%rsp)
sete %al
cmpl $0x1, 0x14(%rsp)
sete %cl
orb %al, %cl
movl $0x1, %ecx
movq 0x28(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r15
je 0x4b7e8
xorl %eax, %eax
movq (%rsp), %rdi
movq %r13, %rsi
jmp 0x4b805
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r15
movq (%rsp), %rax
leaq (%rax,%r11), %rdi
leaq (%r11,%r13), %rsi
cmpq 0x38(%rsp), %rsi
cmovgeq 0x50(%rsp), %rsi
movb $0x1, %al
movl %ecx, 0x14(%rsp)
movq 0x48(%rsp), %r12
cmpl $-0x2, 0x10(%rsp)
je 0x4bd19
testb %al, %al
je 0x4bd19
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
cmpq $0x0, (%rsp)
jne 0x4b834
movq $0x0, 0x48(%r14)
movq 0x48(%r14), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
movq %rsi, 0x68(%rsp)
movq %rdi, 0x60(%rsp)
movq %r13, 0x30(%rsp)
jae 0x4b87d
movq (%r15), %rcx
imulq $0xa8, %rax, %rdx
movl 0x4(%rcx,%rdx), %ecx
cmpq %rcx, %r13
jge 0x4b893
movq $0x0, 0x48(%r14)
movaps %xmm0, (%r12)
movl $0x0, 0x10(%rsp)
jmp 0x4b942
movq %rcx, 0x48(%r14)
movaps %xmm0, (%r12)
movl $0xfffffffe, 0x10(%rsp) # imm = 0xFFFFFFFE
jmp 0x4b942
movaps %xmm0, (%r12)
cmpq 0x10(%r15), %rax
jae 0x4b931
movq (%r15), %rsi
movq %r13, %rcx
subq (%rsp), %rcx
incq %rcx
addq %rsi, %rdx
addq $0x8, %rdx
xorl %esi, %esi
movl -0x4(%rdx), %edi
movl (%rdx), %r8d
cmpq %r13, %r8
cmovgeq %r13, %r8
movq (%rsp), %r9
cmpq %r9, %rdi
cmovgq %rdi, %r9
subq %r9, %r8
js 0x4b91c
cmpq %r11, %rcx
jne 0x4b8f4
incq %r8
cmpq %r11, %r8
jne 0x4b8f4
movq 0x28(%r14), %r8
movq 0x30(%r14), %r9
movq %rax, (%r8,%r9,8)
incq 0x30(%r14)
jmp 0x4b90e
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 0x4b917
movq %rax, 0x48(%r14)
movl $0x1, %esi
cmpq %rdi, %r13
jl 0x4b931
incq %rax
addq $0xa8, %rdx
cmpq 0x10(%r15), %rax
jb 0x4b8b8
movq 0x30(%r14), %rax
xorl %ecx, %ecx
addq 0x38(%r14), %rax
setne %cl
movl %ecx, 0x10(%rsp)
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
shlq $0x20, %rax
movq 0x40(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x58(%rsp)
movq %rsi, 0x70(%rsp)
movq %rax, (%rsi,%rcx,8)
movq (%r12), %r14
testq %r14, %r14
setg %bl
jle 0x4b9e2
movq 0x8(%rsp), %rax
movq 0x28(%rax), %r15
movq 0x20(%rsp), %rax
movq (%rax), %r12
movq %r14, %rbp
negq %rbp
movl $0x1, %r13d
movl -0x8(%r15,%r13,8), %eax
imulq $0xa8, %rax, %rdi
movb 0x2c(%r12,%rdi), %al
addb $-0x3, %al
cmpb $0x1, %al
ja 0x4b9bd
addq %r12, %rdi
movq (%rsp), %rsi
movq %r11, %rdx
callq 0x4b60f
movq 0x18(%rsp), %r11
testq %rax, %rax
jns 0x4b9d9
cmpq %r14, %r13
setl %bl
leaq 0x1(,%r13), %rax
addq %rbp, %rax
incq %r13
cmpq $0x1, %rax
jne 0x4b98d
jmp 0x4b9e2
testb $0x1, %bl
jne 0x4b782
testq %r14, %r14
movq 0x20(%rsp), %r13
movq 0x30(%rsp), %r15
jle 0x4baa6
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq (%r13), %rcx
movl %r15d, %edx
subl (%rsp), %edx
incl %edx
xorl %edi, %edi
xorl %esi, %esi
movl (%rax,%rdi,8), %r8d
imulq $0xa8, %r8, %r8
movb 0x2c(%rcx,%r8), %r9b
addb $-0x3, %r9b
cmpb $0x1, %r9b
ja 0x4ba3a
addq %rcx, %r8
addq $0x2c, %r8
movb $0x4, (%r8)
addl %edx, -0x4(%r8)
incq %rsi
incq %rdi
cmpq %rdi, %r14
jne 0x4ba0e
testq %rsi, %rsi
je 0x4baa6
movq 0x28(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x4ba80
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq 0x70(%rsp), %rdi
callq 0x2370
movq 0x18(%rsp), %r11
movq %rax, 0x10(%rbx)
movq (%rsp), %rax
shlq $0x20, %rax
orq %r15, %rax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rcx,8)
movq 0x40(%rsp), %rax
incq (%rdx,%rax,8)
movq 0x8(%rsp), %rdx
movq 0x40(%rdx), %rcx
movq %rcx, %r12
subq 0x38(%rdx), %r12
movb $0x1, %al
cmpq %rcx, %r12
jge 0x4bb7f
movq 0x28(%rdx), %r15
movq (%r13), %r13
movq %r12, %r14
movq $0x0, 0x30(%rsp)
movq (%r15,%r14,8), %rbp
movl %ebp, %ebx
imulq $0xa8, %rbx, %rdi
movb 0x2c(%r13,%rdi), %al
addb $-0x3, %al
cmpb $0x1, %al
ja 0x4bb64
movl 0x4(%r13,%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
subq %rcx, %rdx
movq (%rsp), %rsi
leaq (%rdx,%rsi), %rax
cqto
idivq %r11
subq %rdx, %rsi
cmpq %rcx, %rsi
jg 0x4bb15
movq %rcx, %rsi
addq %r13, %rdi
movq %r11, %rdx
callq 0x4b60f
testq %rax, %rax
js 0x4bb46
shlq $0x20, %rax
orq %rbx, %rax
movq %rax, (%r15,%r14,8)
cmpq %r12, %r14
je 0x4bb41
movq (%r15,%r12,8), %rcx
movq %rcx, (%r15,%r14,8)
movq %rax, (%r15,%r12,8)
incq %r12
jmp 0x4bb5f
movabsq $-0x100000001, %rax     # imm = 0xFFFFFFFEFFFFFFFF
incq %rax
orq %rax, %rbp
movq %rbp, (%r15,%r14,8)
incq 0x30(%rsp)
movq 0x18(%rsp), %r11
incq %r14
movq 0x8(%rsp), %rax
cmpq 0x40(%rax), %r14
jl 0x4bad5
cmpq $0x0, 0x30(%rsp)
sete %al
testb %al, %al
jne 0x4b782
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rsi
cmpq %rsi, %r12
jge 0x4b782
movq %r12, %r13
movq 0x28(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x28(%r14), %r8
movq (%r8,%r13,8), %rax
movl %eax, %ecx
movq 0x20(%rsp), %rdx
movq (%rdx), %rdi
imulq $0xa8, %rcx, %r9
movb 0x2c(%rdi,%r9), %cl
addb $-0x3, %cl
cmpb $0x1, %cl
ja 0x4bd04
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rcx, %rax
jbe 0x4bd50
movl 0x8(%rdi,%r9), %r15d
movl 0x4(%rdi,%r9), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
movq %rcx, %r10
subq %rdx, %r10
movq (%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 %r15, %rax
cmovlq %rax, %r15
subq 0x38(%r14), %rsi
cmpq %r12, %rsi
setl %al
jge 0x4bc95
movq (%r8,%rsi,8), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
cmpq %r10, %rcx
je 0x4bd28
movl %edx, %edx
imulq $0xa8, %rdx, %rdx
movb 0x2c(%rdi,%rdx), %r10b
addb $-0x3, %r10b
cmpb $0x2, %r10b
jae 0x4bd31
movq 0x58(%rdi,%rdx), %rdx
shlq $0x5, %rcx
movslq (%rdx,%rcx), %r10
cmpq %r10, %rbp
jl 0x4bc8c
addq %rcx, %rdx
movslq 0x4(%rdx), %rcx
cmpq %rcx, %r15
jle 0x4bc91
incq %rsi
jmp 0x4bc30
testb $0x1, %al
jne 0x4bd04
leaq (%rdi,%r9), %rax
addq $0x2c, %rax
movb $0x4, (%rax)
movl %r15d, %ecx
subl %ebp, %ecx
movl -0x4(%rax), %edx
addl %edx, %ecx
incl %ecx
movl %ecx, -0x4(%rax)
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x4bce2
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x18(%rsp), %r11
movq %rax, 0x10(%rbx)
shlq $0x20, %rbp
orq %r15, %rbp
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rbp, (%rcx,%rax,8)
movq 0x40(%rsp), %rax
incq (%rcx,%rax,8)
incq %r13
movq 0x40(%r14), %rsi
cmpq %rsi, %r13
jl 0x4bba6
jmp 0x4b782
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d9b90(%rip), %rdi    # 0x2258bf
jmp 0x4bd38
leaq 0x1d9b98(%rip), %rdi    # 0x2258d0
leaq 0x1d9904(%rip), %rsi    # 0x225643
leaq 0x1d9b10(%rip), %rcx    # 0x225856
movl $0xc60, %edx            # imm = 0xC60
callq 0x2110
leaq 0x1d9ada(%rip), %rdi    # 0x225831
leaq 0x1d98e5(%rip), %rsi    # 0x225643
leaq 0x1d9af1(%rip), %rcx    # 0x225856
movl $0xc5c, %edx            # imm = 0xC5C
callq 0x2110