// File: /workspace/github_cpp_makefile_star2_O2/rpetit3[P]fastq-scan/fastq-scan.cpp
// Function: main
int main(int argc, char **argv) {
    // Read command line
    float GENOME_SIZE =  1.0;
    int PHRED_OFFSET = 33;
    bool QC_ONLY = false;
    int opt;
    while ((opt = getopt(argc, argv, "g:p:qvh")) >= 0) {
        switch (opt) {
            case 'g': GENOME_SIZE = atof(optarg); break;
            case 'p': PHRED_OFFSET = atoi(optarg); break;
            case 'q': QC_ONLY = true; break;
            case 'v': return version();
            case 'h': return usage();
        }
    }
    if (!(PHRED_OFFSET == 33 || PHRED_OFFSET == 64)) {
        cerr << "Invalid value for -p (" << PHRED_OFFSET << "), only 33 or 64 are valid" << endl;
        return 1;
    } else if (GENOME_SIZE < 0) {
        cerr << "Invalid value for -g (" << GENOME_SIZE << "), value muse be >= 0" << endl;
        return 1;
    }
    
    if (isatty(0)) return usage();

    // Parse FASTQ
    Stats stats;
    stats.init();
    stats.phred = PHRED_OFFSET;
    string name, seq, plus, qual;
    ifstream in("/dev/stdin", ios::in);
    while(true) {
        if(!getline(in, name, '\n')) break;
        if(!getline(in, seq, '\n')) break;
        if(!getline(in, plus, '\n')) break;
        if(!getline(in, qual, '\n')) break;
        stats.read_length.push_back(seq.length());
        stats.read_total++;
        int missing_qual = stats.transform_quality(qual);
        if (missing_qual == 1){
            cerr << "WARNING: Missing quality for a read.\n";
            cerr << name << "\n";
            cerr << seq << "\n";
            cerr << plus << "\n";
            cerr << qual << "\n";
            cerr << "Please fix it to continue.\n";
            exit(50);
        }
    }
    in.close();

    if (stats.read_total > 0) {
        // Determine Stats
        stats.read_stats();
        stats.qual_stats();
        stats.jsonify_stats(GENOME_SIZE, QC_ONLY);
    } else {
        // Empty file, or nothing to parse
        cerr << "Nothing to parse in STDIN, please verify your file is not empty." << endl;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3a8, %rsp            # imm = 0x3A8
movq %rsi, %r14
movl %edi, %ebp
movss 0x2c1a(%rip), %xmm0     # 0x5004
movss %xmm0, (%rsp)
pushq $0x21
popq %rbx
xorl %r13d, %r13d
leaq 0x2c52(%rip), %r15      # 0x504e
movq 0x5bbd(%rip), %r12      # 0x7fc0
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2040
testl %eax, %eax
js 0x245b
cmpl $0x76, %eax
je 0x24a4
cmpl $0x68, %eax
je 0x24d0
cmpl $0x70, %eax
je 0x244e
cmpl $0x71, %eax
je 0x2449
cmpl $0x67, %eax
jne 0x2403
movq (%r12), %rdi
callq 0x2180
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
jmp 0x2403
movb $0x1, %r13b
jmp 0x2403
movq (%r12), %rdi
callq 0x21c0
movl %eax, %ebx
jmp 0x2403
cmpl $0x21, %ebx
je 0x2469
cmpl $0x40, %ebx
jne 0x24ed
xorps %xmm0, %xmm0
movss (%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x24d9
movq 0x5b73(%rip), %rdi      # 0x7ff0
leaq 0x2c04(%rip), %rsi      # 0x5088
movss %xmm1, (%rsp)
callq 0x2140
movq %rax, %rdi
movss (%rsp), %xmm0
callq 0x20e0
leaq 0x2bfd(%rip), %rsi      # 0x509f
jmp 0x2511
movq 0x5b25(%rip), %rdi      # 0x7fd0
leaq 0x2c91(%rip), %rsi      # 0x5143
callq 0x2140
leaq 0x5c9a(%rip), %rsi      # 0x8158
movq %rax, %rdi
callq 0x2130
movq %rax, %rdi
callq 0x20a0
jmp 0x24d5
callq 0x288f
xorl %ebp, %ebp
jmp 0x2524
xorl %ebp, %ebp
xorl %edi, %edi
callq 0x2210
testl %eax, %eax
je 0x2538
callq 0x288f
jmp 0x2524
movq 0x5afc(%rip), %rdi      # 0x7ff0
leaq 0x2b5b(%rip), %rsi      # 0x5056
callq 0x2140
movq %rax, %rdi
movl %ebx, %esi
callq 0x2200
leaq 0x2b5c(%rip), %rsi      # 0x506d
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20a0
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0xa8(%rsp), %rdi
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x70(%rdi)
movups %xmm0, 0x80(%rdi)
movups %xmm0, 0x90(%rdi)
movups %xmm0, 0xa0(%rdi)
andq $0x0, 0xb0(%rdi)
callq 0x29ac
movl %ebx, 0x160(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x58(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x2af0(%rip), %rsi      # 0x50b5
leaq 0x1a0(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2240
leaq 0x1a0(%rsp), %r14
pushq $0xa
popq %rbp
leaq 0x28(%rsp), %rbx
leaq 0x88(%rsp), %r15
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movl %ebp, %edx
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x276f
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x276f
movq %r14, %rdi
leaq 0x48(%rsp), %rsi
movl %ebp, %edx
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x276f
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x276f
movl 0x10(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4908
incq 0xe0(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2190
leaq 0xa8(%rsp), %rdi
movq %r15, %rsi
callq 0x2a22
movl %eax, %r12d
movq %r15, %rdi
callq 0x2268
cmpl $0x1, %r12d
jne 0x25ed
movq 0x5928(%rip), %rdi      # 0x7ff0
leaq 0x29f1(%rip), %rsi      # 0x50c0
callq 0x2140
movq 0x5915(%rip), %rdi      # 0x7ff0
leaq 0x68(%rsp), %rsi
callq 0x2130
leaq 0x29f8(%rip), %rsi      # 0x50e4
movq %rax, %rdi
callq 0x2140
movq 0x58f5(%rip), %rdi      # 0x7ff0
leaq 0x8(%rsp), %rsi
callq 0x2130
leaq 0x29d8(%rip), %rsi      # 0x50e4
movq %rax, %rdi
callq 0x2140
movq 0x58d5(%rip), %rdi      # 0x7ff0
leaq 0x48(%rsp), %rsi
callq 0x2130
leaq 0x29b8(%rip), %rsi      # 0x50e4
movq %rax, %rdi
callq 0x2140
movq 0x58b5(%rip), %rdi      # 0x7ff0
leaq 0x28(%rsp), %rsi
callq 0x2130
leaq 0x2998(%rip), %rsi      # 0x50e4
movq %rax, %rdi
callq 0x2140
movq 0x5895(%rip), %rdi      # 0x7ff0
leaq 0x2984(%rip), %rsi      # 0x50e6
callq 0x2140
pushq $0x32
popq %rdi
callq 0x2170
leaq 0x1a0(%rsp), %rdi
callq 0x2030
cmpq $0x0, 0xe0(%rsp)
je 0x27bc
leaq 0xa8(%rsp), %rdi
callq 0x2aaa
leaq 0xa8(%rsp), %rdi
callq 0x2c2c
movzbl %r13b, %esi
andl $0x1, %esi
leaq 0xa8(%rsp), %rdi
movss (%rsp), %xmm0
callq 0x2ddc
jmp 0x27d7
movq 0x582d(%rip), %rdi      # 0x7ff0
leaq 0x2938(%rip), %rsi      # 0x5102
callq 0x2140
movq %rax, %rdi
callq 0x20a0
leaq 0x1a0(%rsp), %rdi
callq 0x2050
leaq 0x28(%rsp), %rdi
callq 0x2268
leaq 0x48(%rsp), %rdi
callq 0x2268
leaq 0x8(%rsp), %rdi
callq 0x2268
leaq 0x68(%rsp), %rdi
callq 0x2268
leaq 0xa8(%rsp), %rdi
callq 0x361a
jmp 0x24d5
movq %rax, %rbx
jmp 0x2852
movq %rax, %rbx
jmp 0x287a
jmp 0x2842
jmp 0x2842
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2268
jmp 0x2845
jmp 0x2842
jmp 0x2842
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x2050
leaq 0x28(%rsp), %rdi
callq 0x2268
leaq 0x48(%rsp), %rdi
callq 0x2268
leaq 0x8(%rsp), %rdi
callq 0x2268
leaq 0x68(%rsp), %rdi
callq 0x2268
leaq 0xa8(%rsp), %rdi
callq 0x361a
movq %rbx, %rdi
callq 0x2220