// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/api/internal/bam/BamMultiReader_p.cpp
// Function: BamTools::Internal::BamMultiReaderPrivate::CloseFiles(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
bool BamMultiReaderPrivate::CloseFiles(const vector<string>& filenames) {

    bool errorsEncountered = false;
    m_errorString.clear();

    // iterate over filenames
    vector<string>::const_iterator filesIter = filenames.begin();
    vector<string>::const_iterator filesEnd  = filenames.end();
    for ( ; filesIter != filesEnd; ++filesIter ) {
        const string& filename = (*filesIter);
        if ( filename.empty() ) continue;

        // iterate over readers
        vector<MergeItem>::iterator readerIter = m_readers.begin();
        vector<MergeItem>::iterator readerEnd  = m_readers.end();
        for ( ; readerIter != readerEnd; ++readerIter ) {
            MergeItem& item = (*readerIter);
            BamReader* reader = item.Reader;
            if ( reader == 0 ) continue;

            // if reader matches requested filename
            if ( reader->GetFilename() == filename ) {

                // remove reader's entry from alignment cache
                m_alignmentCache->Remove(reader);

                // clean up reader & its alignment
                if ( !reader->Close() ) {
                    m_errorString.append(1, '\t');
                    m_errorString.append(reader->GetErrorString());
                    m_errorString.append(1, '\n');
                    errorsEncountered = true;
                }
                delete reader;
                reader = 0;

                // delete reader's alignment entry
                BamAlignment* alignment = item.Alignment;
                delete alignment;
                alignment = 0;

                // remove reader from reader list
                m_readers.erase(readerIter);

                // on match, just go on to next filename
                // (no need to keep looking and item iterator is invalid now anyway)
                break;
            }
        }
    }

    // make sure we clean up properly if all readers were closed
    if ( m_readers.empty() ) {

        // clean up merger
        if ( m_alignmentCache ) {
            m_alignmentCache->Clear();
            delete m_alignmentCache;
            m_alignmentCache = 0;
        }

        // reset merge flags
        m_hasUserMergeOrder = false;
        m_mergeOrder = BamMultiReader::RoundRobinMerge;
    }

    // return whether all readers closed OK
    return !errorsEncountered;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r15
movq $0x0, 0x30(%rdi)
movq 0x28(%rdi), %rax
movb $0x0, (%rax)
movq (%rsi), %r12
movq 0x8(%rsi), %rbx
cmpq %rbx, %r12
je 0x354e7
leaq 0x28(%r15), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %rbx, (%rsp)
cmpq $0x0, 0x8(%r12)
je 0x354d0
movq (%r15), %r13
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x353d6
leaq 0x10(%r13), %rbx
movq %r12, 0x40(%rsp)
movq (%r13), %rbp
testq %rbp, %rbp
je 0x353bb
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x26c90
movq 0x28(%rsp), %rdx
cmpq 0x8(%r12), %rdx
jne 0x35392
movq 0x20(%rsp), %r14
testq %rdx, %rdx
je 0x3539c
movq (%r12), %rsi
movq %r14, %rdi
callq 0x277e0
testl %eax, %eax
sete %r12b
jmp 0x3539f
movq 0x20(%rsp), %r14
xorl %r12d, %r12d
jmp 0x3539f
movb $0x1, %r12b
leaq 0x30(%rsp), %rax
cmpq %rax, %r14
je 0x353b1
movq %r14, %rdi
callq 0x27560
testb %r12b, %r12b
movq 0x40(%rsp), %r12
jne 0x353e0
addq $0x10, %r13
addq $0x10, %rbx
cmpq %r15, %r13
jne 0x35352
movq 0x8(%rsp), %r15
movq (%rsp), %rbx
jmp 0x354d0
movq 0x8(%rsp), %r15
jmp 0x354d0
movq 0x8(%rsp), %r15
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
callq *0x30(%rax)
movq %rbp, %rdi
callq 0x261d0
testb %al, %al
jne 0x35471
movq 0x30(%r15), %rsi
movl $0x1, %ecx
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
movl $0x9, %r8d
callq 0x28f20
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x26d30
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rdi
callq 0x265d0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x3544f
callq 0x27560
movq 0x30(%r15), %rsi
movl $0x1, %ecx
movq 0x18(%rsp), %rdi
xorl %edx, %edx
movl $0xa, %r8d
callq 0x28f20
movb $0x1, %al
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
callq 0x278c0
movq %rbp, %rdi
callq 0x27560
movq 0x8(%r13), %r14
testq %r14, %r14
je 0x35492
movq %r14, %rdi
callq 0x285f0
movq %r14, %rdi
callq 0x27560
leaq 0x10(%r13), %rsi
movq 0x8(%r15), %rax
cmpq %rax, %rsi
je 0x354c4
movq %rax, %rdx
subq %rbx, %rdx
testq %rdx, %rdx
movq (%rsp), %rbx
jle 0x354c8
movq %r13, %rdi
callq 0x287c0
movq 0x8(%r15), %rax
jmp 0x354c8
movq (%rsp), %rbx
addq $-0x10, %rax
movq %rax, 0x8(%r15)
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x3532d
movq 0x10(%rsp), %rbx
xorb $0x1, %bl
jmp 0x354e9
movb $0x1, %bl
movq (%r15), %rax
cmpq 0x8(%r15), %rax
jne 0x35525
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x35518
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x35510
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x18(%r15)
movb $0x0, 0x20(%r15)
movl $0x0, 0x24(%r15)
andb $0x1, %bl
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
jne 0x3555b
jmp 0x35560
movq %rax, %r15
movq %r14, %rdi
jmp 0x3555b
movq %rax, %r15
movq %rbp, %rdi
callq 0x27560
movq %r15, %rdi
callq 0x28c10