// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
movl %edi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
cmpl $0x1, -0x44(%rbp)
jne 0xd185c
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x40(%rbp)
jmp 0xd1866
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x14(%rbp), %eax
subl -0x10(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x10(%rbp), %eax
subl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpq -0x68(%rbp), %rax
jl 0xd1890
movl $0x0, -0xc(%rbp)
jmp 0xd19de
movl -0x58(%rbp), %eax
addl -0x50(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpq -0x68(%rbp), %rax
jl 0xd18b0
movq -0x68(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jae 0xd18c4
movl $0x0, -0xc(%rbp)
jmp 0xd19de
movl -0x5c(%rbp), %eax
subl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x177, -0x54(%rbp)     # imm = 0x177
ja 0xd1923
movl -0x58(%rbp), %eax
movl %eax, %edi
movl -0x5c(%rbp), %eax
movl %eax, %esi
movl -0x40(%rbp), %eax
movl %eax, %edx
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movl -0x4c(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x44(%rbp), %ebx
movq -0x30(%rbp), %r11
movq -0x28(%rbp), %r10
movq -0x38(%rbp), %rax
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x323b0
movl %eax, -0xc(%rbp)
jmp 0xd19de
movl -0x58(%rbp), %eax
movl %eax, %edi
movl -0x58(%rbp), %eax
addl $0x177, %eax            # imm = 0x177
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movl -0x40(%rbp), %eax
movl %eax, %edx
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movl -0x4c(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x44(%rbp), %ebx
movq -0x30(%rbp), %r11
movq -0x28(%rbp), %r10
movq -0x38(%rbp), %rax
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x323b0
cmpl $0x0, %eax
jne 0xd197d
movl $0x0, -0xc(%rbp)
jmp 0xd19de
movl -0x5c(%rbp), %eax
subl $0x177, %eax            # imm = 0x177
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
movl -0x5c(%rbp), %eax
movl %eax, %esi
movl -0x40(%rbp), %eax
movl %eax, %edx
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movl -0x4c(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x44(%rbp), %ebx
movq -0x30(%rbp), %r11
movq -0x28(%rbp), %r10
movq -0x38(%rbp), %rax
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x323b0
cmpl $0x0, %eax
jne 0xd19d7
movl $0x0, -0xc(%rbp)
jmp 0xd19de
movl $0x1, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)