// File: chhylp123[P]hifiasm/Correct.cpp
// Function: lable_large_indels(overlap_region_alloc*, long long, Correct_dumy*, double)
void lable_large_indels(overlap_region_alloc* overlap_list, long long read_length, Correct_dumy* dumy, double max_ov_diff_ec)
{
    long long i, j, c_i, c_n; uint32_t operLen; uint8_t oper;
    int is_delete = 0; window_list *c_idx;
    for (i = 0; i < (long long)overlap_list->length; i++)
    {
        ///should has at least 3 windows for this overlap
        if (overlap_list->list[i].is_match == 1 && overlap_list->list[i].w_list.n >= 3)
        {
            ///here w_list_length >= 3
            ///skip the first and last window
            for (j = 1; j + 1 < (long long)(overlap_list->list[i].w_list.n); j++)
            {
                ///this window is not matched, it seems to have large difference
                if(overlap_list->list[i].w_list.a[j].y_end == -1)
                {
                    overlap_list->list[i].is_match = 100;
                    is_delete = 1;
                    goto end_rem;
                }

                c_idx = &(overlap_list->list[i].w_list.a[j]);
                c_n = c_idx->clen;
                ///if there are <=2 cigar elements, skip it
                if(c_n < 3) continue;

                ///skip the first and last cigar elements
                for (c_i = 1; c_i + 1 < c_n; c_i++)
                {
                    get_cigar_cell(c_idx, &(overlap_list->list[i].w_list), c_i, &oper, &operLen);
                    
                    
                    if(operLen <= 5)
                    {
                        continue;
                    }
                    ///>=6 bp deletion or insertion 
                    if(oper == 2 || oper == 3)
                    {
                        overlap_list->list[i].is_match = 100;
                        is_delete = 1;
                        goto end_rem;
                    }
                }
            }
        }

        end_rem:;
    }


    if(is_delete == 1)
    {
        long long window_start, window_end;
        Window_Pool w_inf;
        init_Window_Pool(&w_inf, read_length, WINDOW, (int)(1.0/max_ov_diff_ec));
        int flag = 0;
        long long realLen = 0, realLen_100 = 0;
        int to_recover = 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_fully_covered_interval(window_start, window_end, 
            overlap_list, dumy, &realLen, &realLen_100);


            switch (flag)
            {
                case 1:    ///match
                    break;
                case 0:    ///unmatch
                    break;
                case -2: ///unmatch, and the next window also cannot match
                    break;
            }

            ///it seems there is a long indel at the reference read itself
            if(realLen == 0 && realLen_100 > 0)
            {
                to_recover = 1;
                break;
            }
        }

        if(to_recover == 1)
        {
            for (i = 0; i < (long long)overlap_list->length; i++)
            {
                if (overlap_list->list[i].is_match == 100)
                {
                    overlap_list->list[i].is_match = 1;
                }
            }
        }
    }


    for (i = is_delete = 0; i < (long long)(overlap_list->length); i++)
    {
        if (overlap_list->list[i].is_match == 1)
        {
            overlap_list->list[i].without_large_indel = 1;
            is_delete++;
        }

        if (overlap_list->list[i].is_match == 100)
        {
            overlap_list->list[i].is_match = 1;
            overlap_list->list[i].without_large_indel = 0;
            is_delete++;
        }
    }

    // if(is_delete) radix_sort_overlap_region_dp_srt(overlap_list->list, overlap_list->list+overlap_list->length);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x3f843
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x3f82e
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpq $0x3, 0x48(%rax)
jb 0x3f82e
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpq 0x48(%rcx), %rax
jge 0x3f82c
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x3f74e
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x64, 0x2c(%rax)
movl $0x1, -0x4c(%rbp)
jmp 0x3f830
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jge 0x3f78a
jmp 0x3f81b
movq $0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x40(%rbp), %rax
jge 0x3f819
movq -0x58(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x28(%rbp), %rax
addq %rax, %rsi
addq $0x48, %rsi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq -0x45(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x2c960
cmpl $0x5, -0x44(%rbp)
ja 0x3f7d5
jmp 0x3f808
movzbl -0x45(%rbp), %eax
cmpl $0x2, %eax
je 0x3f7e7
movzbl -0x45(%rbp), %eax
cmpl $0x3, %eax
jne 0x3f806
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x64, 0x2c(%rax)
movl $0x1, -0x4c(%rbp)
jmp 0x3f830
jmp 0x3f808
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3f792
jmp 0x3f81b
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3f6e1
jmp 0x3f82e
jmp 0x3f830
jmp 0x3f832
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3f68b
cmpl $0x1, -0x4c(%rbp)
jne 0x3f9de
movq -0x10(%rbp), %rsi
movsd 0x3427a7(%rip), %xmm0   # 0x382000
divsd -0x20(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movslq %eax, %rcx
leaq -0xa0(%rbp), %rdi
movl $0x177, %edx            # imm = 0x177
callq 0x9f470
movl $0x0, -0xa4(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x9f520
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xbd(%rbp)
je 0x3f8d3
cmpl $-0x2, -0xa4(%rbp)
setne %al
movb %al, -0xbd(%rbp)
movb -0xbd(%rbp), %al
testb $0x1, %al
jne 0x3f8e2
jmp 0x3f97a
movq -0x18(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0xb0(%rbp), %r8
leaq -0xb8(%rbp), %r9
callq 0xa0c10
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xc4(%rbp)
subl $-0x2, %eax
je 0x3f953
jmp 0x3f936
movl -0xc4(%rbp), %eax
testl %eax, %eax
je 0x3f951
jmp 0x3f942
movl -0xc4(%rbp), %eax
subl $0x1, %eax
jne 0x3f955
jmp 0x3f94f
jmp 0x3f955
jmp 0x3f955
jmp 0x3f955
cmpq $0x0, -0xb0(%rbp)
jne 0x3f975
cmpq $0x0, -0xb8(%rbp)
jle 0x3f975
movl $0x1, -0xbc(%rbp)
jmp 0x3f97a
jmp 0x3f8a0
cmpl $0x1, -0xbc(%rbp)
jne 0x3f9dc
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x3f9da
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x64, %eax
jne 0x3f9ca
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2c(%rax)
jmp 0x3f9cc
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3f98b
jmp 0x3f9dc
jmp 0x3f9de
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x3fa9c
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
jne 0x3fa39
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2d(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl $0x64, %eax
jne 0x3fa89
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x2c(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb $0x0, 0x2d(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3fa8b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3f9ed
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)