// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_revert.cpp
// Function: BamTools::RevertTool::RevertToolPrivate::Run()
bool RevertTool::RevertToolPrivate::Run(void) {
  
    // opens the BAM file without checking for indexes
    BamReader reader;
    if ( !reader.Open(m_settings->InputFilename) ) {
        cerr << "bamtools revert ERROR: could not open " << m_settings->InputFilename
             << " for reading... Aborting." << endl;
        return false;
    }

    // get BAM file metadata
    const string& headerText = reader.GetHeaderText();
    const RefVector& references = reader.GetReferenceData();
    
    // determine compression mode for BamWriter
    bool writeUncompressed = ( m_settings->OutputFilename == Options::StandardOut() &&
                              !m_settings->IsForceCompression );
    BamWriter::CompressionMode compressionMode = BamWriter::Compressed;
    if ( writeUncompressed ) compressionMode = BamWriter::Uncompressed;

    // open BamWriter
    BamWriter writer;
    writer.SetCompressionMode(compressionMode);
    if ( !writer.Open(m_settings->OutputFilename, headerText, references) ) {
        cerr << "bamtools revert ERROR: could not open " << m_settings->OutputFilename
             << " for writing... Aborting." << endl;
        reader.Close();
        return false;
    }

    // plow through file, reverting alignments
    BamAlignment al;
    while ( reader.GetNextAlignment(al) ) {
        RevertAlignment(al);
        writer.SaveAlignment(al);
    }
    
    // clean and exit
    reader.Close();
    writer.Close();
    return true; 
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x228(%rsp)
movq 0x228(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x220(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x864d0
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x86980
movb %al, 0x77(%rsp)
jmp 0xd995a
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0xd99fb
jmp 0xd9968
movq 0x8b671(%rip), %rdi     # 0x164fe0
leaq 0x58754(%rip), %rsi     # 0x1320ca
callq 0x86700
movq %rax, 0x58(%rsp)
jmp 0xd9982
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x86640
movq %rax, 0x50(%rsp)
jmp 0xd999f
movq 0x50(%rsp), %rdi
leaq 0x5668b(%rip), %rsi     # 0x130036
callq 0x86700
movq %rax, 0x48(%rsp)
jmp 0xd99b7
movq 0x48(%rsp), %rdi
movq 0x8b5ad(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xd99ca
movb $0x0, 0x237(%rsp)
movl $0x1, 0x210(%rsp)
jmp 0xd9cde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
jmp 0xd9cfc
leaq 0x1e8(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x86250
jmp 0xd9a12
leaq 0x1e8(%rsp), %rax
movq %rax, 0x208(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x860a0
movq %rax, 0x40(%rsp)
jmp 0xd9a36
movq 0x60(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x1e0(%rsp)
movq (%rax), %rax
addq $0x28, %rax
movq %rax, 0x30(%rsp)
callq 0x10f290
movq %rax, 0x38(%rsp)
jmp 0xd9a60
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x91630
movb %al, 0x2f(%rsp)
jmp 0xd9a75
movb 0x2f(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x2e(%rsp)
jne 0xd9a86
jmp 0xd9a97
movq 0x60(%rsp), %rax
movq (%rax), %rax
movb 0x2(%rax), %al
xorb $-0x1, %al
movb %al, 0x2e(%rsp)
movb 0x2e(%rsp), %al
andb $0x1, %al
movb %al, 0x1df(%rsp)
movl $0x0, 0x1d8(%rsp)
testb $0x1, 0x1df(%rsp)
je 0xd9adf
movl $0x1, 0x1d8(%rsp)
jmp 0xd9adf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
jmp 0xd9ccd
leaq 0x1d0(%rsp), %rdi
callq 0x863f0
jmp 0xd9aee
leaq 0x1d0(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x86280
jmp 0xd9b05
movq 0x60(%rsp), %rax
movq (%rax), %rsi
addq $0x28, %rsi
movq 0x208(%rsp), %rdx
movq 0x1e0(%rsp), %rcx
leaq 0x1d0(%rsp), %rdi
callq 0x86bd0
movb %al, 0x2d(%rsp)
jmp 0xd9b34
movb 0x2d(%rsp), %al
testb $0x1, %al
jne 0xd9be4
jmp 0xd9b42
movq 0x8b497(%rip), %rdi     # 0x164fe0
leaq 0x5857a(%rip), %rsi     # 0x1320ca
callq 0x86700
movq %rax, 0x20(%rsp)
jmp 0xd9b5c
movq 0x20(%rsp), %rdi
movq 0x60(%rsp), %rax
movq (%rax), %rsi
addq $0x28, %rsi
callq 0x86640
movq %rax, 0x18(%rsp)
jmp 0xd9b79
movq 0x18(%rsp), %rdi
leaq 0x569ae(%rip), %rsi     # 0x130533
callq 0x86700
movq %rax, 0x10(%rsp)
jmp 0xd9b91
movq 0x10(%rsp), %rdi
movq 0x8b3d3(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0xd9ba4
leaq 0x220(%rsp), %rdi
callq 0x860c0
jmp 0xd9bb3
movb $0x0, 0x237(%rsp)
movl $0x1, 0x210(%rsp)
jmp 0xd9c9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
jmp 0xd9cba
leaq 0x78(%rsp), %rdi
callq 0x86260
jmp 0xd9bf0
jmp 0xd9bf2
leaq 0x220(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x86bb0
movb %al, 0xf(%rsp)
jmp 0xd9c0a
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xd9c14
jmp 0xd9c5b
movq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xd9830
jmp 0xd9c25
leaq 0x1d0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x86e80
jmp 0xd9c39
jmp 0xd9bf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x218(%rsp)
movl %eax, 0x214(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x86b30
jmp 0xd9c9a
leaq 0x220(%rsp), %rdi
callq 0x860c0
jmp 0xd9c6a
leaq 0x1d0(%rsp), %rdi
callq 0x86410
jmp 0xd9c79
movb $0x1, 0x237(%rsp)
movl $0x1, 0x210(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x86b30
jmp 0xd9c98
jmp 0xd9c9c
jmp 0xd9cba
leaq 0x1d0(%rsp), %rdi
callq 0x86510
jmp 0xd9cab
leaq 0x1e8(%rsp), %rdi
callq 0x86f68
jmp 0xd9ccb
leaq 0x1d0(%rsp), %rdi
callq 0x86510
jmp 0xd9cc9
jmp 0xd9ccd
jmp 0xd9cde
leaq 0x1e8(%rsp), %rdi
callq 0x86f68
jmp 0xd9cdc
jmp 0xd9cfc
leaq 0x220(%rsp), %rdi
callq 0x86790
movb 0x237(%rsp), %al
andb $0x1, %al
addq $0x238, %rsp            # imm = 0x238
retq
leaq 0x220(%rsp), %rdi
callq 0x86790
jmp 0xd9d0b
jmp 0xd9d0d
movq 0x218(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopw %cs:(%rax,%rax)