// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %r8, %rbx
movq %rcx, 0x40(%rsp)
movq %rdx, %r12
movq %rsi, 0x38(%rsp)
movq %rdi, %r15
movq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x88(%rsp), %r14
xorl %ebp, %ebp
movl %ebp, 0x230(%r9)
movq %rbp, 0x220(%r9)
movl %ebp, 0x10(%r9)
movq %rbp, 0x8(%r9)
movq %r9, 0x18(%rsp)
leaq 0x18(%r9), %rdi
movl $0x1ac, %edx            # imm = 0x1AC
xorl %esi, %esi
callq 0x20e0
movq %r12, 0x10(%rsp)
movq 0x8(%r12), %rax
cmpq %r14, %rax
movq %r14, %r13
cmovlq %rax, %r13
decq %r13
movq %rax, 0x20(%rsp)
decq %rax
movq %rax, 0x28(%rsp)
leaq 0x30(%rbx), %r8
xorps %xmm0, %xmm0
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movq %r8, 0x30(%rsp)
movq %r13, %rdx
movq %rbp, %rsi
cmpq 0x28(%rsp), %r13
jne 0x5857c
cmpq $0x0, 0x20(%rsp)
sete %al
cmpl $0x1, 0x4(%rsp)
sete %cl
orb %al, %cl
movl $0x1, %ecx
je 0x58580
xorl %eax, %eax
movq %rsi, %rbp
movq %rdx, %r13
jmp 0x58599
movl 0x4(%rsp), %ecx
leaq (%rsi,%r14), %rbp
leaq (%rdx,%r14), %r13
cmpq 0x20(%rsp), %r13
cmovgeq 0x28(%rsp), %r13
movb $0x1, %al
movl %ecx, 0x4(%rsp)
cmpl $-0x2, %r12d
je 0x586bd
testb %al, %al
je 0x586bd
movaps %xmm0, (%r8)
testq %rsi, %rsi
jne 0x585bc
movq $0x0, 0x48(%rbx)
movq 0x48(%rbx), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
jae 0x585ed
movq (%r15), %rdi
imulq $0xa8, %rax, %rcx
movl 0x4(%rdi,%rcx), %edi
cmpq %rdi, %rdx
jge 0x58638
movq $0x0, 0x48(%rbx)
movaps %xmm0, (%r8)
xorl %r12d, %r12d
jmp 0x585fb
movq %rcx, 0x48(%rbx)
movaps %xmm0, (%r8)
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rax
movq (%rax), %rdi
subq $0x8, %rsp
movq %r15, %rcx
movq %rbx, %r8
movq 0x40(%rsp), %r9
pushq 0x10(%rsp)
pushq %r14
pushq $0x1
pushq 0x60(%rsp)
pushq 0x40(%rsp)
callq 0x50775
xorps %xmm0, %xmm0
addq $0x30, %rsp
movq 0x30(%rsp), %r8
jmp 0x5854b
movaps %xmm0, (%r8)
xorl %r12d, %r12d
cmpq 0x10(%r15), %rax
jae 0x585fb
movq (%r15), %rdi
addq %rdi, %rcx
addq $0x4, %rcx
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rcx), %r9d
movl 0x4(%rcx), %r10d
cmpq %rdx, %r10
cmovgeq %rdx, %r10
cmpq %rsi, %r9
movq %rsi, %r11
cmovgq %r9, %r11
cmpq %r11, %r10
jl 0x58699
cmpb $0x1, 0x28(%rcx)
jne 0x58687
movq 0x28(%rbx), %r10
movq 0x30(%rbx), %r11
movq %rax, (%r10,%r11,8)
incq 0x30(%rbx)
incq %rdi
testq %r8, %r8
jne 0x58693
movq %rax, 0x48(%rbx)
movl $0x1, %r8d
cmpq %r9, %rdx
jl 0x586ae
incq %rax
addq $0xa8, %rcx
cmpq 0x10(%r15), %rax
jb 0x58654
xorl %r12d, %r12d
testq %rdi, %rdi
setne %r12b
jmp 0x585fb
movq 0x18(%rsp), %rbp
movq 0x228(%rbp), %rcx
movl 0x230(%rbp), %eax
cmpq $0x0, 0x8(%rsp)
je 0x5873e
cmpq %rax, %rcx
jae 0x587a1
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(%rbp)
movq 0x218(%rbp), %rsi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rdx
movq 0x8(%rsp), %rdi
callq 0x1e3800
jmp 0x5879a
cmpq %rax, %rcx
jae 0x587a1
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(%rbp)
movq 0x218(%rbp), %rdi
leaq 0x8(,%rcx,8), %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, 0x218(%rbp)
movq $0x0, 0x220(%rbp)
movl 0x10(%r15), %eax
movl %eax, 0x1c8(%rbp)
movl $0x0, 0x1c4(%rbp)
movl 0x10(%rbp), %ecx
testq %rcx, %rcx
je 0x58838
movl $0x1, %r13d
movl $0x18, %r12d
xorl %r14d, %r14d
xorl %eax, %eax
cmpq %rcx, %r13
je 0x587ef
movq (%rbp), %rcx
movl (%rcx,%r12), %edx
leaq (%rax,%rax,2), %rsi
cmpl (%rcx,%rsi,8), %edx
je 0x58823
movq (%rbp), %rcx
leaq (%rax,%rax,2), %rdx
leaq (%rcx,%rdx,8), %rsi
movq %r13, %rdx
subq %rax, %rdx
leaq (%r14,%r14,2), %rax
leaq (%rcx,%rax,8), %rcx
movq %rbp, %rdi
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
callq 0x571e7
cltq
addq %rax, %r14
movq %r13, %rax
leaq 0x1(%r13), %rdx
movl 0x10(%rbp), %ecx
addq $0x18, %r12
cmpq %rcx, %r13
movq %rdx, %r13
jb 0x587d9
jmp 0x5883b
xorl %r14d, %r14d
movl %r14d, 0x10(%rbp)
movq %rbp, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x52353
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 0x5198e