// File: /workspace/github_cpp_makefile_star2_O1/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, 0x30(%rsp)
movq %r8, 0x38(%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 0x59139
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)
decq %rax
movq %rax, 0x28(%rsp)
leaq 0x30(%rbx), %rdi
xorps %xmm0, %xmm0
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movq %rdi, 0x40(%rsp)
cmpq 0x28(%rsp), %rsi
jne 0x58ef9
cmpq $0x0, 0x20(%rsp)
sete %al
cmpl $0x1, 0xc(%rsp)
sete %cl
orb %al, %cl
movl $0x1, %ecx
je 0x58efd
xorl %eax, %eax
movq %r13, %r14
movq %rsi, %r15
jmp 0x58f1b
movl 0xc(%rsp), %ecx
movl $0x177, %eax            # imm = 0x177
leaq (%rax,%r13), %r14
leaq (%rsi,%rax), %r15
cmpq 0x20(%rsp), %r15
cmovgeq 0x28(%rsp), %r15
movb $0x1, %al
movl %ecx, 0xc(%rsp)
cmpl $-0x2, %ebp
je 0x5905d
testb %al, %al
je 0x5905d
movaps %xmm0, (%rdi)
testq %r13, %r13
jne 0x58f3c
movq $0x0, 0x48(%rbx)
movq 0x48(%rbx), %rax
movq 0x10(%r12), %rcx
cmpq %rcx, %rax
jae 0x58f70
movq (%r12), %rcx
imulq $0xa8, %rax, %rdx
movl 0x4(%rcx,%rdx), %ecx
cmpq %rcx, %rsi
jge 0x58f81
movq $0x0, 0x48(%rbx)
movaps %xmm0, (%rdi)
xorl %ebp, %ebp
jmp 0x5902f
movq %rcx, 0x48(%rbx)
movaps %xmm0, (%rdi)
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x5902f
movaps %xmm0, (%rdi)
cmpq 0x10(%r12), %rax
jae 0x59021
movq (%r12), %rdi
movq %rsi, %rcx
subq %r13, %rcx
addq %rdi, %rdx
addq $0x8, %rdx
xorl %edi, %edi
movl -0x4(%rdx), %r8d
movl (%rdx), %r9d
cmpq %rsi, %r9
cmovgeq %rsi, %r9
cmpq %r13, %r8
movq %r13, %r10
cmovgq %r8, %r10
subq %r10, %r9
js 0x5900b
cmpq $0x176, %rcx            # imm = 0x176
jne 0x58fe3
cmpq $0x176, %r9             # imm = 0x176
jne 0x58fe3
movq 0x28(%rbx), %r9
movq 0x30(%rbx), %r10
movq %rax, (%r9,%r10,8)
incq 0x30(%rbx)
jmp 0x58ffd
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 0x59006
movq %rax, 0x48(%rbx)
movl $0x1, %edi
cmpq %r8, %rsi
jl 0x59021
incq %rax
addq $0xa8, %rdx
cmpq 0x10(%r12), %rax
jb 0x58fa2
movq 0x30(%rbx), %rax
xorl %ebp, %ebp
addq 0x38(%rbx), %rax
setne %bpl
movq 0x18(%rsp), %rax
movq (%rax), %r9
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movq 0x10(%rsp), %r8
callq 0x4852a
movq %r14, %r13
movq %r15, %rsi
movq 0x40(%rsp), %rdi
xorps %xmm0, %xmm0
jmp 0x58ece
leaq 0x2316f4(%rip), %rax    # 0x28a758
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 0x38(%rsp), %r13
movq %r13, %r9
pushq $0x177                  # imm = 0x177
pushq 0xa8(%rsp)
callq 0x87a95
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
movq %rbx, %r8
movq 0xa0(%rsp), %r9
callq 0x5812f
addq $0x10, %rsp
cmpl $0x0, 0xb8(%rsp)
je 0x5910a
subq $0x8, %rsp
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq 0x38(%rsp), %r8
movq 0x88(%rsp), %r9
pushq 0xb0(%rsp)
pushq 0xa8(%rsp)
pushq 0xa0(%rsp)
callq 0x4f211
addq $0x20, %rsp
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq 0xc8(%rsp), %r9
callq 0x4f628
movq 0xc0(%rsp), %rcx
movl %eax, (%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq