// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: correct_overlap(overlap_region_alloc*, All_reads*, UC_Read*, Correct_dumy*, UC_Read*, Graph*, Graph*, Cigar_record*, haplotype_evdience_alloc*, Round2_alignment*, kvec_t_u64_warp*, window_list_alloc*, int, int, int*, int*)
void correct_overlap(overlap_region_alloc* overlap_list, All_reads* R_INF, 
                        UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read, 
                        Graph* g, Graph* DAGCon, Cigar_record* current_cigar, 
                        haplotype_evdience_alloc* hap, Round2_alignment* second_round, 
                        kvec_t_u64_warp* v_idx, window_list_alloc* win_ciagr_buf, int force_repeat, int is_consensus, int* fully_cov, int* abnormal)
{
    clear_Correct_dumy(dumy, overlap_list, NULL);

    long long window_start, window_end;

    Window_Pool w_inf;

    init_Window_Pool(&w_inf, g_read->length, WINDOW, (int)(1.0/asm_opt.max_ov_diff_ec));

    int flag = 0;

    while(get_Window(&w_inf, &window_start, &window_end) && flag != -2)
    {
        dumy->length = 0;
        dumy->lengthNT = 0;
        flag = get_interval(window_start, window_end, overlap_list, dumy, 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;
        }

        ///dumy->lengthNT represent how many overlaps that the length of them is not equal to WINDOW; may larger or less than WINDOW
        ///dumy->length represent how many overlaps that the length of them is WINDOW
        /****************************may improve**************************/
        ///now the windows which are larger than WINDOW are verified one-by-one, to improve it, we can do it group-bygroup
        verify_window(window_start, window_end, overlap_list, dumy, R_INF, g_read->seq);
    }
    // fprintf(stderr, "###dumy->start_i:%lu, overlap_list->length:%lu\n\n", dumy->start_i, overlap_list->length);
    
    // recalcate_window(overlap_list, R_INF, g_read, dumy, overlap_read);
    // partition_overlaps(overlap_list, R_INF, g_read, dumy, hap, force_repeat);
    recalcate_window_advance(overlap_list, R_INF, NULL, g_read, dumy, overlap_read, v_idx, w_inf.window_length, asm_opt.max_ov_diff_ec, asm_opt.max_ov_diff_final);
    // fprintf(stderr, "[M::%s-beg] occ[0]->%lu, occ[1]->%lu, occ[2]->%lu, occ[3]->%lu\n", __func__, 
    // ovlp_occ(overlap_list, 0), ovlp_occ(overlap_list, 1), ovlp_occ(overlap_list, 2), ovlp_occ(overlap_list, 3));
    partition_overlaps_advance(overlap_list, R_INF, g_read, overlap_read, dumy, hap, force_repeat);
    // fprintf(stderr, "[M::%s-after] occ[0]->%lu, occ[1]->%lu, occ[2]->%lu, occ[3]->%lu\n", __func__, 
    // ovlp_occ(overlap_list, 0), ovlp_occ(overlap_list, 1), ovlp_occ(overlap_list, 2), ovlp_occ(overlap_list, 3));
    if(is_consensus)
    {
        generate_consensus(overlap_list, R_INF, g_read, dumy, g, DAGCon, current_cigar, second_round, win_ciagr_buf);
    }

    (*fully_cov) = check_if_fully_covered(overlap_list, R_INF, g_read, dumy, g, abnormal);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
xorl %r13d, %r13d
movq %rcx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x58595
movq %r14, 0x18(%rsp)
movq 0x8(%r14), %rax
movl $0x177, %ecx            # imm = 0x177
cmpq %rcx, %rax
movl $0x177, %esi            # imm = 0x177
cmovlq %rax, %rsi
decq %rsi
movq %rax, 0x20(%rsp)
leaq -0x1(%rax), %rcx
leaq 0x30(%rbx), %r8
xorps %xmm0, %xmm0
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
cmpq %rcx, %rsi
jne 0x58362
cmpq $0x0, 0x20(%rsp)
je 0x584b9
cmpl $0x1, 0xc(%rsp)
movl $0x1, 0xc(%rsp)
je 0x584b9
movl $0x177, %eax            # imm = 0x177
leaq (%rsi,%rax), %rbp
cmpq 0x20(%rsp), %rbp
cmovgeq %rcx, %rbp
cmpl $-0x2, %r14d
je 0x584b9
movaps %xmm0, (%r8)
testq %r13, %r13
je 0x5838d
movq 0x48(%rbx), %rax
jmp 0x58397
movq $0x0, 0x48(%rbx)
xorl %eax, %eax
movq 0x10(%r12), %rcx
cmpq %rcx, %rax
jae 0x583c9
movq (%r12), %rdx
imulq $0xa8, %rax, %rdi
movl 0x4(%rdx,%rdi), %ecx
cmpq %rcx, %rsi
jge 0x583dc
movq $0x0, 0x48(%rbx)
movaps %xmm0, (%r8)
xorl %r14d, %r14d
jmp 0x5847d
movq %rcx, 0x48(%rbx)
movaps %xmm0, (%r8)
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
jmp 0x5847d
movq %rsi, %rcx
subq %r13, %rcx
movaps %xmm0, (%r8)
addq %rdi, %rdx
addq $0x8, %rdx
xorl %edi, %edi
movl -0x4(%rdx), %r8d
movl (%rdx), %r9d
cmpq %rsi, %r9
cmovaeq %rsi, %r9
cmpq %r13, %r8
movq %r13, %r10
cmovgq %r8, %r10
subq %r10, %r9
js 0x58458
cmpq $0x176, %rcx            # imm = 0x176
jne 0x58430
cmpq $0x176, %r9             # imm = 0x176
jne 0x58430
movq 0x28(%rbx), %r9
movq 0x30(%rbx), %r10
movq %rax, (%r9,%r10,8)
incq 0x30(%rbx)
jmp 0x5844a
movq 0x28(%rbx), %r9
movq 0x38(%rbx), %r10
incq %r10
movq %r10, 0x38(%rbx)
movq 0x40(%rbx), %r11
subq %r10, %r11
movq %rax, (%r9,%r11,8)
testq %rdi, %rdi
jne 0x58453
movq %rax, 0x48(%rbx)
movl $0x1, %edi
cmpq %r8, %rsi
jl 0x5846e
incq %rax
addq $0xa8, %rdx
cmpq 0x10(%r12), %rax
jb 0x583ef
movq 0x30(%rbx), %rax
xorl %r14d, %r14d
addq 0x38(%rbx), %rax
setne %r14b
movl $0x177, %eax            # imm = 0x177
leaq (%rax,%r13), %r15
movq 0x18(%rsp), %rax
movq (%rax), %r9
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movq 0x10(%rsp), %r8
callq 0x47afa
movq %r15, %r13
movq %rbp, %rsi
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
xorps %xmm0, %xmm0
jmp 0x5833e
leaq 0x23d298(%rip), %rax    # 0x295758
movsd 0xc0(%rax), %xmm0
movsd 0xc8(%rax), %xmm1
movq %r12, %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
xorl %edx, %edx
movq 0x18(%rsp), %r14
movq %r14, %rcx
movq %rbx, %r8
movq 0x30(%rsp), %r13
movq %r13, %r9
pushq $0x177                  # imm = 0x177
pushq 0xa8(%rsp)
callq 0x86e70
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
movq %rbx, %r8
movq 0xa0(%rsp), %r9
callq 0x57568
addq $0x10, %rsp
cmpl $0x0, 0xb8(%rsp)
je 0x58566
subq $0x8, %rsp
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq 0x30(%rsp), %r8
movq 0x88(%rsp), %r9
pushq 0xb0(%rsp)
pushq 0xa8(%rsp)
pushq 0xa0(%rsp)
callq 0x4e386
addq $0x20, %rsp
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq 0xc8(%rsp), %r9
callq 0x4e77b
movq 0xc0(%rsp), %rcx
movl %eax, (%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq