// File: zeeev[P]DASVC/bamtools/src/api/internal/index/BamStandardIndex_p.cpp
// Function: BamTools::Internal::BamStandardIndex::AdjustRegion(BamTools::BamRegion const&, unsigned int&, unsigned int&)
void BamStandardIndex::AdjustRegion(const BamRegion& region, uint32_t& begin, uint32_t& end) {

    // retrieve references from reader
    const RefVector& references = m_reader->GetReferenceData();

    // LeftPosition cannot be greater than or equal to reference length
    if ( region.LeftPosition >= references.at(region.LeftRefID).RefLength )
        throw BamException("BamStandardIndex::AdjustRegion", "invalid region requested");

    // set region 'begin'
    begin = (unsigned int)region.LeftPosition;

    // if right bound specified AND left&right bounds are on same reference
    // OK to use right bound position as region 'end'
    if ( region.isRightBoundSpecified() && ( region.LeftRefID == region.RightRefID ) )
        end = (unsigned int)region.RightPosition;

    // otherwise, set region 'end' to last reference base
    else end = (unsigned int)references.at(region.LeftRefID).RefLength;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq 0xa0(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x77d80
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x80(%rsp), %rdi
movq 0x98(%rsp), %rax
movslq (%rax), %rsi
callq 0x7aa10
movq %rax, %rcx
movl 0x20(%rsp), %eax
cmpl 0x20(%rcx), %eax
jl 0xb0d27
movb $0x1, 0x26(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x10(%rsp)
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x3a497(%rip), %rsi     # 0xeb0dd
leaq 0x60(%rsp), %rdi
callq 0x78e70
jmp 0xb0c52
leaq 0x27(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x3aca6(%rip), %rsi     # 0xeb913
leaq 0x28(%rsp), %rdi
callq 0x78e70
jmp 0xb0c79
movq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x79cd0
jmp 0xb0c8f
movq 0x10(%rsp), %rdi
movb $0x0, 0x26(%rsp)
movq 0x61270(%rip), %rsi     # 0x111f10
movq 0x612b9(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xb0dbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0xb0d05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0xb0ced
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x7cce8
jmp 0xb0ceb
jmp 0xb0ced
leaq 0x27(%rsp), %rdi
callq 0x76f80
leaq 0x60(%rsp), %rdi
callq 0x7cce8
jmp 0xb0d03
jmp 0xb0d05
leaq 0x5f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x26(%rsp)
jne 0xb0d18
jmp 0xb0d22
movq 0x10(%rsp), %rdi
callq 0x74e00
jmp 0xb0daa
movq 0x98(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x90(%rsp), %rax
movl %ecx, (%rax)
movq 0x98(%rsp), %rdi
callq 0x77110
testb $0x1, %al
jne 0xb0d4f
jmp 0xb0d7d
movq 0x98(%rsp), %rax
movl (%rax), %eax
movq 0x98(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xb0d7d
movq 0x98(%rsp), %rax
movl 0xc(%rax), %ecx
movq 0x88(%rsp), %rax
movl %ecx, (%rax)
jmp 0xb0da2
movq 0x80(%rsp), %rdi
movq 0x98(%rsp), %rax
movslq (%rax), %rsi
callq 0x7aa10
movl 0x20(%rax), %ecx
movq 0x88(%rsp), %rax
movl %ecx, (%rax)
addq $0xa8, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)