// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/evo_DNA_to_Protein.cpp
// Function: DNAtoProtein(int, char**)
int DNAtoProtein(int argc, char** argv) {
    parseDNAtoProteinOptions(argc, argv);
    std::vector<string> allAligmentFiles; string AAFileName;
    std::vector<string> allNewLabels;
    
    std::cerr << "Translate multiple aligments from DNA to protein" << std::endl;
    
    if (opt::alignmentFile != "") {
        allAligmentFiles.push_back(opt::alignmentFile);
        // look at suffix
        size_t suffixPos = opt::alignmentFile.find_last_of('.');
        if (suffixPos !=  std::string::npos) {
            if (opt::alignmentFile.substr(suffixPos) == ".fa" || opt::alignmentFile.substr(suffixPos) == ".fasta")
                std::cerr << "for the gene: " << stripExtension(opt::alignmentFile) << std::endl;
            else
                std::cerr << "for the gene: " << opt::alignmentFile << std::endl;
        } else {
            std::cerr << "for the gene: " << opt::alignmentFile << std::endl;
        }
    } else {
        std::ifstream* alignmentList = new std::ifstream(opt::alignmentListFile.c_str());
        std::cerr << "for the genes in: " << opt::alignmentListFile << std::endl;
        std::string line;
        while (getline(*alignmentList, line)) {
            allAligmentFiles.push_back(line);
        }
    }
    if (opt::newLabelFile != "") {
        std::cerr << "using labels from: " << opt::newLabelFile << std::endl;
        std::ifstream* newLabels = new std::ifstream(opt::newLabelFile.c_str());
        std::string line;
        while (getline(*newLabels, line)) {
            allNewLabels.push_back(line);
        }
    }
    
    // Loop over the mutiple alignment files:
    for (std::vector<std::string>::size_type i = 0; i != allAligmentFiles.size(); i++) {
        std::ifstream* alignment = new std::ifstream(allAligmentFiles[i].c_str());
        std::vector<string> allSeqs; std::vector<string> allSeqsAA;
        // Load the DNA alignment
        std::string line; int lineNum = 1;
        while (getline(*alignment, line)) {
            if (lineNum % 2 == 1) assert(line[0] == '>');
            lineNum++;
            if (line[0] == '>' && opt::newLabelFile != "") continue;
            if (line[0] == '>' && opt::newLabelFile == "") { allNewLabels.push_back(line); continue; }
            allSeqs.push_back(line);
        } alignment->close();
        
       // std::cerr << "loaded seqs for: " << allAligmentFiles[i] << std::endl;
        //std::cerr << "allSeqs.size(): " << allSeqs.size() << std::endl;
        // Translate to Amino Acid sequences:
        std::string::size_type geneLengthNt = allSeqs[0].length();
        int numSamples = (int)allSeqs.size();
        std::vector<string> altCodons; altCodons.resize(numSamples);
        allSeqsAA.resize(numSamples);
        if (numSamples > 0) {
            assert(geneLengthNt % 3 == 0); // The gene length must be divisible by three
            for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
                allSeqsAA[j].reserve(geneLengthNt/3);
            }
            for (string::size_type k = 0; k != geneLengthNt; k++) {
                for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
                    altCodons[j] += allSeqs[j][k];
                }
                // Find the types of mutation we are dealing with
                if ((k+1)%3 == 0) {
                    for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
                        assert(allSeqs[j].substr(k-2,3) == altCodons[j]);
                        allSeqsAA[j] += getAminoAcidOneLetterCode(altCodons[j]);
                    }
                    for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
                        altCodons[j] = "";
                    }
                }
            }
        } else{
            std::cerr << allAligmentFiles[i] << "has no alignment.." << std::endl;
        }
        //std::cerr << "processed seqs for: " << allAligmentFiles[i] << std::endl;
        //std::cerr << "going to output: " << allAligmentFiles[i] << std::endl;
        size_t suffixPos = allAligmentFiles[i].find_last_of('.');
        if (suffixPos != std::string::npos) {
            if (allAligmentFiles[i].substr(suffixPos) == ".fa" || allAligmentFiles[i].substr(suffixPos) == ".fasta")
                AAFileName = opt::outFolder + stripExtension(allAligmentFiles[i]) + "_AA.fasta";
            else
                AAFileName = opt::outFolder + allAligmentFiles[i] + "_AA.fasta";
        } else {
            AAFileName = opt::outFolder + allAligmentFiles[i] + "_AA.fasta";
        }
        //std::cerr << "into: " << AAFileName << std::endl;
        std::ofstream* AAalignment = new std::ofstream(AAFileName.c_str());
        for (std::vector<std::string>::size_type j = 0; j != numSamples; j++) {
            *AAalignment << allNewLabels[j] << std::endl;
            *AAalignment << allSeqsAA[j] << std::endl;
        } AAalignment->close();
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
callq 0x354f6
andq $0x0, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
leaq 0xe8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movaps %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movq 0xa8480(%rip), %rdi     # 0xdcfe8
leaq 0x66081(%rip), %rsi     # 0x9abf0
callq 0x8480
movq %rax, %rdi
callq 0x8230
leaq 0xa9285(%rip), %rdi     # 0xdde08
leaq 0x65295(%rip), %rsi     # 0x99e1f
callq 0x2ea9b
testb %al, %al
je 0x34c02
leaq 0xa926e(%rip), %rsi     # 0xdde08
leaq 0x30(%rsp), %rdi
callq 0x2b0a4
leaq 0xa925d(%rip), %rdi     # 0xdde08
pushq $0x2e
popq %rsi
pushq $-0x1
popq %rdx
callq 0x8940
cmpq $-0x1, %rax
je 0x34d22
movq %rax, %rbx
leaq 0xa923e(%rip), %rsi     # 0xdde08
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %rax, %rdx
callq 0x84b0
leaq 0x746a9(%rip), %rsi     # 0xa928a
leaq 0x8(%rsp), %rdi
callq 0x2193f
testb %al, %al
je 0x34c90
leaq 0x8(%rsp), %rdi
callq 0x8978
jmp 0x34cda
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r14
movq 0xa9212(%rip), %rsi     # 0xdde28
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movq 0xa83c0(%rip), %rdi     # 0xdcfe8
leaq 0x61a21(%rip), %rsi     # 0x96650
callq 0x8480
leaq 0xa91ed(%rip), %rsi     # 0xdde28
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rbx
leaq 0x30(%rsp), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x34d16
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2b0a4
jmp 0x34c66
leaq 0xa9171(%rip), %rsi     # 0xdde08
leaq 0x118(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %rbx, %rdx
callq 0x84b0
leaq 0x65fe8(%rip), %rsi     # 0x9ac99
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
callq 0x2193f
movl %eax, %ebp
movq %rbx, %rdi
callq 0x8978
leaq 0x8(%rsp), %rdi
callq 0x8978
testb %bpl, %bpl
je 0x34d22
movq 0xa8307(%rip), %rdi     # 0xdcfe8
leaq 0x650b5(%rip), %rsi     # 0x99d9d
callq 0x8480
movq %rax, %rbx
leaq 0xa9111(%rip), %rsi     # 0xdde08
leaq 0x8(%rsp), %rdi
callq 0x404d7
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
leaq 0x8(%rsp), %rdi
callq 0x8978
jmp 0x34d4c
movq 0xa82bf(%rip), %rdi     # 0xdcfe8
leaq 0x6506d(%rip), %rsi     # 0x99d9d
callq 0x8480
leaq 0xa90cc(%rip), %rsi     # 0xdde08
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
leaq 0xa90f5(%rip), %rdi     # 0xdde48
leaq 0x650c5(%rip), %rsi     # 0x99e1f
callq 0x2ea9b
testb %al, %al
je 0x34dfe
movq 0xa827a(%rip), %rdi     # 0xdcfe8
leaq 0x640f9(%rip), %rsi     # 0x98e6e
callq 0x8480
leaq 0xa90c7(%rip), %rsi     # 0xdde48
movq %rax, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r14
movq 0xa90a3(%rip), %rsi     # 0xdde48
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rbx
leaq 0xc0(%rsp), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x34df4
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2b0a4
jmp 0x34dce
leaq 0x8(%rsp), %rdi
callq 0x8978
xorl %r12d, %r12d
leaq 0x118(%rsp), %r13
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %rax
subq %rbx, %rax
sarq $0x5, %rax
cmpq %rax, %r12
je 0x3534d
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r15
movq %r12, %rax
shlq $0x5, %rax
movq (%rbx,%rax), %rsi
movq %rax, %rbx
movq %r15, %rdi
pushq $0x8
popq %rdx
callq 0x8890
andq $0x0, 0x80(%rsp)
andq $0x0, 0xb0(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0xa0(%rsp)
movb $0x0, 0x18(%rsp)
pushq $0x1
popq %rbp
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x34f25
movq 0x8(%rsp), %rax
movb (%rax), %al
testb $0x1, %bpl
jne 0x34eb8
orl $0x1, %ebp
cmpb $0x3e, %al
je 0x34ec2
jmp 0x34f11
cmpb $0x3e, %al
jne 0x353a2
incl %ebp
leaq 0xa8f7f(%rip), %rdi     # 0xdde48
leaq 0x64f4f(%rip), %rsi     # 0x99e1f
callq 0x2ea9b
testb %al, %al
jne 0x34e83
movq 0x8(%rsp), %rax
cmpb $0x3e, (%rax)
jne 0x34f11
leaq 0xa8f5e(%rip), %rdi     # 0xdde48
leaq 0x64f2e(%rip), %rsi     # 0x99e1f
callq 0x2193f
testb %al, %al
je 0x34f11
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2b0a4
jmp 0x34e83
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2b0a4
jmp 0x34e83
movq %rbx, 0x28(%rsp)
movq %r12, 0x90(%rsp)
movq %r15, %rdi
callq 0x80e0
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %r14
movq 0x8(%rax), %rcx
movq %rcx, 0x98(%rsp)
subq %rax, %r14
shrq $0x5, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movslq %r14d, %rbx
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x34872
pushq $-0x1
popq %rbp
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x34872
testl %r14d, %r14d
jle 0x350c4
movq 0x98(%rsp), %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
testq %rdx, %rdx
jne 0x353bb
movq %rax, %r14
movq %rbx, %r15
xorl %r12d, %r12d
subq $0x1, %r15
jb 0x34fd2
movq 0xa0(%rsp), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x8700
addq $0x20, %r12
jmp 0x34fb3
xorl %r15d, %r15d
cmpq 0x98(%rsp), %r15
je 0x350f1
movq %r15, %r14
movq %rbx, %r15
xorl %r12d, %r12d
subq $0x1, %r15
jb 0x35013
movq 0x70(%rsp), %rax
movq (%rax,%r12), %rax
movsbl (%rax,%r14), %esi
movq 0x50(%rsp), %rdi
addq %r12, %rdi
callq 0x8400
addq $0x20, %r12
jmp 0x34fec
leaq 0x1(%r14), %r15
movq %r15, %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
testq %rdx, %rdx
jne 0x34fd5
addq $-0x2, %r14
movq %rbx, %rbp
xorl %r12d, %r12d
subq $0x1, %rbp
jb 0x35093
movq 0x70(%rsp), %rsi
addq %r12, %rsi
movq %r13, %rdi
movq %r14, %rdx
pushq $0x3
popq %rcx
callq 0x84b0
movq 0x50(%rsp), %rsi
addq %r12, %rsi
movq %r13, %rdi
callq 0x26b06
testb %al, %al
je 0x35385
movq %r13, %rdi
callq 0x8978
movq 0x50(%rsp), %rdi
addq %r12, %rdi
callq 0x35736
movq 0xa0(%rsp), %rdi
addq %r12, %rdi
movsbl %al, %esi
callq 0x8400
addq $0x20, %r12
jmp 0x35031
movq %rbx, %r14
xorl %r12d, %r12d
leaq 0x64d7f(%rip), %rbp     # 0x99e1f
subq $0x1, %r14
jb 0x350bc
movq 0x50(%rsp), %rdi
addq %r12, %rdi
movq %rbp, %rsi
callq 0x88f0
addq $0x20, %r12
jmp 0x350a0
pushq $-0x1
popq %rbp
jmp 0x34fd5
movq 0x30(%rsp), %rsi
addq 0x28(%rsp), %rsi
movq 0xa7f13(%rip), %rdi     # 0xdcfe8
callq 0x8430
movq %rax, %rdi
leaq 0x64d05(%rip), %rsi     # 0x99de9
callq 0x8480
movq %rax, %rdi
callq 0x8230
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %r15
addq %r15, %rdi
pushq $0x2e
popq %rsi
movq %rbp, %rdx
callq 0x8940
cmpq $-0x1, %rax
je 0x35160
movq %rax, %r14
movq 0x30(%rsp), %rsi
addq %r15, %rsi
movq %r13, %rdi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x84b0
movq 0x90(%rsp), %r12
movq %r13, %rdi
leaq 0x74150(%rip), %rsi     # 0xa928a
callq 0x2193f
testb %al, %al
je 0x351b1
movq %r13, %rdi
callq 0x8978
leaq 0xf8(%rsp), %r15
leaq 0x138(%rsp), %r14
jmp 0x35204
addq 0x30(%rsp), %r15
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0xa8cf1(%rip), %rsi     # 0xdde68
movq %r15, %rdx
callq 0x28b6d
movq 0x90(%rsp), %r12
movq %r13, %rdi
movq %r14, %rsi
leaq 0x65b02(%rip), %rdx     # 0x9ac96
callq 0x28a29
leaq 0xd8(%rsp), %rdi
movq %r13, %rsi
callq 0x8550
movq %r13, %rdi
jmp 0x35255
movq 0x30(%rsp), %rsi
addq 0x28(%rsp), %rsi
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x84b0
movq %r15, %rdi
leaq 0x65abe(%rip), %rsi     # 0x9ac99
callq 0x2193f
movl %eax, %r14d
movq %r15, %rdi
callq 0x8978
movq %r13, %rdi
callq 0x8978
testb %r14b, %r14b
leaq 0x138(%rsp), %r14
je 0x35302
movq 0x28(%rsp), %rsi
addq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x404d7
movq %r15, %rdi
leaq 0xa8c48(%rip), %rsi     # 0xdde68
movq %r14, %rdx
callq 0x28aaf
movq %r13, %rdi
movq %r15, %rsi
leaq 0x65a61(%rip), %rdx     # 0x9ac96
callq 0x28a29
leaq 0xd8(%rsp), %rdi
movq %r13, %rsi
callq 0x8550
movq %r13, %rdi
callq 0x8978
movq %r15, %rdi
callq 0x8978
movq %r14, %rdi
callq 0x8978
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r14
movq 0xd8(%rsp), %rsi
movq %rax, %rdi
pushq $0x10
popq %rdx
callq 0x84e0
xorl %r15d, %r15d
subq $0x1, %rbx
jb 0x352c7
movq 0xc0(%rsp), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movq 0xa0(%rsp), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x8430
movq %rax, %rdi
callq 0x8230
addq $0x20, %r15
jmp 0x35285
movq %r14, %rdi
callq 0x8620
leaq 0x50(%rsp), %rdi
callq 0x28a08
leaq 0x8(%rsp), %rdi
callq 0x8978
leaq 0xa0(%rsp), %rdi
callq 0x28a08
leaq 0x70(%rsp), %rdi
callq 0x28a08
incq %r12
jmp 0x34e09
movq 0x28(%rsp), %rdx
addq 0x30(%rsp), %rdx
movq %r15, %rdi
leaq 0xa8b52(%rip), %rsi     # 0xdde68
callq 0x28b6d
movq %r13, %rdi
movq %r15, %rsi
leaq 0x6596e(%rip), %rdx     # 0x9ac96
callq 0x28a29
leaq 0xd8(%rsp), %rdi
movq %r13, %rsi
callq 0x8550
movq %r13, %rdi
callq 0x8978
movq %r15, %rdi
jmp 0x3525d
leaq 0xc0(%rsp), %rdi
callq 0x28a08
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0x30(%rsp), %rdi
callq 0x28a08
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x658e1(%rip), %rdi     # 0x9ac6d
leaq 0x6588e(%rip), %rsi     # 0x9ac21
leaq 0x6589e(%rip), %rcx     # 0x9ac38
pushq $0x77
popq %rdx
callq 0x82f0
leaq 0x612ba(%rip), %rdi     # 0x96663
leaq 0x65871(%rip), %rsi     # 0x9ac21
leaq 0x65881(%rip), %rcx     # 0x9ac38
pushq $0x5d
jmp 0x3539c
leaq 0x65895(%rip), %rdi     # 0x9ac57
leaq 0x65858(%rip), %rsi     # 0x9ac21
leaq 0x65868(%rip), %rcx     # 0x9ac38
pushq $0x6c
jmp 0x3539c
jmp 0x3547a
jmp 0x35473
jmp 0x35473
jmp 0x3547a
jmp 0x353ef
jmp 0x35473
movq %rax, %rbx
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
jmp 0x3546c
jmp 0x35473
jmp 0x35473
jmp 0x35473
jmp 0x35416
jmp 0x3549c
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x35444
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x35444
jmp 0x3549c
movq %rax, %rbx
jmp 0x3543c
jmp 0x3549c
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x8978
leaq 0x138(%rsp), %rdi
callq 0x8978
jmp 0x3549f
jmp 0x3549c
movq %rax, %rbx
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0x84a0
jmp 0x3549f
jmp 0x3548f
movq %rax, %rbx
movl $0x208, %esi            # imm = 0x208
movq %r15, %rdi
callq 0x84a0
jmp 0x354ca
movq %rax, %rbx
jmp 0x354ca
jmp 0x3547a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8978
jmp 0x354ca
jmp 0x3549c
jmp 0x3549c
jmp 0x3549c
movq %rax, %rbx
jmp 0x354a9
jmp 0x3549c
jmp 0x3549c
jmp 0x3549c
jmp 0x3549c
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x28a08
leaq 0x8(%rsp), %rdi
callq 0x8978
leaq 0xa0(%rsp), %rdi
callq 0x28a08
leaq 0x70(%rsp), %rdi
callq 0x28a08
leaq 0xc0(%rsp), %rdi
callq 0x28a08
leaq 0xd8(%rsp), %rdi
callq 0x8978
leaq 0x30(%rsp), %rdi
callq 0x28a08
movq %rbx, %rdi
callq 0x8870