// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: boundary_verify(unsigned int, unsigned int, ma_hit_t*, char*, char*, All_reads*)
int boundary_verify(uint32_t x_interval_s, uint32_t x_interval_e, ma_hit_t* map, 
char* x_buffer, char* y_buffer, All_reads* R_INF)
{
    uint32_t xs, ys, dir, x_id, y_id, x_interval_Len, y_interval_Len, y_interval_s, y_interval_e;
    dir = (*map).rev;
    xs = Get_qs((*map));
    x_id = Get_qn((*map));
    y_id = Get_tn((*map));
    long long yLen = Get_READ_LENGTH((*R_INF), y_id);

    if(dir == 1)
    {
        ys = yLen - (Get_te((*map)) - 1) - 1;         
    }
    else
    {
        ys = Get_ts((*map));
    }
    ///[x_interval_s, x_interval_e)
    x_interval_Len = x_interval_e - x_interval_s;

    ///[y_interval_s, y_interval_e]
    y_interval_s = (x_interval_s - xs) + ys;
    if(y_interval_s >= yLen)
    {
        return 0;
    }
    y_interval_e = y_interval_s + x_interval_Len - 1;
    if(y_interval_e >= yLen)
    {
        y_interval_e = yLen - 1;
    }

    if(y_interval_e < y_interval_s)
    {
        return 0;
    }
    
    y_interval_Len = y_interval_e - y_interval_s + 1;


    if(y_interval_Len <= WINDOW)
    {
        return verify_single_window(y_interval_s, y_interval_e, ys, xs, y_id, x_id, 
                                                        dir, y_buffer, x_buffer, R_INF);
    }
    else
    {
        
        if(verify_single_window(y_interval_s, y_interval_s + WINDOW - 1, ys, xs, y_id, x_id, 
                                                        dir, y_buffer, x_buffer, R_INF) == 0)
        {
            return 0;
        }

        if(verify_single_window(y_interval_e - WINDOW + 1, y_interval_e, ys, xs, y_id, x_id, 
                                                        dir, y_buffer, x_buffer, R_INF) == 0)
        {
            return 0;
        }

        return 1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r15
movq %r8, %r10
movq %rcx, %r11
movl %edi, %eax
movl 0x18(%rdx), %ebx
movq (%rdx), %rcx
movl 0xc(%rdx), %r12d
movq 0x18(%r9), %rdi
movq (%rdi,%r12,8), %r8
testl %ebx, %ebx
js 0xa2e7b
movl 0x10(%rdx), %edx
jmp 0xa2e83
movl 0x14(%rdx), %edi
movl %r8d, %edx
subl %edi, %edx
movl %eax, %edi
subl %ecx, %edi
addl %edx, %edi
xorl %ebp, %ebp
cmpq %rdi, %r8
jle 0xa2f53
notl %eax
addl %esi, %eax
addl %edi, %eax
leal -0x1(%r8), %r14d
cmpq %rax, %r8
cmoval %eax, %r14d
cmpl %edi, %r14d
jb 0xa2f53
movq %rcx, %r13
shrq $0x20, %r13
shrl $0x1f, %ebx
movl %r14d, %eax
subl %edi, %eax
incl %eax
cmpl $0x177, %eax            # imm = 0x177
ja 0xa2ee5
movl %r14d, %esi
movl %edx, %edx
movl %ecx, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq %r15
pushq %r11
pushq %r10
pushq %rbx
callq 0x4798f
addq $0x48, %rsp
jmp 0xa2f59
leal 0x176(%rdi), %esi
movl %edx, %edx
movl %ecx, %ecx
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movl %r12d, %r8d
movl %r13d, %r9d
pushq %r15
pushq %r11
pushq %r10
pushq %rbx
movq %r10, 0x30(%rsp)
movq %r11, 0x28(%rsp)
callq 0x4798f
addq $0x20, %rsp
testl %eax, %eax
je 0xa2f53
leal -0x176(%r14), %edi
movl %r14d, %esi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movl %r12d, %r8d
movl %r13d, %r9d
pushq %r15
pushq 0x10(%rsp)
pushq 0x20(%rsp)
pushq %rbx
callq 0x4798f
addq $0x20, %rsp
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq