// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a9e4
cmpb $0x0, 0x1(%r14)
jne 0x2a9e4
addq $0x8, %r14
callq 0x646e2
movq %r14, %rdi
movq %rax, %rsi
callq 0x2e1b0
movq (%rbx), %rax
cmpb $0x1, 0x1(%rax)
jne 0x2aaed
movq 0x20(%rax), %rsi
leaq 0x180(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x27ba0
leaq 0x1f8(%rsp), %rdi
callq 0x27130
movl %eax, %ebp
testb %al, %al
je 0x2aa80
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 0x27bb0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2aac8
movq (%rbx), %rdi
addq $0x8, %rdi
movq %r15, %rsi
callq 0x2e1b0
jmp 0x2aa3a
movq 0x65559(%rip), %r14     # 0x8ffe0
leaq 0x47614(%rip), %rsi     # 0x720a2
movl $0x47, %edx
movq %r14, %rdi
callq 0x276c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x65527(%rip), %rdi     # 0x8ffe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
jmp 0x2aad7
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x2aad7
callq 0x27560
leaq 0x180(%rsp), %rdi
callq 0x27170
testb %bpl, %bpl
je 0x2accf
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x27b40
movq (%rbx), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x273c0
testb %al, %al
je 0x2ac81
movq (%rbx), %rax
cmpb $0x1, (%rax)
jne 0x2ab3f
cmpb $0x1, 0x4(%rax)
jne 0x2ab3f
leaq 0x180(%rsp), %rsi
movl $0x1, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x27770
testb %al, %al
je 0x2ad47
leaq 0x180(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x27270
leaq 0x8(%rbx), %rdi
leaq 0x180(%rsp), %rsi
callq 0x2e1f8
leaq 0x180(%rsp), %rdi
callq 0x2e378
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movq (%rbx), %rdi
cmpb $0x1, 0x4(%rdi)
jne 0x2abc2
subq $-0x80, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x669d4
testb %al, %al
je 0x2acd7
leaq 0x8(%rsp), %rdi
callq 0x273e0
testb %al, %al
je 0x2abc2
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x27af0
testb %al, %al
je 0x2ae81
leaq 0x180(%rsp), %rdi
callq 0x27aa0
movq (%rbx), %rax
cmpb $0x1, 0x2(%rax)
jne 0x2ad71
movq 0x40(%rax), %rsi
leaq 0x180(%rsp), %rdi
movl $0x10, %edx
callq 0x27080
movq 0x180(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1a0(%rsp,%rax)
je 0x2ad58
movq 0x653cd(%rip), %rdi     # 0x8ffe0
leaq 0x4763c(%rip), %rsi     # 0x72256
movl $0x27, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0x653aa(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rbx
leaq 0x47639(%rip), %rsi     # 0x7227e
movl $0xb, %edx
movq %rax, %rdi
callq 0x276c0
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 %r14d, %r14d
jmp 0x2afe2
movl $0x45, %edx
leaq 0x4745d(%rip), %rsi     # 0x720ea
movq 0x6534c(%rip), %rbx     # 0x8ffe0
movq %rbx, %rdi
callq 0x276c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x65326(%rip), %rdi     # 0x8ffe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
xorl %r14d, %r14d
jmp 0x2afef
xorl %r14d, %r14d
jmp 0x2aff9
movq 0x65302(%rip), %rdi     # 0x8ffe0
leaq 0x474e4(%rip), %rsi     # 0x721c9
movl $0x30, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
movq 0x652d9(%rip), %rdi     # 0x8ffe0
callq 0x276c0
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 0x474b8(%rip), %rsi     # 0x721fa
jmp 0x2ae8d
movl $0x43, %edx
leaq 0x473dd(%rip), %rsi     # 0x72130
jmp 0x2ac8d
leaq 0x20(%rbx), %rdi
movq 0x20(%rbx), %rax
addq -0x18(%rax), %rdi
leaq 0x188(%rsp), %rsi
callq 0x27bf0
movq (%rbx), %r15
movq 0x68(%r15), %r12
addq $0x60, %r15
cmpq 0x65985(%rip), %r12     # 0x90708
jne 0x2ada8
testq %r12, %r12
je 0x2ae6c
movq 0x6596b(%rip), %rsi     # 0x90700
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2ae6c
cmpq 0x658b9(%rip), %r12     # 0x90668
jne 0x2adde
leaq 0x468(%rip), %r13       # 0x2b220
movb $0x1, %r14b
testq %r12, %r12
je 0x2af18
movq 0x65895(%rip), %rsi     # 0x90660
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af18
cmpq 0x658a3(%rip), %r12     # 0x90688
jne 0x2ae14
leaq 0x588(%rip), %r13       # 0x2b376
movb $0x1, %r14b
testq %r12, %r12
je 0x2af18
movq 0x6587f(%rip), %rsi     # 0x90680
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af18
cmpq 0x6588d(%rip), %r12     # 0x906a8
jne 0x2ae4a
leaq 0x78a(%rip), %r13       # 0x2b5ae
movb $0x1, %r14b
testq %r12, %r12
je 0x2af18
movq 0x65869(%rip), %rsi     # 0x906a0
movq (%r15), %rdi
movq %r12, %rdx
callq 0x275f0
testl %eax, %eax
je 0x2af18
leaq 0x6586f(%rip), %rsi     # 0x906c0
movq %r15, %rdi
callq 0x2e3bb
movb $0x1, %r14b
testb %al, %al
je 0x2aed6
leaq 0x989(%rip), %r13       # 0x2b7f0
jmp 0x2af18
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x2b114
movl %eax, %r14d
jmp 0x2afc2
movl $0x54, %edx
leaq 0x472e7(%rip), %rsi     # 0x72174
movq 0x6514c(%rip), %rbx     # 0x8ffe0
movq %rbx, %rdi
callq 0x276c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x27590
movsbl %al, %esi
movq 0x65126(%rip), %rdi     # 0x8ffe0
callq 0x27040
movq %rax, %rdi
callq 0x27410
leaq 0x8(%rsp), %rdi
callq 0x27190
jmp 0x2acc7
movq (%rbx), %rdi
addq $0x60, %rdi
leaq 0x657fc(%rip), %rsi     # 0x906e0
callq 0x2e3bb
testb %al, %al
je 0x2aef6
leaq 0x1034(%rip), %r13      # 0x2bf28
jmp 0x2af18
movq (%rbx), %rdi
addq $0x60, %rdi
leaq 0x6581c(%rip), %rsi     # 0x90720
callq 0x2e3bb
testb %al, %al
je 0x2b00e
leaq 0x15da(%rip), %r13      # 0x2c4f2
xorl %eax, %eax
testb %al, %al
jne 0x2afc2
movq (%rbx), %r14
movq 0x68(%r14), %rdx
cmpq 0x657b8(%rip), %rdx     # 0x906e8
jne 0x2af87
testq %rdx, %rdx
je 0x2af4b
movq 0x657a2(%rip), %rsi     # 0x906e0
movq 0x60(%r14), %rdi
callq 0x275f0
testl %eax, %eax
jne 0x2af87
cmpb $0x0, 0x6(%r14)
jne 0x2af87
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x274d0
leaq 0x20(%rbx), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x276c0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2af87
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 0x2afb5
movq %rbx, %rdi
movq %r15, %rsi
callq *%r13
jmp 0x2af9b
leaq 0x28(%rsp), %rdi
callq 0x27930
movb $0x1, %r14b
leaq 0x8(%rsp), %rdi
callq 0x27190
movq (%rbx), %rax
cmpb $0x1, 0x2(%rax)
jne 0x2afe2
leaq 0x180(%rsp), %rdi
callq 0x27850
leaq 0x180(%rsp), %rdi
callq 0x27890
leaq 0x8(%rsp), %rdi
callq 0x27110
movl %r14d, %eax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x64fcb(%rip), %rdi     # 0x8ffe0
leaq 0x4726e(%rip), %rsi     # 0x7228a
movl $0x2d, %edx
callq 0x276c0
movq (%rbx), %rax
movq 0x60(%rax), %rsi
movq 0x68(%rax), %rdx
movq 0x64fa8(%rip), %rdi     # 0x8ffe0
callq 0x276c0
movq %rax, %rdi
callq 0x27310
movq 0x64f94(%rip), %rdi     # 0x8ffe0
leaq 0x47265(%rip), %rsi     # 0x722b8
movl $0x37, %edx
callq 0x276c0
movq 0x64f7c(%rip), %rdi     # 0x8ffe0
callq 0x27310
movb $0x1, %al
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x2af1a
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b0cc
callq 0x27560
jmp 0x2b0cc
jmp 0x2b0ac
jmp 0x2b0ac
jmp 0x2b0ba
jmp 0x2b0ac
jmp 0x2b0ac
movq %rax, %rbx
leaq 0x180(%rsp), %rdi
callq 0x2e378
jmp 0x2b0d9
jmp 0x2b0ba
movq %rax, %rbx
jmp 0x2b0cc
jmp 0x2b0ba
movq %rax, %rbx
jmp 0x2b0f7
jmp 0x2b0ba
movq %rax, %rbx
jmp 0x2b0d9
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x27930
leaq 0x180(%rsp), %rdi
callq 0x27890
leaq 0x8(%rsp), %rdi
callq 0x27110
jmp 0x2b104
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b0f7
callq 0x27560
leaq 0x180(%rsp), %rdi
callq 0x27170
movq %rbx, %rdi
callq 0x27b20
movq %rax, %rdi
callq 0x2e1ed