// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: get_available_interval(long long, long long, overlap_region_alloc*, Correct_dumy*)
inline int get_available_interval(long long window_start, long long window_end, overlap_region_alloc* overlap_list, Correct_dumy* dumy)
{
    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;

    
    long long fake_length = 0;

    for (; i < overlap_list->length; i++)
    {
        ///check if the interval is overlapped with current overlap   
        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)
        {
            ///number of overlaps
            fake_length++;

            ///check if this overlap is available
            if (overlap_list->list[i].is_match == 1)
            {
                dumy->overlapID[dumy->length] = i;
                dumy->length++; 
            }
            if(fud == 0) fud = 1, dumy->start_i = i;
        }
        
        if((long long)overlap_list->list[i].x_pos_s > window_end)
        {
            break;
        }
    }

    ///fake_length is the number of overlaps, instead of the number of available overlaps
    if (fake_length == 0)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

// Assembly:
testq %rdi, %rdi
je 0x530db
movq 0x48(%rcx), %rax
jmp 0x530e2
andq $0x0, 0x48(%rcx)
xorl %eax, %eax
movq 0x10(%rdx), %r8
cmpq %r8, %rax
jae 0x53119
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq (%rdx), %r8
imulq $0xa8, %rax, %r9
movl 0x4(%r8,%r9), %r10d
cmpq %rsi, %r10
jle 0x5312a
andq $0x0, 0x48(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
xorl %eax, %eax
jmp 0x531ad
movq %r8, 0x48(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
retq
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rcx)
addq %r9, %r8
addq $0x4, %r8
xorl %r10d, %r10d
movabsq $0x1, %r11
xorl %ebx, %ebx
xorl %r9d, %r9d
cmpq 0x10(%rdx), %rax
jae 0x531a5
movl (%r8), %r14d
movl 0x4(%r8), %r15d
cmpq %rsi, %r15
cmovaeq %rsi, %r15
cmpq %rdi, %r14
movq %rdi, %r12
cmovgq %r14, %r12
cmpq %r12, %r15
jb 0x53196
cmpb $0x1, 0x28(%r8)
jne 0x53187
movq 0x28(%rcx), %r15
movq %rax, (%r15,%r10,8)
movq 0x30(%rcx), %r10
incq %r10
movq %r10, 0x30(%rcx)
incq %r9
testq %rbx, %rbx
jne 0x53193
movq %rax, 0x48(%rcx)
movq %r11, %rbx
incq %rax
addq $0xa8, %r8
cmpq %rsi, %r14
jle 0x5314a
xorl %eax, %eax
testq %r9, %r9
setne %al
popq %rbx
popq %r12
popq %r14
popq %r15
retq