// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %r9, %r12
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %rbp
andl $0x0, 0x230(%r9)
movq %rdi, %r15
andq $0x0, 0x220(%r9)
leaq 0x230(%r9), %rax
movq %rax, 0x28(%rsp)
andl $0x0, 0x10(%r9)
andq $0x0, 0x8(%r9)
leaq 0x18(%r9), %rdi
xorl %r13d, %r13d
movl $0x1ac, %edx            # imm = 0x1AC
xorl %esi, %esi
callq 0x20e0
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %rax
leaq 0x22af58(%rip), %rcx    # 0x253758
movsd 0x1baa98(%rip), %xmm0   # 0x1e32a0
divsd 0xc0(%rcx), %xmm0
cvttsd2si %xmm0, %ecx
leaq 0x30(%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(%r14), %rbx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x52721
cmpl $-0x2, %r13d
je 0x288cb
testl %eax, %eax
je 0x288cb
xorpd %xmm0, %xmm0
movapd %xmm0, (%rbx)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x530d0
movl %eax, %r13d
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq $0x8, %rsp
movq %r15, %rcx
movq %r14, %r8
movq %rbp, %r9
pushq $0x1
pushq 0x18(%rsp)
pushq %r12
callq 0x215bc
addq $0x20, %rsp
jmp 0x2885b
movq %r14, 0x8(%rsp)
leaq 0x10(%r15), %rdx
xorl %ebx, %ebx
movq %r12, %rdi
movq 0x28(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x53d01
pushq $0x1
popq %r13
pushq $0x18
popq %rbp
xorl %r14d, %r14d
movl 0x10(%r12), %eax
cmpq %rax, %r13
ja 0x28943
movq (%r12), %rax
je 0x2890e
movl (%rax,%rbp), %ecx
imulq $0x18, %rbx, %rdx
cmpl (%rax,%rdx), %ecx
je 0x2893a
imulq $0x18, %rbx, %rsi
addq %rax, %rsi
movq %r13, %rdx
subq %rbx, %rdx
imulq $0x18, %r14, %rcx
addq %rax, %rcx
movq %r12, %rdi
movq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x27a67
cltq
addq %rax, %r14
movq %r13, %rbx
incq %r13
addq $0x18, %rbp
jmp 0x288f2
movl %r14d, 0x10(%r12)
movsd 0x1babe8(%rip), %xmm0   # 0x1e3538
pushq $0x1
popq %rcx
pushq $-0x1
popq %r8
xorps %xmm1, %xmm1
movq %r12, %rdi
movq %r15, %rsi
callq 0x23d9f
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x22ade3(%rip), %rax    # 0x253758
movsd 0xc0(%rax), %xmm0
movq %r15, %rdi
movq 0x8(%rsp), %rdx
callq 0x22ac3
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq