// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_stats.cpp
// Function: BamTools::StatsTool::StatsToolPrivate::Run()
bool StatsTool::StatsToolPrivate::Run() {
  
    // 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 stats 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 the BAM files
    BamMultiReader reader;
    if ( !reader.Open(m_settings->InputFiles) ) {
        cerr << "bamtools stats ERROR: could not open input BAM file(s)... Aborting." << endl;
        reader.Close();
        return false;
    }
    
    // plow through alignments, keeping track of stats
    BamAlignment al;
    while ( reader.GetNextAlignmentCore(al) )
        ProcessAlignment(al);
    reader.Close();
    
    // print stats & exit
    PrintStats();
    return true; 
}

// Assembly:
subq $0x408, %rsp            # imm = 0x408
movq %rdi, 0x3f8(%rsp)
movq 0x3f8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq (%rax), %rax
testb $0x1, (%rax)
jne 0x107a45
movq 0x58(%rsp), %rax
movq (%rax), %rax
testb $0x1, 0x1(%rax)
jne 0x107a45
movq 0x58(%rsp), %rax
movq (%rax), %rax
addq $0x8, %rax
movq %rax, 0x50(%rsp)
callq 0x10f280
movq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x91220
movq 0x58(%rsp), %rax
movq (%rax), %rax
testb $0x1, 0x1(%rax)
je 0x107bde
movq 0x58(%rsp), %rax
movq (%rax), %rdi
addq $0x20, %rdi
callq 0x86320
movq %rax, %rsi
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movl $0x8, %edx
callq 0x86e30
movq 0x40(%rsp), %rdi
callq 0x86c10
movb %al, 0x4f(%rsp)
jmp 0x107a92
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x107afa
jmp 0x107a9c
movq 0x5d53d(%rip), %rdi     # 0x164fe0
leaq 0x2bc30(%rip), %rsi     # 0x1336da
callq 0x86700
movq %rax, 0x38(%rsp)
jmp 0x107ab6
movq 0x38(%rsp), %rdi
movq 0x5d4ae(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0x107ac9
movb $0x0, 0x407(%rsp)
movl $0x1, 0x1e0(%rsp)
jmp 0x107ba7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x107bca
leaq 0x1c0(%rsp), %rdi
callq 0x86a30
jmp 0x107b09
jmp 0x107b0b
leaq 0x1f0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x86140
movq %rax, 0x30(%rsp)
jmp 0x107b27
movq 0x30(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x86b60
movq %rax, 0x28(%rsp)
jmp 0x107b42
movq 0x28(%rsp), %rax
cmpq $0x0, %rax
je 0x107b8d
movq 0x58(%rsp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x91220
jmp 0x107b68
jmp 0x107b0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x86f68
jmp 0x107bc8
leaq 0x1c0(%rsp), %rdi
callq 0x86f68
jmp 0x107b9c
movl $0x0, 0x1e0(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x861c0
movl 0x1e0(%rsp), %eax
testl %eax, %eax
je 0x107bc6
jmp 0x107bc1
jmp 0x107d44
jmp 0x107bde
jmp 0x107bca
leaq 0x1f0(%rsp), %rdi
callq 0x861c0
jmp 0x107bd9
jmp 0x107d55
leaq 0x1b8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x86db0
movq 0x58(%rsp), %rax
movq 0x18(%rsp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x864a0
movb %al, 0x27(%rsp)
jmp 0x107c0c
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x107c83
jmp 0x107c16
movq 0x5d3c3(%rip), %rdi     # 0x164fe0
leaq 0x2bafc(%rip), %rsi     # 0x133720
callq 0x86700
movq %rax, 0x10(%rsp)
jmp 0x107c30
movq 0x10(%rsp), %rdi
movq 0x5d334(%rip), %rsi     # 0x164f70
callq 0x86770
jmp 0x107c43
leaq 0x1b8(%rsp), %rdi
callq 0x861e0
jmp 0x107c52
movb $0x0, 0x407(%rsp)
movl $0x1, 0x1e0(%rsp)
jmp 0x107d24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x107d33
leaq 0x60(%rsp), %rdi
callq 0x86260
jmp 0x107c8f
jmp 0x107c91
leaq 0x1b8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x86190
movb %al, 0xf(%rsp)
jmp 0x107ca9
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x107cb3
jmp 0x107ce6
movq 0x58(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x107830
jmp 0x107cc4
jmp 0x107c91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x86b30
jmp 0x107d22
leaq 0x1b8(%rsp), %rdi
callq 0x861e0
jmp 0x107cf5
movq 0x58(%rsp), %rdi
callq 0x107140
jmp 0x107d01
movb $0x1, 0x407(%rsp)
movl $0x1, 0x1e0(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x86b30
jmp 0x107d20
jmp 0x107d24
jmp 0x107d33
leaq 0x1b8(%rsp), %rdi
callq 0x86150
jmp 0x107d44
leaq 0x1b8(%rsp), %rdi
callq 0x86150
jmp 0x107d42
jmp 0x107d55
movb 0x407(%rsp), %al
andb $0x1, %al
addq $0x408, %rsp            # imm = 0x408
retq
movq 0x1e8(%rsp), %rdi
callq 0x86d80
movq %rax, %rdi
callq 0x91290
nopw (%rax,%rax)