// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamRandomAccessController_p.cpp
// Function: BamTools::Internal::BamRandomAccessController::SetRegion(BamTools::BamRegion const&, int const&)
bool BamRandomAccessController::SetRegion(const BamRegion& region, const int& referenceCount) {

    // store region
    m_region = region;

    // cannot jump when no index is available
    if ( !HasIndex() ) {
        SetErrorString("BamRandomAccessController", "cannot jump if no index data available");
        return false;
    }

    // adjust region as necessary to reflect where data actually begins
    AdjustRegion(referenceCount);

    // if no data present, return true
    //   * Not an error, but future attempts to access alignments in this region will not return data
    //     Returning true is useful in a BamMultiReader setting where some BAM files may
    //     lack alignments in regions where other files still have data available.
    if ( !m_hasAlignmentsInRegion )
        return true;

    // return success/failure of jump to specified region,
    //
    //  * Index::Jump() is allowed to modify the m_hasAlignmentsInRegion flag
    //    This covers 'corner case' where a region is requested that lies beyond the last
    //    alignment on a reference. If this occurs, any subsequent calls to GetNextAlignment[Core]
    //    will not return data. BamMultiReader will still be able to successfully pull alignments
    //    from a region from other files even if this one has no data.
    if ( !m_index->Jump(m_region, &m_hasAlignmentsInRegion) ) {
        const string indexError = m_index->GetErrorString();
        const string message = string("could not set region\n\t") + indexError;
        SetErrorString("BamRandomAccessController::OpenIndex", message);
        return false;
    }
    else
        return true;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movq %rsi, 0x120(%rsp)
movq %rdx, 0x118(%rsp)
movq 0x128(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq 0x120(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x8(%rdi)
movq 0x8(%rax), %rax
movq %rax, 0x10(%rdi)
callq 0x7bd50
testb $0x1, %al
jne 0xa94bc
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x41833(%rip), %rsi     # 0xeabd1
leaq 0xf8(%rsp), %rdi
callq 0x78e70
jmp 0xa93ad
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x41820(%rip), %rsi     # 0xeabeb
leaq 0xc0(%rsp), %rdi
callq 0x78e70
jmp 0xa93da
movq 0x20(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x71e80
jmp 0xa93f6
leaq 0xc0(%rsp), %rdi
callq 0x7cce8
jmp 0xa9405
leaq 0xbf(%rsp), %rdi
callq 0x76f80
leaq 0xf8(%rsp), %rdi
callq 0x7cce8
jmp 0xa9421
leaq 0xf7(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
jmp 0xa96ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0xa94aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0xa948c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x7cce8
jmp 0xa948a
jmp 0xa948c
leaq 0xbf(%rsp), %rdi
callq 0x76f80
leaq 0xf8(%rsp), %rdi
callq 0x7cce8
jmp 0xa94a8
jmp 0xa94aa
leaq 0xf7(%rsp), %rdi
callq 0x76f80
jmp 0xa96bd
movq 0x20(%rsp), %rdi
movq 0x118(%rsp), %rsi
callq 0x798b0
movq 0x20(%rsp), %rax
testb $0x1, 0x18(%rax)
jne 0xa94e6
movb $0x1, 0x137(%rsp)
jmp 0xa96ac
movq 0x20(%rsp), %rdx
movq (%rdx), %rdi
movq %rdx, %rsi
addq $0x8, %rsi
addq $0x18, %rdx
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0xa96a4
movq 0x20(%rsp), %rax
movq (%rax), %rsi
leaq 0x98(%rsp), %rdi
callq 0x7c320
leaq 0x57(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x416db(%rip), %rsi     # 0xeac12
leaq 0x58(%rsp), %rdi
callq 0x78e70
jmp 0xa9543
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x7c720
jmp 0xa955c
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xa9568
leaq 0x57(%rsp), %rdi
callq 0x76f80
leaq 0x2f(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x415fb(%rip), %rsi     # 0xeab86
leaq 0x30(%rsp), %rdi
callq 0x78e70
jmp 0xa9597
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x71e80
jmp 0xa95ad
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xa95b9
leaq 0x2f(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xa966c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0xa9612
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xa9610
jmp 0xa9612
leaq 0x57(%rsp), %rdi
callq 0x76f80
jmp 0xa9693
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0xa9656
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xa9654
jmp 0xa9656
leaq 0x2f(%rsp), %rdi
callq 0x76f80
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xa9691
leaq 0x98(%rsp), %rdi
callq 0x7cce8
jmp 0xa96ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0xa9693
jmp 0xa9693
leaq 0x98(%rsp), %rdi
callq 0x7cce8
jmp 0xa96a2
jmp 0xa96bd
movb $0x1, 0x137(%rsp)
movb 0x137(%rsp), %al
andb $0x1, %al
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xe8(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)
nopl (%rax)