// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %r15
movq $0x0, 0x30(%rdi)
movq 0x28(%rdi), %rax
movb $0x0, (%rax)
movq (%rsi), %r12
movq 0x8(%rsi), %rax
movq %rax, 0x40(%rsp)
cmpq %rax, %r12
je 0x354c4
leaq 0x28(%r15), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq %r15, 0x18(%rsp)
cmpq $0x0, 0x8(%r12)
je 0x354ab
movq (%r15), %r13
movq 0x8(%r15), %rax
movq %rax, 0x50(%rsp)
cmpq %rax, %r13
je 0x354ab
movq $-0x10, %r14
subq %r13, %r14
addq $0x10, %r13
movq %r12, 0x48(%rsp)
movq -0x10(%r13), %rbp
testq %rbp, %rbp
je 0x35376
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x26c90
movq 0x28(%rsp), %rdx
cmpq 0x8(%r12), %rdx
jne 0x3537d
testq %rdx, %rdx
je 0x35381
movq (%r12), %rsi
movq 0x20(%rsp), %rdi
callq 0x277e0
testl %eax, %eax
sete %bl
jmp 0x35383
xorl %eax, %eax
jmp 0x35491
xorl %ebx, %ebx
jmp 0x35383
movb $0x1, %bl
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x35397
callq 0x27560
testb %bl, %bl
je 0x3548a
movq 0x18(%rsp), %r15
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
callq *0x30(%rax)
movq %rbp, %rdi
callq 0x261d0
testb %al, %al
jne 0x3543b
movq %r15, %rbx
movq 0x30(%r15), %rsi
movl $0x1, %ecx
movq 0x10(%rsp), %r12
movq %r12, %rdi
xorl %edx, %edx
movl $0x9, %r8d
callq 0x28f30
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x26d30
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r12, %rdi
callq 0x265d0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x35411
callq 0x27560
movq 0x30(%rbx), %rsi
movl $0x1, %ecx
movq 0x10(%rsp), %rdi
xorl %edx, %edx
movl $0xa, %r8d
callq 0x28f30
movb $0x1, %al
movq %rax, 0x8(%rsp)
movq %rbx, %r15
movq 0x48(%rsp), %r12
movq %rbp, %rdi
callq 0x278c0
movq %rbp, %rdi
callq 0x27560
movq -0x8(%r13), %rbp
testq %rbp, %rbp
je 0x35464
movq %rbp, %rdi
callq 0x28600
movq %rbp, %rdi
callq 0x27560
movq 0x8(%r15), %rdx
cmpq %rdx, %r13
je 0x35481
addq %r14, %rdx
testq %rdx, %rdx
jle 0x35481
leaq -0x10(%r13), %rdi
movq %r13, %rsi
callq 0x287d0
addq $-0x10, 0x8(%r15)
movb $0x1, %al
jmp 0x35491
xorl %eax, %eax
movq 0x18(%rsp), %r15
testb %al, %al
jne 0x354ab
leaq 0x10(%r13), %rax
addq $-0x10, %r14
cmpq 0x50(%rsp), %r13
movq %rax, %r13
jne 0x3533a
addq $0x20, %r12
cmpq 0x40(%rsp), %r12
jne 0x35306
movq 0x8(%rsp), %rbx
xorb $0x1, %bl
jmp 0x354c6
movb $0x1, %bl
movq (%r15), %rax
cmpq 0x8(%r15), %rax
jne 0x35502
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x354f5
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x354ed
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 $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
jne 0x35532
jmp 0x35537
jmp 0x3552c
movq %rax, %rbx
movq %rbp, %rdi
callq 0x27560
movq %rbx, %rdi
callq 0x28c20
nop