// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: partition_overlaps_advance_back(overlap_region_alloc*, All_reads*, UC_Read*, UC_Read*, Correct_dumy*, haplotype_evdience_alloc*, int)
void partition_overlaps_advance_back(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);

    long long i;
    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), 1, NULL);

    uint64_t pre_site = (uint64_t)-1;
    uint64_t num_of_snps = 0;
    long long pre_i = -1;
    long long sub_length;
    haplotype_evdience* sub_list;

    ////split reads
    for (i = 0; i < hap->length; i++)
    {
        if(pre_site != hap->list[i].site)
        {
            if(i != 0)
            {
                sub_list = hap->list + pre_i;
                sub_length = i - pre_i;
                split_sub_list(hap, sub_list, sub_length, overlap_list, R_INF, g_read);
            }
            num_of_snps++;
            pre_site = hap->list[i].site;
            pre_i = i;
        }
    }

    if(pre_i != -1)
    {
        sub_list = hap->list + pre_i;
        sub_length = i - pre_i;
        split_sub_list(hap, sub_list, sub_length, overlap_list, R_INF, g_read);
    }

    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 $0x38, %rsp
movq %r8, %rbx
movq %rcx, 0x30(%rsp)
movq %rdx, %r14
movq %rsi, 0x28(%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, 0x8(%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, %ebp            # imm = 0x177
cmovlq %rax, %rbp
decq %rbp
movq %rax, 0x18(%rsp)
decq %rax
movq %rax, 0x20(%rsp)
leaq 0x30(%rbx), %r14
xorps %xmm0, %xmm0
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movq %rbp, %rdx
movq %r13, %rsi
cmpq 0x20(%rsp), %rbp
jne 0x56eef
cmpq $0x0, 0x18(%rsp)
sete %al
cmpl $0x1, 0x4(%rsp)
sete %cl
orb %al, %cl
movl $0x1, %ecx
je 0x56ef3
xorl %eax, %eax
movq %rsi, %r13
movq %rdx, %rbp
jmp 0x56f11
movl 0x4(%rsp), %ecx
movl $0x177, %eax            # imm = 0x177
leaq (%rsi,%rax), %r13
leaq (%rdx,%rax), %rbp
cmpq 0x18(%rsp), %rbp
cmovgeq 0x20(%rsp), %rbp
movb $0x1, %al
movl %ecx, 0x4(%rsp)
cmpl $-0x2, %r12d
je 0x5702a
testb %al, %al
je 0x5702a
movaps %xmm0, (%r14)
testq %rsi, %rsi
jne 0x56f34
movq $0x0, 0x48(%rbx)
movq 0x48(%rbx), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
jae 0x56f65
movq (%r15), %rdi
imulq $0xa8, %rax, %rcx
movl 0x4(%rdi,%rcx), %edi
cmpq %rdi, %rdx
jge 0x56fa5
movq $0x0, 0x48(%rbx)
movaps %xmm0, (%r14)
xorl %r12d, %r12d
jmp 0x56f73
movq %rcx, 0x48(%rbx)
movaps %xmm0, (%r14)
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movq 0x10(%rsp), %rax
movq (%rax), %rdi
subq $0x8, %rsp
movq %r15, %rcx
movq %rbx, %r8
movq 0x30(%rsp), %r9
pushq $0x1
pushq 0x40(%rsp)
pushq 0x20(%rsp)
callq 0x50367
xorps %xmm0, %xmm0
addq $0x20, %rsp
jmp 0x56ebe
movaps %xmm0, (%r14)
xorl %r12d, %r12d
cmpq 0x10(%r15), %rax
jae 0x56f73
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 0x57006
cmpb $0x1, 0x28(%rcx)
jne 0x56ff4
movq 0x28(%rbx), %r10
movq 0x30(%rbx), %r11
movq %rax, (%r10,%r11,8)
incq 0x30(%rbx)
incq %rdi
testq %r8, %r8
jne 0x57000
movq %rax, 0x48(%rbx)
movl $0x1, %r8d
cmpq %r9, %rdx
jl 0x5701b
incq %rax
addq $0xa8, %rcx
cmpq 0x10(%r15), %rax
jb 0x56fc1
xorl %r12d, %r12d
testq %rdi, %rdi
setne %r12b
jmp 0x56f73
movq 0x8(%rsp), %rbp
movl 0x230(%rbp), %eax
cmpq %rax, 0x228(%rbp)
movq 0x10(%rsp), %r12
jae 0x570a1
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)
movq 0x10(%r15), %r14
movl %r14d, 0x1c8(%rbp)
movl $0x0, 0x1c4(%rbp)
movl 0x1d8(%rbp), %eax
movl 0x230(%rbp), %r13d
imulq %r14, %r13
cmpq %rax, %r13
jbe 0x570f4
movl %r13d, 0x1d8(%rbp)
movq 0x1d0(%rbp), %rdi
movl %r13d, %esi
callq 0x2370
movq %rax, 0x1d0(%rbp)
movq 0x1d0(%rbp), %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
movl 0x1e8(%rbp), %eax
cmpq %rax, %r14
jbe 0x57130
movl %r14d, 0x1e8(%rbp)
movq 0x1e0(%rbp), %rdi
movl %r14d, %esi
callq 0x2370
movq %rax, 0x1e0(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x57191
movq $-0x1, %rax
xorl %r14d, %r14d
movq $-0x1, %rcx
xorl %r13d, %r13d
movq (%rbp), %rdx
movl (%rdx,%r14), %esi
cmpq %rsi, %rcx
je 0x57180
testq %r13, %r13
je 0x57175
leaq (%rax,%rax,2), %rcx
leaq (%rdx,%rcx,8), %rsi
movq %r13, %rdx
subq %rax, %rdx
movq %rbp, %rdi
movq %r12, %r9
callq 0x50bb1
movq (%rbp), %rax
movl (%rax,%r14), %ecx
movq %r13, %rax
incq %r13
movl 0x10(%rbp), %edx
addq $0x18, %r14
cmpq %rdx, %r13
jb 0x5714a
jmp 0x5719b
movq $-0x1, %rax
xorl %r13d, %r13d
cmpq $-0x1, %rax
je 0x571be
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq (%rbp), %rsi
subq %rax, %r13
movq %rbp, %rdi
movq %r13, %rdx
movq %r12, %r9
callq 0x50bb1
movq %rbp, %rdi
movq %r15, %rsi
callq 0x51cf0
movq 0x8(%r12), %rsi
movq %r15, %rdi
movq %rbx, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5198e