// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xd8, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xa2440
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x18(%rbp), %rdx
movsd 0x336a67(%rip), %xmm0   # 0x382000
divsd -0x40(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %rcx
leaq -0xa8(%rbp), %rdi
callq 0x9f470
movl $0x0, -0xac(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x9f520
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xad(%rbp)
je 0x4b5ee
cmpl $-0x2, -0xac(%rbp)
setne %al
movb %al, -0xad(%rbp)
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x4b5fd
jmp 0x4b6c5
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0xa08e0
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xb4(%rbp)
subl $-0x2, %eax
je 0x4b660
jmp 0x4b643
movl -0xb4(%rbp), %eax
testl %eax, %eax
je 0x4b65e
jmp 0x4b64f
movl -0xb4(%rbp), %eax
subl $0x1, %eax
jne 0x4b662
jmp 0x4b65c
jmp 0x4b662
jmp 0x4b662
jmp 0x4b662
movq -0x70(%rbp), %rax
movq -0x30(%rbp), %rcx
addq 0x30(%rcx), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x18(%rbp), %r9
movq -0x38(%rbp), %rbx
movq -0x28(%rbp), %r11
movq -0xa0(%rbp), %r10
movq 0x20(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x3d050
jmp 0x4b5bb
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x230, %rsi            # imm = 0x230
movq -0x10(%rbp), %rdx
addq $0x10, %rdx
movq 0x20(%rbp), %r8
xorl %ecx, %ecx
callq 0xa24b0
movq $0x1, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
ja 0x4b7a3
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
je 0x4b747
movq -0x38(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x50(%rbp), %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
je 0x4b790
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
imulq $0x18, -0x50(%rbp), %rax
addq %rax, %rsi
movq -0x48(%rbp), %rdx
subq -0x50(%rbp), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rcx
imulq $0x18, -0x58(%rbp), %rax
addq %rax, %rcx
movq -0x20(%rbp), %r8
movq 0x20(%rbp), %r9
callq 0x49450
cltq
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x4b792
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x4b6ff
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x20(%rbp), %rdx
callq 0x40980
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rdx
movsd -0x40(%rbp), %xmm0
callq 0x3f660
addq $0xd8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)