// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamRandomAccessController_p.cpp
// Function: BamTools::Internal::BamRandomAccessController::CreateIndex(BamTools::Internal::BamReaderPrivate*, BamTools::BamIndex::IndexType const&)
bool BamRandomAccessController::CreateIndex(BamReaderPrivate* reader,
                                            const BamIndex::IndexType& type)
{
    // skip if reader is invalid
    assert(reader);
    if ( !reader->IsOpen() ) {
        SetErrorString("BamRandomAccessController::CreateIndex",
                       "cannot create index for unopened reader");
        return false;
    }

    // create new index of requested type
    BamIndex* newIndex = BamIndexFactory::CreateIndexOfType(type, reader);
    if ( newIndex == 0 ) {
        stringstream s("");
        s << "could not create index of type: " << type;
        SetErrorString("BamRandomAccessController::CreateIndex", s.str());
        return false;
    }

    // attempt to build index from current BamReader file
    if ( !newIndex->Create() ) {
        const string indexError = newIndex->GetErrorString();
        const string message = "could not create index: \n\t" + indexError;
        SetErrorString("BamRandomAccessController::CreateIndex", message);
        return false;
    }

    // save new index & return success
    SetIndex(newIndex);
    return true;
}

// Assembly:
subq $0x338, %rsp            # imm = 0x338
movq %rdi, 0x328(%rsp)
movq %rsi, 0x320(%rsp)
movq %rdx, 0x318(%rsp)
movq 0x328(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x320(%rsp), %rdi
callq 0x77980
testb $0x1, %al
jne 0xa85cd
leaq 0x2f7(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x7b5f0
movq 0x40(%rsp), %rdx
leaq 0x425ea(%rip), %rsi     # 0xeaa99
leaq 0x2f8(%rsp), %rdi
callq 0x78e70
jmp 0xa84be
leaq 0x2bf(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x7b5f0
movq 0x38(%rsp), %rdx
leaq 0x425e4(%rip), %rsi     # 0xeaac0
leaq 0x2c0(%rsp), %rdi
callq 0x78e70
jmp 0xa84eb
movq 0x48(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
leaq 0x2c0(%rsp), %rdx
callq 0x71e80
jmp 0xa8507
leaq 0x2c0(%rsp), %rdi
callq 0x7cce8
jmp 0xa8516
leaq 0x2bf(%rsp), %rdi
callq 0x76f80
leaq 0x2f8(%rsp), %rdi
callq 0x7cce8
jmp 0xa8532
leaq 0x2f7(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x337(%rsp)
jmp 0xa897d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa85bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa859d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
leaq 0x2c0(%rsp), %rdi
callq 0x7cce8
jmp 0xa859b
jmp 0xa859d
leaq 0x2bf(%rsp), %rdi
callq 0x76f80
leaq 0x2f8(%rsp), %rdi
callq 0x7cce8
jmp 0xa85b9
jmp 0xa85bb
leaq 0x2f7(%rsp), %rdi
callq 0x76f80
jmp 0xa898e
movq 0x318(%rsp), %rdi
movq 0x320(%rsp), %rsi
callq 0x7bf10
movq %rax, 0x2b0(%rsp)
cmpq $0x0, 0x2b0(%rsp)
jne 0xa882e
leaq 0x107(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x42ac5(%rip), %rsi     # 0xeb0dc
leaq 0x108(%rsp), %rdi
callq 0x78e70
jmp 0xa8626
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0x2c(%rsp)
jmp 0xa863b
movl 0x2c(%rsp), %edx
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x7a4b0
jmp 0xa8656
leaq 0x108(%rsp), %rdi
callq 0x7cce8
jmp 0xa8665
leaq 0x107(%rsp), %rdi
callq 0x76f80
leaq 0x138(%rsp), %rdi
leaq 0x42467(%rip), %rsi     # 0xeaae8
callq 0x768e0
movq %rax, 0x20(%rsp)
jmp 0xa868d
movq 0x20(%rsp), %rdi
movq 0x318(%rsp), %rax
movl (%rax), %esi
callq 0x7b150
jmp 0xa86a3
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x423d8(%rip), %rsi     # 0xeaa99
leaq 0xe0(%rsp), %rdi
callq 0x78e70
jmp 0xa86d0
leaq 0xb8(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x76880
jmp 0xa86e7
movq 0x48(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x71e80
jmp 0xa8703
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xa8712
leaq 0xe0(%rsp), %rdi
callq 0x7cce8
jmp 0xa8721
leaq 0xdf(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x337(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x74f60
jmp 0xa897d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa8783
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x7cce8
jmp 0xa8781
jmp 0xa8783
leaq 0x107(%rsp), %rdi
callq 0x76f80
jmp 0xa898e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa881a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa880d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa87fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xa87fa
jmp 0xa87fc
leaq 0xe0(%rsp), %rdi
callq 0x7cce8
jmp 0xa880b
jmp 0xa880d
leaq 0xdf(%rsp), %rdi
callq 0x76f80
leaq 0x128(%rsp), %rdi
callq 0x74f60
jmp 0xa8829
jmp 0xa898e
movq 0x2b0(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
testb $0x1, %al
jne 0xa8963
movq 0x2b0(%rsp), %rsi
leaq 0x98(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7c320
movq 0x10(%rsp), %rdx
leaq 0x4229f(%rip), %rsi     # 0xeab09
leaq 0x78(%rsp), %rdi
callq 0x75e70
jmp 0xa8876
leaq 0x57(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x42208(%rip), %rsi     # 0xeaa99
leaq 0x58(%rsp), %rdi
callq 0x78e70
jmp 0xa889d
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x71e80
jmp 0xa88b3
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xa88bf
leaq 0x57(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x337(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xa8941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa8952
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
jmp 0xa892b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2e8(%rsp)
movl %eax, 0x2e4(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xa8929
jmp 0xa892b
leaq 0x57(%rsp), %rdi
callq 0x76f80
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xa8950
leaq 0x98(%rsp), %rdi
callq 0x7cce8
jmp 0xa897d
jmp 0xa8952
leaq 0x98(%rsp), %rdi
callq 0x7cce8
jmp 0xa8961
jmp 0xa898e
movq 0x48(%rsp), %rdi
movq 0x2b0(%rsp), %rsi
callq 0x77bf0
movb $0x1, 0x337(%rsp)
movb 0x337(%rsp), %al
andb $0x1, %al
addq $0x338, %rsp            # imm = 0x338
retq
movq 0x2e8(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)