// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movsd 0x1c4fac(%rip), %xmm1   # 0x1e32a0
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movq %rdx, %r14
andl $0x0, 0x90(%rsp)
movq %rsi, %r15
cltq
movq %rcx, 0x60(%rsp)
movq %r8, 0x68(%rsp)
movq %rax, 0x88(%rsp)
andq $0x0, 0x78(%rsp)
cmpq %r8, %rcx
movq %r8, %rax
cmovlq %rcx, %rax
movq %rdi, %r12
decq %rax
movq %rax, 0x80(%rsp)
leaq (%rcx,%r8), %rax
decq %rax
cqto
idivq %r8
movq %rax, 0x70(%rsp)
movq %rcx, %rax
cqto
movq %r8, 0x50(%rsp)
idivq %r8
xorl %ebx, %ebx
testq %rdx, %rdx
setg %bl
addq %rax, %rbx
cmpq %rbx, 0x8(%r14)
jae 0x1e3bd
leaq -0x1(%rbx), %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(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq %r14, 0x28(%rsp)
movq %rbx, (%r14)
leaq 0x30(%r15), %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x52721
cmpl $-0x2, 0x1c(%rsp)
je 0x1e79f
testl %eax, %eax
je 0x1e79f
movq 0x58(%rsp), %rax
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x68(%rsp), %r8
movq %r12, %rdx
movq %r15, %rcx
callq 0x5277b
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rcx
movq (%rcx), %rax
movq 0x10(%rcx), %rsi
shlq $0x20, %rax
movq 0x30(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%rsp)
movq %rsi, 0x8(%rsp)
movq %rax, (%rsi,%rcx,8)
movq 0x30(%r15), %r14
movq 0x10(%rsp), %r13
movq 0x68(%rsp), %rbp
testq %r14, %r14
movl $0x0, %eax
cmovleq %rax, %r14
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x1e4bd
movq 0x28(%r15), %rax
movl (%rax,%rbx,8), %eax
movq (%r12), %rdi
imulq $0xa8, %rax, %rax
movb 0x2c(%rdi,%rax), %cl
addb $-0x3, %cl
cmpb $0x1, %cl
ja 0x1e4b8
addq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x1e25f
testq %rax, %rax
jns 0x1e3df
incq %rbx
jmp 0x1e47e
movl 0x40(%rsp), %eax
subl %r13d, %eax
incl %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x50(%rsp), %rbx
movq 0x28(%rsp), %r13
cmpq %rdx, %r14
je 0x1e50f
movq 0x28(%r15), %rsi
movl (%rsi,%rdx,8), %edi
movq (%r12), %rsi
imulq $0xa8, %rdi, %rdi
movb 0x2c(%rsi,%rdi), %r8b
addb $-0x3, %r8b
cmpb $0x1, %r8b
ja 0x1e50a
addq %rdi, %rsi
addq $0x2c, %rsi
movb $0x4, (%rsi)
addl %eax, -0x4(%rsi)
incq %rcx
incq %rdx
jmp 0x1e4d4
testq %rcx, %rcx
je 0x1e573
movq (%r13), %rax
cmpq 0x8(%r13), %rax
jne 0x1e54b
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r13)
shlq $0x3, %rsi
movq 0x8(%rsp), %rdi
callq 0x2370
movq %rax, %rsi
movq %rax, 0x10(%r13)
movq (%r13), %rax
jmp 0x1e550
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
shlq $0x20, %rcx
orq 0x40(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r13)
movq %rcx, (%rsi,%rax,8)
movq 0x30(%rsp), %rax
incq (%rsi,%rax,8)
movq 0x40(%r15), %rax
movq %rax, %rbp
subq 0x38(%r15), %rbp
movq $0x0, 0x8(%rsp)
movq %rbp, %r14
cmpq %rax, %rbp
jge 0x1e631
movq 0x28(%r15), %rax
movl (%rax,%rbp,8), %eax
movq (%r12), %rdi
imulq $0xa8, %rax, %r13
movb 0x2c(%rdi,%r13), %al
addb $-0x3, %al
cmpb $0x1, %al
ja 0x1e625
addq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
leaq 0x20(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0x51f30
addq (%r12), %r13
movq 0x20(%rsp), %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x1e25f
testq %rax, %rax
js 0x1e60b
shlq $0x20, %rax
movq 0x28(%r15), %rcx
movl (%rcx,%rbp,8), %edx
orq %rax, %rdx
movq %rdx, (%rcx,%rbp,8)
cmpq %r14, %rbp
je 0x1e606
movq (%rcx,%r14,8), %rax
movq %rax, (%rcx,%rbp,8)
movq %rdx, (%rcx,%r14,8)
incq %r14
jmp 0x1e625
movq 0x28(%r15), %rax
movabsq $-0x100000001, %rcx     # imm = 0xFFFFFFFEFFFFFFFF
incq %rcx
orq %rcx, (%rax,%rbp,8)
incq 0x8(%rsp)
incq %rbp
movq 0x40(%r15), %rax
jmp 0x1e58a
cmpq $0x0, 0x8(%rsp)
je 0x1e3df
movq %r14, %r13
cmpq %rax, %r13
jge 0x1e3df
movq 0x28(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movl %ecx, %edx
movq (%r12), %rdi
imulq $0xa8, %rdx, %rbp
movb 0x2c(%rdi,%rbp), %dl
addb $-0x3, %dl
cmpb $0x1, %dl
ja 0x1e797
movabsq $-0x100000001, %rax     # imm = 0xFFFFFFFEFFFFFFFF
cmpq %rax, %rcx
jbe 0x1e7d9
addq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
leaq 0x20(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0x51f30
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x40(%r15), %rax
movq %rax, %rsi
subq 0x38(%r15), %rsi
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rdx
cmpq %r14, %rsi
jge 0x1e71b
movq 0x28(%r15), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
shrq $0x20, %rdi
cmpq %r11, %rdi
je 0x1e7b1
movl %r8d, %r9d
movq (%r12), %r8
imulq $0xa8, %r9, %r9
movb 0x2c(%r8,%r9), %r10b
addb $-0x3, %r10b
cmpb $0x2, %r10b
jae 0x1e7ba
movq 0x58(%r8,%r9), %r8
shlq $0x5, %rdi
movslq (%r8,%rdi), %r9
cmpq %r9, %rcx
jl 0x1e716
addq %rdi, %r8
movslq 0x4(%r8), %rdi
cmpq %rdi, %rdx
jle 0x1e797
incq %rsi
jmp 0x1e6b6
movq (%r12), %rax
movb $0x4, 0x2c(%rax,%rbp)
movl %edx, %esi
subl %ecx, %esi
movl 0x28(%rax,%rbp), %edi
addl %edi, %esi
incl %esi
movl %esi, 0x28(%rax,%rbp)
movq 0x28(%rsp), %rbp
movq (%rbp), %rdi
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rdi
jne 0x1e777
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbp)
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq (%rbp), %rdi
shlq $0x20, %rcx
orq %rdx, %rcx
leaq 0x1(%rdi), %rdx
movq %rdx, (%rbp)
movq %rcx, (%rax,%rdi,8)
movq 0x30(%rsp), %rcx
incq (%rax,%rcx,8)
movq 0x40(%r15), %rax
incq %r13
jmp 0x1e640
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c5167(%rip), %rdi    # 0x1e391f
jmp 0x1e7c1
leaq 0x1c516f(%rip), %rdi    # 0x1e3930
leaq 0x1c4edb(%rip), %rsi    # 0x1e36a3
leaq 0x1c50e7(%rip), %rcx    # 0x1e38b6
movl $0xc60, %edx            # imm = 0xC60
callq 0x2110
leaq 0x1c50b1(%rip), %rdi    # 0x1e3891
leaq 0x1c4ebc(%rip), %rsi    # 0x1e36a3
leaq 0x1c50c8(%rip), %rcx    # 0x1e38b6
movl $0xc5c, %edx            # imm = 0xC5C
callq 0x2110