// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/api/internal/bam/BamMultiReader_p.cpp
// Function: BamTools::Internal::BamMultiReaderPrivate::CreateAlignmentCache()
IMultiMerger* BamMultiReaderPrivate::CreateAlignmentCache(void) {

    // if no merge order set explicitly, use SAM header to lookup proper order
    if ( !m_hasUserMergeOrder ) {

        // fetch SamHeader from BAM files
        SamHeader header = GetHeader();

        // if BAM files are sorted by position
        if ( header.SortOrder == Constants::SAM_HD_SORTORDER_COORDINATE )
            m_mergeOrder = BamMultiReader::MergeByCoordinate;

        // if BAM files are sorted by read name
        else if ( header.SortOrder == Constants::SAM_HD_SORTORDER_QUERYNAME )
            m_mergeOrder = BamMultiReader::MergeByName;

        // otherwise, sorting is either "unknown" or marked as "unsorted"
        else
            m_mergeOrder = BamMultiReader::RoundRobinMerge;
    }

    // use current merge order to create proper 'multi-merger'
    switch ( m_mergeOrder ) {

        // merge BAM files by position
        case BamMultiReader::MergeByCoordinate :
            return new MultiMerger<Algorithms::Sort::ByPosition>();

        // merge BAM files by read name
        case BamMultiReader::MergeByName :
            return new MultiMerger<Algorithms::Sort::ByName>();

        // sorting is "unknown", "unsorted" or "ignored"... so use unsorted merger
        case BamMultiReader::RoundRobinMerge :
            return new MultiMerger<Algorithms::Sort::Unsorted>();

        // unknown merge order, can't create merger
        default:
            return 0;
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rdi, %rbx
cmpb $0x0, 0x20(%rdi)
jne 0x35ca1
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26ba0
movq 0x28(%r14), %r14
cmpq 0x37785(%rip), %r14     # 0x6d3c8
jne 0x35c67
movl $0x1, %ebp
testq %r14, %r14
je 0x35c94
movq 0x3776a(%rip), %rsi     # 0x6d3c0
movq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x277e0
testl %eax, %eax
je 0x35c94
cmpq 0x3777a(%rip), %r14     # 0x6d3e8
jne 0x35c92
movl $0x2, %ebp
testq %r14, %r14
je 0x35c94
movq 0x3775f(%rip), %rsi     # 0x6d3e0
movq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x277e0
testl %eax, %eax
je 0x35c94
xorl %ebp, %ebp
movl %ebp, 0x24(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x275d0
movl 0x24(%rbx), %eax
testl %eax, %eax
je 0x35cf8
cmpl $0x1, %eax
je 0x35cbf
cmpl $0x2, %eax
jne 0x35d37
movq 0x352eb(%rip), %r14     # 0x6afa8
jmp 0x35cc6
movq 0x35282(%rip), %r14     # 0x6af48
addq $0x10, %r14
movl $0x38, %edi
callq 0x276b0
movq %rax, %rbx
movq %r14, (%rax)
xorl %eax, %eax
movl %eax, 0x8(%rbx)
leaq 0x10(%rbx), %rcx
movl %eax, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq %rcx, 0x20(%rbx)
movq %rcx, 0x28(%rbx)
movq %rax, 0x30(%rbx)
jmp 0x35d39
movl $0x58, %edi
callq 0x276b0
movq %rax, %rbx
movq 0x351e4(%rip), %rax     # 0x6aef0
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x28(%rbx)
movups %xmm0, 0x38(%rbx)
movups %xmm0, 0x48(%rbx)
xorl %esi, %esi
callq 0x277d0
jmp 0x35d39
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x27560
movq %r14, %rdi
callq 0x28c10
nop