// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamRandomAccessController_p.cpp
// Function: BamTools::Internal::BamRandomAccessController::AlignmentState(BamTools::BamAlignment const&) const
BamRandomAccessController::RegionState
BamRandomAccessController::AlignmentState(const BamAlignment& alignment) const {

    // if region has no left bound at all
    if ( !m_region.isLeftBoundSpecified() )
        return OverlapsRegion;

    // handle unmapped reads - return AFTER region to halt processing
    if ( alignment.RefID == -1 )
        return AfterRegion;

    // if alignment is on any reference before left bound reference
    if ( alignment.RefID < m_region.LeftRefID )
        return BeforeRegion;

    // if alignment is on left bound reference
    else if ( alignment.RefID == m_region.LeftRefID ) {

        // if alignment starts at or after left bound position
        if ( alignment.Position >= m_region.LeftPosition) {

            if ( m_region.isRightBoundSpecified() &&             // right bound is specified AND
                 m_region.LeftRefID == m_region.RightRefID &&    // left & right bounds on same reference AND
                 alignment.Position >= m_region.RightPosition )  // alignment starts on or after right bound position
                return AfterRegion;

            // otherwise, alignment overlaps region
            else return OverlapsRegion;
        }

        // alignment starts before left bound position
        else {

            // if alignment overlaps left bound position
            if ( alignment.GetEndPosition() > m_region.LeftPosition )
                return OverlapsRegion;
            else
                return BeforeRegion;
        }
    }

    // otherwise alignment is on a reference after left bound reference
    else {

        // if region has a right bound
        if ( m_region.isRightBoundSpecified() ) {

            // alignment is on any reference between boundaries
            if ( alignment.RefID < m_region.RightRefID )
                return OverlapsRegion;

            // alignment is on any reference after right boundary
            else if ( alignment.RefID > m_region.RightRefID )
                return AfterRegion;

            // alignment is on right bound reference
            else {

                // if alignment starts before right bound position
                if ( alignment.Position < m_region.RightPosition )
                    return OverlapsRegion;
                else
                    return AfterRegion;
            }
        }

        // otherwise, alignment starts after left bound and there is no right bound given
        else return OverlapsRegion;
    }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x8(%rsp)
addq $0x8, %rdi
callq 0x732d0
testb $0x1, %al
jne 0xa8252
movl $0x1, 0x24(%rsp)
jmp 0xa83c2
movq 0x10(%rsp), %rax
cmpl $-0x1, 0xa8(%rax)
jne 0xa826d
movl $0x2, 0x24(%rsp)
jmp 0xa83c2
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xa8(%rax), %eax
cmpl 0x8(%rcx), %eax
jge 0xa828f
movl $0x0, 0x24(%rsp)
jmp 0xa83c2
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xa8(%rax), %eax
cmpl 0x8(%rcx), %eax
jne 0xa833f
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xac(%rax), %eax
cmpl 0xc(%rcx), %eax
jl 0xa830d
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
callq 0x77110
testb $0x1, %al
jne 0xa82d1
jmp 0xa8300
movq 0x8(%rsp), %rcx
movl 0x8(%rcx), %eax
cmpl 0x10(%rcx), %eax
jne 0xa8300
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xac(%rax), %eax
cmpl 0x14(%rcx), %eax
jl 0xa8300
movl $0x2, 0x24(%rsp)
jmp 0xa83c2
movl $0x1, 0x24(%rsp)
jmp 0xa83c2
movq 0x10(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x76240
movq 0x8(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jle 0xa8332
movl $0x1, 0x24(%rsp)
jmp 0xa83c2
movl $0x0, 0x24(%rsp)
jmp 0xa83c2
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
callq 0x77110
testb $0x1, %al
jne 0xa8353
jmp 0xa83ba
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xa8(%rax), %eax
cmpl 0x10(%rcx), %eax
jge 0xa8372
movl $0x1, 0x24(%rsp)
jmp 0xa83c2
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xa8(%rax), %eax
cmpl 0x10(%rcx), %eax
jle 0xa8391
movl $0x2, 0x24(%rsp)
jmp 0xa83c2
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movl 0xac(%rax), %eax
cmpl 0x14(%rcx), %eax
jge 0xa83b0
movl $0x1, 0x24(%rsp)
jmp 0xa83c2
movl $0x2, 0x24(%rsp)
jmp 0xa83c2
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopl (%rax,%rax)