// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
leaq 0x28(%rdi), %rcx
andq $0x0, 0x30(%rdi)
movq 0x28(%rdi), %rax
movb $0x0, (%rax)
movq (%rsi), %r15
movq 0x8(%rsi), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0xc(%rsp)
leaq 0x28(%rsp), %r12
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
cmpq 0x20(%rsp), %r15
je 0x3f1cd
cmpq $0x0, 0x8(%r15)
je 0x3f1c4
movq (%rbx), %r13
movq 0x8(%rbx), %rbx
cmpq %rbx, %r13
je 0x3f123
movq (%r13), %rbp
testq %rbp, %rbp
je 0x3f11d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x32250
movq %r12, %rdi
movq %r15, %rsi
callq 0x32220
movl %eax, %r14d
movq %r12, %rdi
callq 0x33a00
testb %r14b, %r14b
jne 0x3f12d
addq $0x10, %r13
jmp 0x3f0e9
movq 0x10(%rsp), %rbx
jmp 0x3f1c4
movq 0x10(%rsp), %rbx
movq 0x18(%rbx), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
callq *0x30(%rax)
movq %rbp, %rdi
callq 0x31240
testb %al, %al
jne 0x3f190
movq 0x18(%rsp), %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0x9
popq %rdx
callq 0x333e0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x32330
movq %r14, %rdi
movq %r12, %rsi
callq 0x35680
movq %r12, %rdi
callq 0x33a00
movq %r14, %rdi
pushq $0x1
popq %rsi
pushq $0xa
popq %rdx
callq 0x333e0
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %rbp, %rdi
callq 0x333a0
movq %rbp, %rdi
callq 0x32fa0
movq 0x8(%r13), %rbp
testq %rbp, %rbp
je 0x3f1b1
movq %rbp, %rdi
callq 0x346b0
movq %rbp, %rdi
callq 0x32fa0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x34770
addq $0x20, %r15
jmp 0x3f0cc
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
jne 0x3f201
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x3f1f9
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x3f1f4
movq (%rdi), %rax
callq *0x8(%rax)
andq $0x0, 0x18(%rbx)
movb $0x0, 0x20(%rbx)
andl $0x0, 0x24(%rbx)
movl 0xc(%rsp), %eax
notb %al
andb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
jmp 0x3f243
jmp 0x3f229
movq %rax, %rbx
movq %rbp, %rdi
callq 0x32fa0
jmp 0x3f243
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
movq %rbx, %rdi
callq 0x34ed0
movq %rax, %rdi
callq 0x39b2f
nop