// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/toolkit/bamtools_convert.cpp
// Function: BamTools::ConvertTool::ConvertToolPrivate::Run()
bool ConvertTool::ConvertToolPrivate::Run(void) {
 
    // ------------------------------------
    // initialize conversion input/output
        
    // set to default input if none provided
    if ( !m_settings->HasInput && !m_settings->HasInputFilelist )
        m_settings->InputFiles.push_back(Options::StandardIn());
    
    // add files in the filelist to the input file list
    if ( m_settings->HasInputFilelist ) {

        ifstream filelist(m_settings->InputFilelist.c_str(), ios::in);
        if ( !filelist.is_open() ) {
            cerr << "bamtools convert ERROR: could not open input BAM file list... Aborting." << endl;
            return false;
        }

        string line;
        while ( getline(filelist, line) )
            m_settings->InputFiles.push_back(line);
    }

    // open input files
    BamMultiReader reader;
    if ( !reader.Open(m_settings->InputFiles) ) {
        cerr << "bamtools convert ERROR: could not open input BAM file(s)... Aborting." << endl;
        return false;
    }

    // if input is not stdin & a region is provided, look for index files
    if ( m_settings->HasInput && m_settings->HasRegion ) {
        if ( !reader.LocateIndexes() ) {
            cerr << "bamtools convert ERROR: could not locate index file(s)... Aborting." << endl;
            return false;
        }
    }

    // retrieve reference data
    m_references = reader.GetReferenceData();

    // set region if specified
    BamRegion region;
    if ( m_settings->HasRegion ) {
        if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) {

            if ( reader.HasIndexes() ) {
                if ( !reader.SetRegion(region) ) {
                    cerr << "bamtools convert ERROR: set region failed. Check that REGION describes a valid range" << endl;
                    reader.Close();
                    return false;
                }
            }

        } else {
            cerr << "bamtools convert ERROR: could not parse REGION: " << m_settings->Region << endl;
            cerr << "Check that REGION is in valid format (see documentation) and that the coordinates are valid"
                 << endl;
            reader.Close();
            return false;
        }
    }
        
    // if output file given
    ofstream outFile;
    if ( m_settings->HasOutput ) {
      
        // open output file stream
        outFile.open(m_settings->OutputFilename.c_str());
        if ( !outFile ) {
            cerr << "bamtools convert ERROR: could not open " << m_settings->OutputFilename
                 << " for output" << endl;
            return false; 
        }
        
        // set m_out to file's streambuf
        m_out.rdbuf(outFile.rdbuf()); 
    }
    
    // -------------------------------------
    // do conversion based on format
    
     bool convertedOk = true;
    
    // pileup is special case
    // conversion not done per alignment, like the other formats
    if ( m_settings->Format == FORMAT_PILEUP )
        convertedOk = RunPileupConversion(&reader);
    
    // all other formats
    else {
    
        bool formatError = false;
        
        // set function pointer to proper conversion method
        void (BamTools::ConvertTool::ConvertToolPrivate::*pFunction)(const BamAlignment&) = 0;
        if      ( m_settings->Format == FORMAT_BED )   pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintBed;
        else if ( m_settings->Format == FORMAT_FASTA ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintFasta;
        else if ( m_settings->Format == FORMAT_FASTQ ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintFastq;
        else if ( m_settings->Format == FORMAT_JSON )  pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintJson;
        else if ( m_settings->Format == FORMAT_SAM )   pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintSam;
        else if ( m_settings->Format == FORMAT_YAML )  pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintYaml;
        else { 
            cerr << "bamtools convert ERROR: unrecognized format: " << m_settings->Format << endl;
            cerr << "Please see documentation for list of supported formats " << endl;
            formatError = true;
            convertedOk = false;
        }
        
        // if format selected ok
        if ( !formatError ) {
        
            // if SAM format & not omitting header, print SAM header first
            if ( (m_settings->Format == FORMAT_SAM) && !m_settings->IsOmittingSamHeader ) 
                m_out << reader.GetHeaderText();
            
            // iterate through file, doing conversion
            BamAlignment a;
            while ( reader.GetNextAlignment(a) )
                (this->*pFunction)(a);
            
            // set flag for successful conversion
            convertedOk = true;
        }
    }
    
    // ------------------------
    // clean up & exit
    reader.Close();
    if ( m_settings->HasOutput )
        outFile.close();
    return convertedOk;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movq %rdi, %rbx
movq (%rdi), %r14
cmpb $0x0, (%r14)
jne 0x2a9d7
cmpb $0x0, 0x1(%r14)
jne 0x2a9d7
addq $0x8, %r14
callq 0x641a2
movq %r14, %rdi
movq %rax, %rsi
callq 0x2e190
movq (%rbx), %r14
cmpb $0x1, 0x1(%r14)
jne 0x2aae5
movq 0x20(%r14), %rsi
leaq 0x180(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x27b90
leaq 0x1f8(%rsp), %rdi
callq 0x27130
testb %al, %al
je 0x2aa6f
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x28(%rsp), %r15
movq 0x180(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x27ba0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2aac9
movq (%rbx), %rdi
addq $0x8, %rdi
movq %r15, %rsi
callq 0x2e190
jmp 0x2aa29
movq 0x6456a(%rip), %rbx     # 0x8efe0
leaq 0x46625(%rip), %rsi     # 0x710a2
movl $0x47, %edx
movq %rbx, %rdi
callq 0x276b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x64538(%rip), %rdi     # 0x8efe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
leaq 0x180(%rsp), %rdi
callq 0x27170
xorl %ebp, %ebp
jmp 0x2afd7
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x2aad8
callq 0x27560
leaq 0x180(%rsp), %rdi
callq 0x27170
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x27b30
movq (%rbx), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x273c0
testb %al, %al
je 0x2ac79
movq (%rbx), %rax
cmpb $0x1, (%rax)
jne 0x2ab37
cmpb $0x1, 0x4(%rax)
jne 0x2ab37
leaq 0x180(%rsp), %rsi
movl $0x1, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x27760
testb %al, %al
je 0x2ad36
leaq 0x180(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x27270
leaq 0x8(%rbx), %rdi
leaq 0x180(%rsp), %rsi
callq 0x2e1d8
leaq 0x180(%rsp), %rdi
callq 0x2e37a
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movq (%rbx), %rdi
cmpb $0x1, 0x4(%rdi)
jne 0x2abba
subq $-0x80, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x6643c
testb %al, %al
je 0x2acc6
leaq 0x8(%rsp), %rdi
callq 0x273e0
testb %al, %al
je 0x2abba
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x27ae0
testb %al, %al
je 0x2ae66
leaq 0x180(%rsp), %rdi
callq 0x27a90
movq (%rbx), %r14
cmpb $0x1, 0x2(%r14)
jne 0x2ad63
movq 0x40(%r14), %rsi
leaq 0x180(%rsp), %rdi
movl $0x10, %edx
callq 0x27080
movq 0x180(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1a0(%rsp,%rax)
je 0x2ad47
movq 0x643d4(%rip), %rdi     # 0x8efe0
leaq 0x46643(%rip), %rsi     # 0x71256
movl $0x27, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0x643b1(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
leaq 0x46640(%rip), %rsi     # 0x7127e
movl $0xb, %edx
movq %rax, %rdi
callq 0x276b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %ebp, %ebp
jmp 0x2afc0
movl $0x45, %edx
leaq 0x46465(%rip), %rsi     # 0x710ea
movq 0x64354(%rip), %rbx     # 0x8efe0
movq %rbx, %rdi
callq 0x276b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x6432e(%rip), %rdi     # 0x8efe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %ebp, %ebp
jmp 0x2afcd
movq 0x64313(%rip), %rdi     # 0x8efe0
leaq 0x464f5(%rip), %rsi     # 0x711c9
movl $0x30, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
movq 0x642ea(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq %rbx, %rdi
callq 0x27040
movq %rax, %rdi
callq 0x27410
movl $0x5b, %edx
leaq 0x464c9(%rip), %rsi     # 0x711fa
jmp 0x2ae72
movl $0x43, %edx
leaq 0x463ee(%rip), %rsi     # 0x71130
jmp 0x2ac85
leaq 0x20(%rbx), %rdi
movq 0x20(%rbx), %rax
addq -0x18(%rax), %rdi
leaq 0x188(%rsp), %rsi
callq 0x27be0
movq (%rbx), %r14
leaq 0x60(%r14), %r15
movq 0x68(%r14), %r12
cmpq 0x6498e(%rip), %r12     # 0x8f700
jne 0x2ad97
testq %r12, %r12
je 0x2ae52
movq 0x64974(%rip), %rsi     # 0x8f6f8
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2ae52
cmpq 0x648c2(%rip), %r12     # 0x8f660
jne 0x2adca
leaq 0x451(%rip), %r13       # 0x2b1f8
testq %r12, %r12
je 0x2af03
movq 0x648a1(%rip), %rsi     # 0x8f658
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af03
cmpq 0x648af(%rip), %r12     # 0x8f680
jne 0x2adfd
leaq 0x574(%rip), %r13       # 0x2b34e
testq %r12, %r12
je 0x2af03
movq 0x6488e(%rip), %rsi     # 0x8f678
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af03
cmpq 0x6489c(%rip), %r12     # 0x8f6a0
jne 0x2ae30
leaq 0x76b(%rip), %r13       # 0x2b578
testq %r12, %r12
je 0x2af03
movq 0x6487b(%rip), %rsi     # 0x8f698
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af03
leaq 0x64881(%rip), %rsi     # 0x8f6b8
movq %r15, %rdi
callq 0x2e3c3
movq (%rbx), %r14
testb %al, %al
je 0x2aebb
leaq 0x96d(%rip), %r13       # 0x2b7ba
jmp 0x2af03
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x2b0ec
movl %eax, %ebp
jmp 0x2afa0
movl $0x54, %edx
leaq 0x46302(%rip), %rsi     # 0x71174
movq 0x64167(%rip), %rbx     # 0x8efe0
movq %rbx, %rdi
callq 0x276b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x64141(%rip), %rdi     # 0x8efe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
leaq 0x8(%rsp), %rdi
callq 0x27190
jmp 0x2acbf
addq $0x60, %r14
leaq 0x64812(%rip), %rsi     # 0x8f6d8
movq %r14, %rdi
callq 0x2e3c3
movq (%rbx), %r14
testb %al, %al
je 0x2aede
leaq 0x1016(%rip), %r13      # 0x2bef2
jmp 0x2af03
addq $0x60, %r14
leaq 0x6482f(%rip), %rsi     # 0x8f718
movq %r14, %rdi
callq 0x2e3c3
testb %al, %al
je 0x2afeb
movq (%rbx), %r14
leaq 0x15b9(%rip), %r13      # 0x2c4bc
movq 0x68(%r14), %rdx
cmpq 0x647d2(%rip), %rdx     # 0x8f6e0
jne 0x2af65
testq %rdx, %rdx
je 0x2af29
movq 0x647bc(%rip), %rsi     # 0x8f6d8
movq 0x60(%r14), %rdi
callq 0x275f0
testl %eax, %eax
jne 0x2af65
cmpb $0x0, 0x6(%r14)
jne 0x2af65
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x274d0
leaq 0x20(%rbx), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x276b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2af65
callq 0x27560
leaq 0x28(%rsp), %rdi
callq 0x27220
leaq 0x8(%rsp), %r14
leaq 0x28(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x272d0
testb %al, %al
je 0x2af93
movq %rbx, %rdi
movq %r15, %rsi
callq *%r13
jmp 0x2af79
leaq 0x28(%rsp), %rdi
callq 0x27920
movb $0x1, %bpl
leaq 0x8(%rsp), %rdi
callq 0x27190
movq (%rbx), %rax
cmpb $0x1, 0x2(%rax)
jne 0x2afc0
leaq 0x180(%rsp), %rdi
callq 0x27840
leaq 0x180(%rsp), %rdi
callq 0x27880
leaq 0x8(%rsp), %rdi
callq 0x27110
movl %ebp, %eax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x63fee(%rip), %rdi     # 0x8efe0
leaq 0x46291(%rip), %rsi     # 0x7128a
movl $0x2d, %edx
callq 0x276b0
movq (%rbx), %rax
movq 0x60(%rax), %rsi
movq 0x68(%rax), %rdx
movq 0x63fcb(%rip), %rdi     # 0x8efe0
callq 0x276b0
movq %rax, %rdi
callq 0x27310
movq 0x63fb7(%rip), %rdi     # 0x8efe0
leaq 0x46288(%rip), %rsi     # 0x712b8
movl $0x37, %edx
callq 0x276b0
movq 0x63f9f(%rip), %rdi     # 0x8efe0
callq 0x27310
xorl %ebp, %ebp
jmp 0x2afa0
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b0a3
callq 0x27560
jmp 0x2b0a3
jmp 0x2b083
jmp 0x2b083
jmp 0x2b091
jmp 0x2b083
jmp 0x2b083
movq %rax, %rbx
leaq 0x180(%rsp), %rdi
callq 0x2e37a
jmp 0x2b0b0
jmp 0x2b091
movq %rax, %rbx
jmp 0x2b0a3
jmp 0x2b091
movq %rax, %rbx
jmp 0x2b0ce
jmp 0x2b091
movq %rax, %rbx
jmp 0x2b0b0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x27920
leaq 0x180(%rsp), %rdi
callq 0x27880
leaq 0x8(%rsp), %rdi
callq 0x27110
jmp 0x2b0db
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b0ce
callq 0x27560
leaq 0x180(%rsp), %rdi
callq 0x27170
movq %rbx, %rdi
callq 0x27b10
movq %rax, %rdi
callq 0x2e1cd
nop