// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: partition_ul_overlaps_advance(overlap_region_alloc*, ul_idx_t const*, UC_Read*, UC_Read*, Correct_dumy*, haplotype_evdience_alloc*, int, double, long long, void*)
void partition_ul_overlaps_advance(overlap_region_alloc* overlap_list, const ul_idx_t *uref, 
                        UC_Read* g_read, UC_Read* overlap_read, Correct_dumy* dumy, haplotype_evdience_alloc* hap, 
                        int force_repeat, double max_ov_diff_ec, long long blockLen, void *km)
{
    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, blockLen, (int)(1.0/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_ul_advance(g_read->seq, window_start, window_end, overlap_list, dumy, uref, hap, overlap_read, 1, w_inf.window_length, km);
    }


    
    ///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, km);
    for (k = 1, l = m = 0; k <= hap->length; ++k) {  
        if (k == hap->length || hap->list[k].site != hap->list[l].site) {
            // debug_phasing_snp_site_status(hap, hap->list+l, k-l, overlap_list);
            m += insert_snp_ee(hap, hap->list+l, k-l, hap->list+m, g_read, km);
            l = k;
        }
    }
    hap->length = m;

    generate_haplotypes_naive_advance(hap, overlap_list, km);

    // 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, max_ov_diff_ec);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r9, %r12
movq %r8, 0x10(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r14
andl $0x0, 0x230(%r9)
movq 0xb8(%rsp), %rbx
andq $0x0, 0x220(%r9)
leaq 0x230(%r9), %rax
movq %rax, 0x30(%rsp)
andl $0x0, 0x10(%r9)
andq $0x0, 0x8(%r9)
leaq 0x18(%r9), %rdi
xorl %ebp, %ebp
movl $0x1ac, %edx            # imm = 0x1AC
xorl %esi, %esi
callq 0x20e0
movq %r15, 0x8(%rsp)
movq 0x8(%r15), %rax
movsd 0x1ba808(%rip), %xmm0   # 0x1e32a0
divsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
leaq 0x40(%rsp), %rsi
andl $0x0, 0x30(%rsi)
movslq %ecx, %rcx
movq %rax, (%rsi)
movq %rbx, 0x8(%rsi)
movq %rcx, 0x28(%rsi)
andq $0x0, 0x18(%rsi)
cmpq %rbx, %rax
movq %rbx, %rcx
cmovlq %rax, %rcx
decq %rcx
movq %rcx, 0x20(%rsi)
addq %rbx, %rax
decq %rax
cqto
idivq %rbx
movq 0x10(%rsp), %rbx
movq %rax, 0x10(%rsi)
leaq 0x30(%rbx), %r15
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x52721
cmpl $-0x2, %ebp
je 0x28b61
testl %eax, %eax
je 0x28b61
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x530d0
movl %eax, %ebp
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
subq $0x8, %rsp
movq %r14, %rcx
movq %rbx, %r8
movq %r13, %r9
pushq 0xc8(%rsp)
pushq 0x58(%rsp)
pushq $0x1
pushq 0x58(%rsp)
pushq %r12
callq 0x21975
addq $0x30, %rsp
jmp 0x28ae7
leaq 0x10(%r14), %rdx
xorl %ebx, %ebx
movq %r12, %rdi
movq 0x30(%rsp), %rsi
xorl %ecx, %ecx
movq 0xc0(%rsp), %r8
callq 0x53d01
pushq $0x1
popq %r13
pushq $0x18
popq %rbp
xorl %r15d, %r15d
movl 0x10(%r12), %eax
cmpq %rax, %r13
ja 0x28bde
movq (%r12), %rax
je 0x28ba4
movl (%rax,%rbp), %ecx
imulq $0x18, %rbx, %rdx
cmpl (%rax,%rdx), %ecx
je 0x28bd5
imulq $0x18, %rbx, %rsi
addq %rax, %rsi
movq %r13, %rdx
subq %rbx, %rdx
imulq $0x18, %r15, %rcx
addq %rax, %rcx
movq %r12, %rdi
movq 0x8(%rsp), %r8
movq 0xc0(%rsp), %r9
callq 0x27a67
cltq
addq %rax, %r15
movq %r13, %rbx
incq %r13
addq $0x18, %rbp
jmp 0x28b88
movl %r15d, 0x10(%r12)
movq %r12, %rdi
movq %r14, %rsi
movq 0xc0(%rsp), %rdx
callq 0x23346
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdi
movq 0x10(%rsp), %rdx
movsd 0x18(%rsp), %xmm0
callq 0x22ac3
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq