// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %r9, 0x10(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %r12
xorl %r15d, %r15d
movq %rcx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x29361
movq %rbp, %r14
movq 0x8(%rbp), %rax
leaq 0x22a584(%rip), %rcx    # 0x253758
movsd 0x1ba0c4(%rip), %xmm0   # 0x1e32a0
divsd 0xc0(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
leaq 0x20(%rsp), %rdi
andl $0x0, 0x30(%rdi)
movslq %ecx, %rcx
movq %rax, (%rdi)
movl $0x177, %esi            # imm = 0x177
movq %rsi, 0x8(%rdi)
movq %rcx, 0x28(%rdi)
andq $0x0, 0x18(%rdi)
cmpq %rsi, %rax
movl $0x177, %ecx            # imm = 0x177
cmovlq %rax, %rcx
decq %rcx
movq %rcx, 0x20(%rdi)
addq $0x176, %rax            # imm = 0x176
cqto
idivq %rsi
movq %rax, 0x10(%rdi)
leaq 0x30(%rbx), %rbp
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
callq 0x52721
cmpl $-0x2, %r15d
je 0x2928c
testl %eax, %eax
je 0x2928c
xorpd %xmm0, %xmm0
movapd %xmm0, (%rbp)
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq 0x28(%rsp), %r8
movq %r12, %rdx
movq %rbx, %rcx
callq 0x5277b
movl %eax, %r15d
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq (%r14), %r9
movq %r12, %rdx
movq %rbx, %rcx
movq %r13, %r8
callq 0x1b6cf
jmp 0x2922f
leaq 0x22a4c5(%rip), %rax    # 0x253758
movsd 0xc0(%rax), %xmm0
movsd 0xc8(%rax), %xmm1
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
movq %rbx, %r8
movq 0x18(%rsp), %r15
movq %r15, %r9
pushq 0x28(%rsp)
pushq 0xb8(%rsp)
callq 0x53ed4
popq %rax
popq %rcx
subq $0x10, %rsp
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq 0xb0(%rsp), %r9
callq 0x28795
popq %rax
popq %rcx
cmpl $0x0, 0xc8(%rsp)
je 0x29332
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq 0x18(%rsp), %r8
movq 0x98(%rsp), %r9
pushq 0xc0(%rsp)
pushq 0xb8(%rsp)
pushq 0xb0(%rsp)
callq 0x208e1
addq $0x20, %rsp
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq 0xd8(%rsp), %r9
callq 0x20b09
movq 0xd0(%rsp), %rcx
movl %eax, (%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq