// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_coverage.cpp
// Function: BamTools::CoverageTool::CoverageToolPrivate::Run()
bool CoverageTool::CoverageToolPrivate::Run(void) {  
  
    // if output filename given
    ofstream outFile;
    if ( m_settings->HasOutputFile ) {
      
        // open output file stream
        outFile.open(m_settings->OutputFilename.c_str());
        if ( !outFile ) {
            cerr << "bamtools coverage ERROR: could not open " << m_settings->OutputFilename
                 << " for output" << endl;
            return false; 
        }
        
        // set m_out to file's streambuf
        m_out.rdbuf(outFile.rdbuf()); 
    } 
    
    //open our BAM reader
    BamReader reader;
    if ( !reader.Open(m_settings->InputBamFilename) ) {
        cerr << "bamtools coverage ERROR: could not open input BAM file: " << m_settings->InputBamFilename << endl;
        return false;
    }

    // retrieve references
    m_references = reader.GetReferenceData();
    
    // set up our output 'visitor'
    CoverageVisitor* cv = new CoverageVisitor(m_references, &m_out);
    
    // set up pileup engine with 'visitor'
    PileupEngine pileup;
    pileup.AddVisitor(cv);
    
    // process input data
    BamAlignment al;    
    while ( reader.GetNextAlignment(al) ) 
        pileup.AddAlignment(al);
    pileup.Flush();
    
    // clean up 
    reader.Close();
    if ( m_settings->HasOutputFile )
        outFile.close();
    delete cv;
    cv = 0;
    
    // return success
    return true;
}

// Assembly:
subq $0x408, %rsp            # imm = 0x408
movq %rdi, 0x3f8(%rsp)
movq 0x3f8(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x86d10
movq 0x70(%rsp), %rax
movq (%rax), %rax
testb $0x1, 0x1(%rax)
je 0x98d99
movq 0x70(%rsp), %rax
movq (%rax), %rdi
addq $0x28, %rdi
callq 0x86320
movq %rax, 0x68(%rsp)
jmp 0x98c83
movq 0x68(%rsp), %rsi
leaq 0x1f8(%rsp), %rdi
movl $0x10, %edx
callq 0x86090
jmp 0x98c9c
movq 0x1f8(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x1f8(%rsp,%rax), %rdi
callq 0x863b0
movb %al, 0x67(%rsp)
jmp 0x98cbb
movb 0x67(%rsp), %al
testb $0x1, %al
jne 0x98cc8
jmp 0x98d5b
movq 0xcc311(%rip), %rdi     # 0x164fe0
leaq 0x95e6f(%rip), %rsi     # 0x12eb45
callq 0x86700
movq %rax, 0x58(%rsp)
jmp 0x98ce2
movq 0x58(%rsp), %rdi
movq 0x70(%rsp), %rax
movq (%rax), %rsi
addq $0x28, %rsi
callq 0x86640
movq %rax, 0x50(%rsp)
jmp 0x98cff
movq 0x50(%rsp), %rdi
leaq 0x956cd(%rip), %rsi     # 0x12e3d8
callq 0x86700
movq %rax, 0x48(%rsp)
jmp 0x98d17
movq 0x48(%rsp), %rdi
movq 0xcc24d(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0x98d2a
movb $0x0, 0x407(%rsp)
movl $0x1, 0x1e8(%rsp)
jmp 0x99051
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x9906f
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x8(%rax,%rcx), %rax
movq %rax, 0x38(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x86e70
movq %rax, 0x40(%rsp)
jmp 0x98d86
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x86ea0
jmp 0x98d97
jmp 0x98d99
leaq 0x1e0(%rsp), %rdi
callq 0x864d0
jmp 0x98da8
movq 0x70(%rsp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
leaq 0x1e0(%rsp), %rdi
callq 0x86980
movb %al, 0x37(%rsp)
jmp 0x98dc7
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x98e4c
jmp 0x98dd1
movq 0xcc208(%rip), %rdi     # 0x164fe0
leaq 0x95d8f(%rip), %rsi     # 0x12eb6e
callq 0x86700
movq %rax, 0x28(%rsp)
jmp 0x98deb
movq 0x28(%rsp), %rdi
movq 0x70(%rsp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x86640
movq %rax, 0x20(%rsp)
jmp 0x98e08
movq 0x20(%rsp), %rdi
movq 0xcc15c(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0x98e1b
movb $0x0, 0x407(%rsp)
movl $0x1, 0x1e8(%rsp)
jmp 0x9902f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x99040
leaq 0x1e0(%rsp), %rdi
callq 0x860a0
movq %rax, 0x18(%rsp)
jmp 0x98e60
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rdi
addq $0x118, %rdi            # imm = 0x118
callq 0x912a0
jmp 0x98e78
movl $0x28, %edi
callq 0x86720
movq %rax, 0x10(%rsp)
jmp 0x98e89
movq 0x10(%rsp), %rdi
movq 0x70(%rsp), %rdx
movq %rdx, %rsi
addq $0x118, %rsi            # imm = 0x118
addq $0x8, %rdx
callq 0x99b50
jmp 0x98ea8
movq 0x10(%rsp), %rax
movq %rax, 0x1d8(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x111d30
jmp 0x98ec4
movq 0x1d8(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x111e40
jmp 0x98edb
leaq 0x78(%rsp), %rdi
callq 0x86260
jmp 0x98ee7
jmp 0x98ee9
leaq 0x1e0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x86bb0
movb %al, 0xf(%rsp)
jmp 0x98f01
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x98f0b
jmp 0x98f80
leaq 0x1d0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x111e10
jmp 0x98f1f
jmp 0x98ee9
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
callq 0x866a0
jmp 0x99040
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x9901e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x86b30
jmp 0x9901a
leaq 0x1d0(%rsp), %rdi
callq 0x111e70
jmp 0x98f8f
leaq 0x1e0(%rsp), %rdi
callq 0x860c0
jmp 0x98f9e
movq 0x70(%rsp), %rax
movq (%rax), %rax
testb $0x1, 0x1(%rax)
je 0x98fbd
leaq 0x1f8(%rsp), %rdi
callq 0x86a70
jmp 0x98fbb
jmp 0x98fbd
movq 0x1d8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x98fe0
movq (%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x98fde
jmp 0x98fe0
movq $0x0, 0x1d8(%rsp)
movb $0x1, 0x407(%rsp)
movl $0x1, 0x1e8(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x86b30
jmp 0x9900b
leaq 0x1d0(%rsp), %rdi
callq 0x111da0
jmp 0x9901c
jmp 0x9901e
jmp 0x9902f
leaq 0x1d0(%rsp), %rdi
callq 0x111da0
jmp 0x9902d
jmp 0x99040
leaq 0x1e0(%rsp), %rdi
callq 0x86790
jmp 0x9903e
jmp 0x99051
leaq 0x1e0(%rsp), %rdi
callq 0x86790
jmp 0x9904f
jmp 0x9906f
leaq 0x1f8(%rsp), %rdi
callq 0x86ab0
movb 0x407(%rsp), %al
andb $0x1, %al
addq $0x408, %rsp            # imm = 0x408
retq
leaq 0x1f8(%rsp), %rdi
callq 0x86ab0
jmp 0x9907e
jmp 0x99080
movq 0x1f0(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopw %cs:(%rax,%rax)