// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: partition_overlaps_advance(overlap_region_alloc*, All_reads*, UC_Read*, UC_Read*, Correct_dumy*, haplotype_evdience_alloc*, int)
void partition_overlaps_advance(overlap_region_alloc* overlap_list, All_reads* R_INF, 
                        UC_Read* g_read, UC_Read* overlap_read, Correct_dumy* dumy, 
                        haplotype_evdience_alloc* hap, int force_repeat)
{
    ResizeInitHaplotypeEvdience(hap);

    uint64_t k, l, m;
    long long window_start, window_end;
    long long num_availiable_win = 0;
    
    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;
        ///return overlaps that is overlaped with [window_start, window_end]
        flag = get_available_interval(window_start, window_end, overlap_list, dumy);
        switch (flag)
        {
            case 1:    ///found matched overlaps
                break;
            case 0:    ///do not find any matched overlaps
                break;
            case -2: ///do not find any matched overlaps, and the next window also cannot match
                break;
        }
        
        num_availiable_win = num_availiable_win + dumy->length;
        
        ///need to deal with 
        cluster_advance(g_read->seq, window_start, window_end, overlap_list, dumy, R_INF, hap, overlap_read, 1);
    }

    ///very time-consuming
    ///Fix-attention ---> able to be sorted locally
    // qsort(hap->list, hap->length, sizeof(haplotype_evdience), cmp_haplotype_evdience);
    SetSnpMatrix(hap, &(hap->nn_snp), &(overlap_list->length), 0, NULL);
    for (k = 1, l = m = 0; k <= hap->length; ++k) {  
        if (k == hap->length || hap->list[k].site != hap->list[l].site) {
            m += insert_snp_ee(hap, hap->list+l, k-l, hap->list+m, g_read, NULL);
            l = k;
        }
    }
    hap->length = m;

    // generate_haplotypes_naive_advance(hap, overlap_list, NULL);
    generate_haplotypes_naive_HiFi(hap, overlap_list, 0.04, g_read, 1, 0, ((uint64_t)-1));
    // generate_haplotypes_DP(hap, overlap_list, R_INF, g_read->length, force_repeat);
    // generate_haplotypes_naive(hap, overlap_list, R_INF, g_read->length, force_repeat);

    lable_large_indels(overlap_list, g_read->length, dumy, asm_opt.max_ov_diff_ec);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, 0x40(%rsp)
movq %rdx, %r14
movq %rsi, 0x38(%rsp)
movq %rdi, %r15
xorl %r13d, %r13d
movl %r13d, 0x230(%r9)
movq %r13, 0x220(%r9)
movl %r13d, 0x10(%r9)
movq %r13, 0x8(%r9)
movq %r9, 0x18(%rsp)
leaq 0x18(%r9), %rdi
movl $0x1ac, %edx            # imm = 0x1AC
xorl %esi, %esi
callq 0x20e0
movq %r14, 0x10(%rsp)
movq 0x8(%r14), %rax
movl $0x177, %ecx            # imm = 0x177
cmpq %rcx, %rax
movl $0x177, %edx            # imm = 0x177
cmovlq %rax, %rdx
decq %rdx
movq %rax, 0x20(%rsp)
leaq -0x1(%rax), %rcx
leaq 0x30(%rbx), %r8
xorps %xmm0, %xmm0
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movq %rcx, 0x30(%rsp)
movq %r8, 0x28(%rsp)
cmpq %rcx, %rdx
jne 0x57622
cmpq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %r12
je 0x5775f
cmpl $0x1, 0xc(%rsp)
movl $0x1, 0xc(%rsp)
jne 0x57627
jmp 0x5775f
movq 0x18(%rsp), %r12
movl $0x177, %eax            # imm = 0x177
leaq (%rdx,%rax), %r14
cmpq 0x20(%rsp), %r14
cmovgeq %rcx, %r14
cmpl $-0x2, %ebp
je 0x5775f
movaps %xmm0, (%r8)
testq %r13, %r13
je 0x57651
movq 0x48(%rbx), %rax
jmp 0x5765b
movq $0x0, 0x48(%rbx)
xorl %eax, %eax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
jae 0x5768a
movq (%r15), %rcx
imulq $0xa8, %rax, %rsi
movl 0x4(%rcx,%rsi), %edi
cmpq %rdi, %rdx
jge 0x57699
movq $0x0, 0x48(%rbx)
movaps %xmm0, (%r8)
xorl %ebp, %ebp
jmp 0x57711
movq %rcx, 0x48(%rbx)
movaps %xmm0, (%r8)
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x57711
movaps %xmm0, (%r8)
addq %rsi, %rcx
addq $0x4, %rcx
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
movl (%rcx), %r9d
movl 0x4(%rcx), %r10d
cmpq %rdx, %r10
cmovaeq %rdx, %r10
cmpq %r13, %r9
movq %r13, %r11
cmovgq %r9, %r11
cmpq %r11, %r10
jb 0x576f3
cmpb $0x1, 0x28(%rcx)
jne 0x576e1
movq 0x28(%rbx), %r10
movq %rax, (%r10,%rdi,8)
movq 0x30(%rbx), %rdi
incq %rdi
movq %rdi, 0x30(%rbx)
incq %rsi
testq %r8, %r8
jne 0x576ed
movq %rax, 0x48(%rbx)
movl $0x1, %r8d
cmpq %r9, %rdx
jl 0x57708
incq %rax
addq $0xa8, %rcx
cmpq 0x10(%r15), %rax
jb 0x576ab
xorl %ebp, %ebp
testq %rsi, %rsi
setne %bpl
movl $0x177, %eax            # imm = 0x177
leaq (%rax,%r13), %r12
movq 0x10(%rsp), %rax
movq (%rax), %rdi
subq $0x8, %rsp
movq %r13, %rsi
movq %r15, %rcx
movq %rbx, %r8
movq 0x40(%rsp), %r9
pushq $0x1
pushq 0x50(%rsp)
pushq 0x30(%rsp)
callq 0x4f4dd
addq $0x20, %rsp
movq %r12, %r13
movq %r14, %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
xorps %xmm0, %xmm0
jmp 0x575f8
movl 0x230(%r12), %eax
cmpq %rax, 0x228(%r12)
jae 0x577d2
decq %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, 0x228(%r12)
movq 0x218(%r12), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x218(%r12)
movq $0x0, 0x220(%r12)
movl 0x10(%r15), %eax
movl %eax, 0x1c8(%r12)
movl $0x0, 0x1c4(%r12)
movl 0x10(%r12), %edx
testq %rdx, %rdx
je 0x5786f
movl $0x1, %ebp
movl $0x18, %r13d
xorl %r14d, %r14d
movl %edx, %eax
xorl %ecx, %ecx
movq (%r12), %rdi
cmpq %rdx, %rbp
je 0x57828
movl (%rdi,%r13), %edx
leaq (%rcx,%rcx,2), %rsi
cmpl (%rdi,%rsi,8), %edx
je 0x5785b
leaq (%rcx,%rcx,2), %rax
leaq (%rdi,%rax,8), %rsi
movq %rbp, %rdx
subq %rcx, %rdx
leaq (%r14,%r14,2), %rax
leaq (%rdi,%rax,8), %rcx
movq %r12, %rdi
movq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x566b1
cltq
addq %rax, %r14
movl 0x10(%r12), %eax
movq %rbp, %rcx
leaq 0x1(%rbp), %rsi
movl %eax, %edx
addq $0x18, %r13
cmpq %rdx, %rbp
movq %rsi, %rbp
jb 0x57812
jmp 0x57872
xorl %r14d, %r14d
movl %r14d, 0x10(%r12)
movsd 0x1d9d69(%rip), %xmm0   # 0x2315e8
movl $0x1, %ecx
xorps %xmm1, %xmm1
movq %r12, %rdi
movq %r15, %rsi
movq $-0x1, %r8
callq 0x51d63
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
movq %rbx, %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50add