// File: /workspace/github_cpp_makefile_star2_O1/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 0x39c82
movq %r14, %rdi
movq %r15, %rsi
callq 0x28f10
testq %rax, %rax
je 0x39cf3
movq %rax, %r15
movq (%rax), %rax
movq %r15, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x39dbb
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x39c78
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, (%rbx)
movq %r15, (%rbx)
movb $0x1, %al
jmp 0x39e53
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1bc32(%rip), %rsi     # 0x558c4
leaq 0x1bc51(%rip), %rdx     # 0x558ea
leaq 0x40(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1bc38(%rip), %rsi     # 0x558eb
leaq 0x1bc58(%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 0x39ce0
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
jne 0x39e4c
jmp 0x39e51
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1c18b(%rip), %rdx     # 0x55e8f
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x28750
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39d2f
callq 0x27560
leaq 0x50(%rsp), %r15
leaq 0x1bbd8(%rip), %rsi     # 0x55913
movl $0x20, %edx
movq %r15, %rdi
callq 0x27a70
movl (%r14), %esi
movq %r15, %rdi
callq 0x28aa0
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x1bb64(%rip), %rsi     # 0x558c4
leaq 0x1bb83(%rip), %rdx     # 0x558ea
callq 0x26750
leaq 0x58(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x28740
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x263b0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39d9e
callq 0x27560
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39dac
callq 0x27560
leaq 0x40(%rsp), %rdi
callq 0x270d0
jmp 0x39e51
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 0x1bb50(%rip), %rsi     # 0x55934
movq %rsp, %rdi
movq %r14, %rdx
callq 0x273f0
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1bac5(%rip), %rsi     # 0x558c4
leaq 0x1bae4(%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 0x39e2f
callq 0x27560
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39e42
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x39e51
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 0x39e79
callq 0x27560
jmp 0x39e79
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39e91
callq 0x27560
jmp 0x39e91
movq %rax, %rbx
movq 0x40(%rsp), %rdi
jmp 0x39ecc
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39eb3
callq 0x27560
jmp 0x39eb3
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x39ed8
callq 0x27560
jmp 0x39ed8
jmp 0x39ed5
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x39f0c
jmp 0x39f16
jmp 0x39f13
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x270d0
jmp 0x39f16
movq %rax, %rdi
callq 0x2f0bd
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x39f02
callq 0x27560
jmp 0x39f02
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x39f16
callq 0x27560
jmp 0x39f16
movq %rax, %rbx
movq %rbx, %rdi
callq 0x28c20