// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_shortRNA.cpp
// Function: shortRNAMain(int, char**)
int shortRNAMain(int argc, char** argv) {
    parseShortRNAOptions(argc, argv);
    
    std::ifstream* smallRNAFile = new std::ifstream(opt::smallRNAFile);
    
    string refFastaFileRoot;
    if (opt::out.empty()) {
        refFastaFileRoot = stripExtension(opt::smallRNAFile);
    } else {
        refFastaFileRoot = opt::out;
    }
    
    string outDistribution = refFastaFileRoot + "smallRNAdist.forR";
    string outDistributionUnique = refFastaFileRoot + "smallRNAdistUnique.forR";
  
    std::cerr << "Output will be in: " << outDistribution << std::endl;
    std::cerr << "and: " << outDistributionUnique << std::endl;
    std::ofstream* outDistributionFile = new std::ofstream(outDistribution);
    std::ofstream* outDistributionUniqueFile = new std::ofstream(outDistributionUnique);
    
    std::map<string, bool> seen;
    
    string line;
    getline(*smallRNAFile, line);
    bool fastq = false;
    if (line[0] == '@') { fastq = true; } else if (line[0] == '>') { fastq = false; } else { std::cerr << "File format not recognised" << std::endl; exit(1); }
    int linesRead = 1;
    
    std::vector<std::vector<int> > counts; std::vector<std::vector<int> > uniqueCounts; counts.resize(34); uniqueCounts.resize(34);
    for (std::vector<std::vector<int> >::size_type i = 0; i != counts.size(); i++) {
        counts[i].resize(4); uniqueCounts[i].resize(4);
    }
    
    while (getline(*smallRNAFile, line)) {
        linesRead++;
        if ((!fastq && (linesRead % 2 == 0))
            || (fastq && ((linesRead+2) % 4 == 0))) {
            if (line[0] == 'N') { continue; }
            else {
                // std::cerr << "Seq: " << line << std::endl;
                string::size_type l = line.length();
                if (seen.find(line) == seen.end()) {
                    switch (line[0]) {
                        case 'A': counts[l][0]++; uniqueCounts[l][0]++;
                            // std::cerr << "l: " << l << " fb: " << line[0] << "c: " << counts[l][0] << std::endl;
                            break;
                        case 'C': counts[l][1]++; uniqueCounts[l][1]++; break;
                        case 'G': counts[l][2]++; uniqueCounts[l][2]++; break;
                        case 'T': counts[l][3]++; uniqueCounts[l][3]++; break;
                        default: std::cerr << "Unknown base in the sequence: " << line[0] << " Exiting..." << std::endl; exit(1);
                    }
                    seen[line] = true;
                } else {
                    switch (line[0]) {
                        case 'A': counts[l][0]++;
                            // std::cerr << "l: " << l << " fb: " << line[0] << "c: " << counts[l][0] << std::endl;
                            break;
                        case 'C': counts[l][1]++; break;
                        case 'G': counts[l][2]++; break;
                        case 'T': counts[l][3]++; break;
                        default: std::cerr << "Unknown base in the sequence: " << line[0] << " Exiting..." << std::endl; exit(1);
                    }
                }
            }
        }
    }
    
    //std::cerr << "Counts_size: " << counts.size() << " " << counts[18][1] << std::endl;
    
    for (std::vector<int>::size_type j = 0; j != 4; j++) {
        for (std::vector<std::vector<int> >::size_type i = 18; i != counts.size(); i++) {
            //std::cerr << " i: " << i << " " << counts[i][j] << std::endl;
            if (i == (counts.size()-1)) {
                *outDistributionFile << counts[i][j] << std::endl;
                *outDistributionUniqueFile << uniqueCounts[i][j] << std::endl;
            }
            else {
                *outDistributionFile << counts[i][j] << "\t";
                *outDistributionUniqueFile << uniqueCounts[i][j] << "\t";
            }
        }
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
callq 0x7328f
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %rbx
leaq 0x6bf1a(%rip), %rsi     # 0xdeb88
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8760
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpq $0x0, 0x6bf1e(%rip)     # 0xdebb0
je 0x72ca7
leaq 0x6bf0d(%rip), %rsi     # 0xdeba8
leaq 0x68(%rsp), %rdi
callq 0x82a0
jmp 0x72cd8
leaq 0x6beda(%rip), %rsi     # 0xdeb88
leaq 0x88(%rsp), %rdi
callq 0x404d7
leaq 0x68(%rsp), %rdi
leaq 0x88(%rsp), %r14
movq %r14, %rsi
callq 0x8550
movq %r14, %rdi
callq 0x8978
leaq 0x39e26(%rip), %rdx     # 0xacb05
leaq 0xd8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x28806
leaq 0x39e1f(%rip), %rdx     # 0xacb17
leaq 0xb8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x28806
movq 0x6a2d7(%rip), %rdi     # 0xdcfe8
leaq 0x39e17(%rip), %rsi     # 0xacb2f
callq 0x8480
leaq 0xd8(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq 0x6a2ac(%rip), %rdi     # 0xdcfe8
leaq 0x1fb37(%rip), %rsi     # 0x9287a
callq 0x8480
leaq 0xb8(%rsp), %rsi
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r14
leaq 0xd8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x8900
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r15
leaq 0xb8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x8900
leaq 0x90(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x80a0
movq 0x48(%rsp), %rax
movzbl (%rax), %r13d
cmpl $0x3e, %r13d
je 0x72df4
cmpl $0x40, %r13d
jne 0x731b7
movq %rbx, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
pushq $0x22
popq %rsi
callq 0x73428
leaq 0x30(%rsp), %rdi
pushq $0x22
popq %rsi
callq 0x73428
xorl %ebx, %ebx
pushq $0x4
popq %r12
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %rax, %rbp
je 0x72e6f
addq %rbx, %rdi
movq %r12, %rsi
callq 0x43aec
movq 0x30(%rsp), %rdi
addq %rbx, %rdi
movq %r12, %rsi
callq 0x43aec
incq %rbp
addq $0x18, %rbx
jmp 0x72e31
pushq $0x4
popq %rbx
leaq 0x48(%rsp), %r12
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x7301f
cmpb $0x40, %r13b
je 0x72f13
leal -0x3(%rbx), %eax
andl $0x1, %eax
je 0x72f13
movq 0x48(%rsp), %rax
cmpb $0x4e, (%rax)
je 0x73018
movq 0x50(%rsp), %rbp
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x73642
movq 0x48(%rsp), %rcx
movzbl (%rcx), %ecx
leaq 0x90(%rsp), %rdx
cmpq %rdx, %rax
je 0x72f2b
cmpl $0x54, %ecx
je 0x72f7f
cmpl $0x43, %ecx
je 0x72f91
cmpl $0x47, %ecx
je 0x72f6d
cmpl $0x41, %ecx
jne 0x7313f
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl (%rax)
jmp 0x72fa1
cmpb $0x40, %r13b
jne 0x73018
testb $0x3, %bl
jne 0x73018
jmp 0x72ea7
cmpl $0x41, %ecx
je 0x72fc7
cmpl $0x43, %ecx
je 0x72fe1
cmpl $0x47, %ecx
je 0x72fa8
cmpl $0x54, %ecx
jne 0x7317b
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0xc(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rcx), %rax
addq $0xc, %rax
jmp 0x72ffe
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0x8(%rax)
jmp 0x72fa1
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0xc(%rax)
jmp 0x72fa1
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0x4(%rax)
movq 0x8(%rsp), %rbp
jmp 0x73018
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0x8(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rcx), %rax
addq $0x8, %rax
jmp 0x72ffe
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl (%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rcx), %rax
jmp 0x72ffe
movq 0x10(%rsp), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
incl 0x4(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rcx), %rax
addq $0x4, %rax
incl (%rax)
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x7345e
movq 0x8(%rsp), %rbp
movb $0x1, (%rax)
incl %ebx
jmp 0x72e7c
xorl %r12d, %r12d
leaq 0x26df5(%rip), %rbx     # 0x99e1e
cmpq $0x4, %r12
je 0x730dc
movl $0x1b0, %r13d           # imm = 0x1B0
pushq $0x12
popq %rbp
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rax, %rbp
je 0x730d4
decq %rax
movq (%rcx,%r13), %rcx
movl (%rcx,%r12,4), %esi
cmpq %rax, %rbp
jne 0x73095
movq %r14, %rdi
callq 0x8840
movq %rax, %rdi
callq 0x8230
movq 0x30(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%r12,4), %esi
movq %r15, %rdi
callq 0x8840
movq %rax, %rdi
callq 0x8230
jmp 0x730c8
movq %r14, %rdi
callq 0x8840
movq %rax, %rdi
movq %rbx, %rsi
callq 0x8480
movq 0x30(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax,%r12,4), %esi
movq %r15, %rdi
callq 0x8840
movq %rax, %rdi
movq %rbx, %rsi
callq 0x8480
incq %rbp
addq $0x18, %r13
jmp 0x7303c
incq %r12
jmp 0x73029
leaq 0x30(%rsp), %rdi
callq 0x3b73c
leaq 0x10(%rsp), %rdi
callq 0x3b73c
leaq 0x48(%rsp), %rdi
callq 0x8978
leaq 0x88(%rsp), %rdi
callq 0x734c4
leaq 0xb8(%rsp), %rdi
callq 0x8978
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0x68(%rsp), %rdi
callq 0x8978
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x69ea2(%rip), %rdi     # 0xdcfe8
leaq 0x39a11(%rip), %rsi     # 0xacb5e
callq 0x8480
movq 0x48(%rsp), %rcx
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x8510
leaq 0x39a14(%rip), %rsi     # 0xacb7d
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
jmp 0x731d2
movq 0x69e66(%rip), %rdi     # 0xdcfe8
leaq 0x399d5(%rip), %rsi     # 0xacb5e
callq 0x8480
movq 0x48(%rsp), %rcx
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x8510
leaq 0x399d8(%rip), %rsi     # 0xacb7d
movq %rax, %rdi
callq 0x8480
movq %rax, %rdi
callq 0x8230
jmp 0x731d2
movq 0x69e2a(%rip), %rdi     # 0xdcfe8
leaq 0x3997e(%rip), %rsi     # 0xacb43
callq 0x8480
movq %rax, %rdi
callq 0x8230
pushq $0x1
popq %rdi
callq 0x8540
jmp 0x731e0
jmp 0x7320d
jmp 0x7320d
movq %rax, %r12
jmp 0x7324c
movq %rax, %r12
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
jmp 0x731ff
jmp 0x7322a
movq %rax, %r12
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0x84a0
jmp 0x73263
jmp 0x7322a
movq %rax, %r12
jmp 0x73270
movq %rax, %r12
jmp 0x7327d
movq %rax, %r12
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
callq 0x84a0
jmp 0x73287
jmp 0x73235
jmp 0x73235
jmp 0x73235
movq %rax, %r12
jmp 0x73263
jmp 0x73235
jmp 0x73235
jmp 0x73235
movq %rax, %r12
leaq 0x30(%rsp), %rdi
callq 0x3b73c
leaq 0x10(%rsp), %rdi
callq 0x3b73c
leaq 0x48(%rsp), %rdi
callq 0x8978
leaq 0x88(%rsp), %rdi
callq 0x734c4
leaq 0xb8(%rsp), %rdi
callq 0x8978
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0x68(%rsp), %rdi
callq 0x8978
movq %r12, %rdi
callq 0x8870