// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: get_interval(long long, long long, overlap_region_alloc*, Correct_dumy*, long long)
inline int get_interval(long long window_start, long long window_end, overlap_region_alloc* overlap_list, Correct_dumy* dumy, long long blockLen)
{
    uint64_t i, fud = 0;
    long long Len;
    if(window_start == 0) dumy->start_i = 0;
    for (i = dumy->start_i; i < overlap_list->length; i++)
    {
        ///this interval is smaller than all overlaps
        ///in this case, the next interval should start from 0
        if (window_end < (long long)overlap_list->list[i].x_pos_s)
        {
            dumy->start_i = 0;
            dumy->length = 0;
            dumy->lengthNT = 0;
            return 0;
        }
        else ///if window_end >= overlap_list->list[i].x_pos_s，this overlap might be overlapped with current interval
        {
            dumy->start_i = i;
            break;
        }
    }


    ///this interval is larger than all overlaps, so we don't need to scan next overlap
    if (i >= overlap_list->length)
    {
        dumy->start_i = overlap_list->length;
        dumy->length = 0;
        dumy->lengthNT = 0;
        return -2;
    }
    
    dumy->length = 0;
    dumy->lengthNT = 0;
    fud = 0;

    for (; i < overlap_list->length; i++)
    {
        if((Len = OVERLAP(window_start, window_end, (long long)overlap_list->list[i].x_pos_s, (long long)overlap_list->list[i].x_pos_e)) > 0)
        {
            ///sometimes the length of window > WINDOW, but overlap length == WINDOW
            // if (Len == WINDOW && window_end - window_start + 1 == WINDOW)
            if (Len == blockLen && window_end - window_start + 1 == blockLen)
            {
                dumy->overlapID[dumy->length] = i;
                dumy->length++; 
            }
            else
            {
                dumy->lengthNT++;
                dumy->overlapID[dumy->size - dumy->lengthNT] = i;
            }
            if(fud == 0) fud = 1, dumy->start_i = i;
        }
        
        if((long long)overlap_list->list[i].x_pos_s > window_end)
        {
            break;
        }
    }

    if ( dumy->length + dumy->lengthNT == 0)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

// Assembly:
testq %rdi, %rdi
je 0x52786
movq 0x48(%rcx), %rax
jmp 0x5278d
andq $0x0, 0x48(%rcx)
xorl %eax, %eax
movq 0x10(%rdx), %r9
cmpq %r9, %rax
jae 0x527c6
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdx), %r10
imulq $0xa8, %rax, %r11
movl 0x4(%r10,%r11), %r9d
cmpq %rsi, %r9
jle 0x527d7
andq $0x0, 0x48(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
xorl %eax, %eax
jmp 0x52881
movq %r9, 0x48(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
retq
movq %rsi, %r9
subq %rdi, %r9
incq %r9
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
addq %r11, %r10
addq $0x8, %r10
xorl %ebx, %ebx
movabsq $0x1, %r11
cmpq 0x10(%rdx), %rax
jae 0x52874
movl -0x4(%r10), %r14d
movl (%r10), %r15d
cmpq %rsi, %r15
cmovaeq %rsi, %r15
cmpq %rdi, %r14
movq %rdi, %r12
cmovgq %r14, %r12
subq %r12, %r15
js 0x52865
incq %r15
cmpq %r8, %r15
jne 0x5283c
cmpq %r8, %r9
jne 0x5283c
movq 0x28(%rcx), %r15
movq 0x30(%rcx), %r12
movq %rax, (%r15,%r12,8)
incq 0x30(%rcx)
jmp 0x52856
movq 0x28(%rcx), %r15
movq 0x38(%rcx), %r12
incq %r12
movq %r12, 0x38(%rcx)
movq 0x40(%rcx), %r13
subq %r12, %r13
movq %rax, (%r15,%r13,8)
testq %rbx, %rbx
movq %r11, %rbx
jne 0x52865
movq %rax, 0x48(%rcx)
movq %r11, %rbx
incq %rax
addq $0xa8, %r10
cmpq %rsi, %r14
jle 0x527fa
movq 0x30(%rcx), %rdx
xorl %eax, %eax
addq 0x38(%rcx), %rdx
setne %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq