// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x27b00
testb %al, %al
je 0x39c03
movq %r14, %rdi
movq %r15, %rsi
callq 0x28f00
testq %rax, %rax
je 0x39c74
movq %rax, %r15
movq (%rax), %rax
movq %r15, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x39d3c
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x39bf9
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, (%rbx)
movb $0x1, %al
jmp 0x39dd4
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1bcb1(%rip), %rsi     # 0x558c4
leaq 0x1bcd0(%rip), %rdx     # 0x558ea
leaq 0x40(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1bcb7(%rip), %rsi     # 0x558eb
leaq 0x1bcd7(%rip), %rdx     # 0x55912
movq %rsp, %rdi
callq 0x26750
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x263b0
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x39c61
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
jne 0x39dcd
jmp 0x39dd2
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1c20a(%rip), %rdx     # 0x55e8f
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x28740
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39cb0
callq 0x27560
leaq 0x50(%rsp), %r15
leaq 0x1bc57(%rip), %rsi     # 0x55913
movl $0x20, %edx
movq %r15, %rdi
callq 0x27a70
movl (%r14), %esi
movq %r15, %rdi
callq 0x28a90
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x1bbe3(%rip), %rsi     # 0x558c4
leaq 0x1bc02(%rip), %rdx     # 0x558ea
callq 0x26750
leaq 0x58(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x28730
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x263b0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39d1f
callq 0x27560
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39d2d
callq 0x27560
leaq 0x40(%rsp), %rdi
callq 0x270d0
jmp 0x39dd2
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x267c0
leaq 0x1bbcf(%rip), %rsi     # 0x55934
movq %rsp, %rdi
movq %r14, %rdx
callq 0x273f0
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1bb44(%rip), %rsi     # 0x558c4
leaq 0x1bb63(%rip), %rdx     # 0x558ea
leaq 0x20(%rsp), %rdi
callq 0x26750
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x263b0
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x39db0
callq 0x27560
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39dc3
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x39dd2
callq 0x27560
xorl %eax, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x39dfa
callq 0x27560
jmp 0x39dfa
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39e12
callq 0x27560
jmp 0x39e12
movq %rax, %rbx
movq 0x40(%rsp), %rdi
jmp 0x39e4d
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39e34
callq 0x27560
jmp 0x39e34
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39e59
callq 0x27560
jmp 0x39e59
jmp 0x39e56
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x39e8d
jmp 0x39e97
jmp 0x39e94
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x270d0
jmp 0x39e97
movq %rax, %rdi
callq 0x2f047
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x39e83
callq 0x27560
jmp 0x39e83
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x39e97
callq 0x27560
jmp 0x39e97
movq %rax, %rbx
movq %rbx, %rdi
callq 0x28c10
nop