// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/evo_permute_codons.cpp
// Function: permuteCodons(int, char**)
int permuteCodons(int argc, char** argv) {
    parsePermuteCodonsOptions(argc, argv);
    std::vector<string> allAligmentFiles; string statsFileName; string pcaVectorsFileName;
    
    std::cerr << "Permuting gene coding sequences" << std::endl;
    
    
    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);
    }
    
        
    // Loop over the mutiple alignment files for the first time to load the codons:
    std::vector<string> allSeqs; std::vector<string> sampleNames; std::vector<int> geneLengths;
    for (std::vector<std::string>::size_type i = 0; i != allAligmentFiles.size(); i++) {
        std::ifstream* alignment = new std::ifstream(allAligmentFiles[i].c_str());
        std::string line; int lineNum = 1; int j = 0;
        while (getline(*alignment, line)) {
            if (lineNum % 2 == 1) assert(line[0] == '>');
            lineNum++;
            if (line[0] == '>') {
                if (i == 0)
                    sampleNames.push_back(line);
                continue;
            }
            if (i == 0) {
                allSeqs.push_back(line);
                allSeqs[j].reserve(1000000);
            } else {
                allSeqs[j] += line;
            }
            if (j == 0)
                geneLengths.push_back((int)line.length());
            j++;
        } alignment->close();
        
        assert(allSeqs[0].length() == vector_sum(geneLengths));
        std::cerr << "loaded seqs for: " << allAligmentFiles[i] << std::endl;
    }
    std::cerr << "allSeqs[0].size(): " << allSeqs[0].length() << "; equals " << allSeqs[0].length()/3 << "AA" << std::endl;
    
    // Loop over the mutiple alignment files for the second time to print out the permuted sequences:
    int totalAA = (int)allSeqs[0].length()/3;
    std::random_device rd; // obtain a random number from hardware
    std::mt19937 eng(rd()); // seed the generator
    std::uniform_int_distribution<> randomAApos(0, totalAA-1); // define the range
    for (std::vector<std::string>::size_type i = 0; i != allAligmentFiles.size(); i++) {
        std::string permutedFileName = allAligmentFiles[i] + "_permuted.txt";
        std::ofstream* permutedFile = new std::ofstream(permutedFileName.c_str());
        int thisLengthAA = geneLengths[i]/3;
        std::vector<string> thisSeqs(sampleNames.size(),"");
        for (int j = 0; j < thisLengthAA; j++) {
            int pos = randomAApos(eng);
            for (int k = 0; k < allSeqs.size(); k++) {
                thisSeqs[k] += allSeqs[k].substr(pos*3,3);
            }
        }
        for (int k = 0; k < allSeqs.size(); k++) {
            *permutedFile << sampleNames[k] << std::endl;
            *permutedFile << thisSeqs[k] << std::endl;
            thisSeqs[k] = "";
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2888, %rsp           # imm = 0x2888
callq 0x32c32
xorl %eax, %eax
movq %rax, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
leaq 0x150(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x130(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0xcfee2(%rip), %rbx     # 0x101fe8
leaq 0x9a0f3(%rip), %rsi     # 0xcc200
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x84e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq 0xcfeb0(%rip), %rdi     # 0x101fe8
callq 0x8040
movq %rax, %rdi
callq 0x8300
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbx
movq 0xd075f(%rip), %rsi     # 0x1028b8
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
movq 0xcfe7b(%rip), %rdi     # 0x101fe8
leaq 0x9a0ac(%rip), %rsi     # 0xcc220
movl $0x12, %edx
callq 0x84e0
movq 0xd0733(%rip), %rsi     # 0x1028b8
movq 0xd0734(%rip), %rdx     # 0x1028c0
movq 0xcfe55(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r14, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
leaq 0x110(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x100(%rsp), %r14
leaq 0x30(%rsp), %r15
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x32223
movq %r15, %rdi
movq %r14, %rsi
callq 0x3133c
jmp 0x321e6
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0xd0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movq %rax, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movq 0x30(%rsp), %r14
cmpq %r14, 0x38(%rsp)
je 0x3250b
xorl %r12d, %r12d
leaq 0x178(%rsp), %rbx
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbp
movq %r12, %r15
shlq $0x5, %r15
movq (%r14,%r15), %rsi
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
movq $0x0, 0x180(%rsp)
movb $0x0, 0x188(%rsp)
movl $0x1, %r13d
xorl %r14d, %r14d
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x323c4
movl %r13d, %ecx
andl $0x80000001, %ecx       # imm = 0x80000001
movq 0x178(%rsp), %rsi
movb (%rsi), %al
cmpl $0x1, %ecx
jne 0x3231a
cmpb $0x3e, %al
jne 0x32a18
incl %r13d
jmp 0x32321
incl %r13d
cmpb $0x3e, %al
jne 0x32338
testq %r12, %r12
jne 0x322c0
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3133c
jmp 0x322c0
testq %r12, %r12
je 0x32358
movq %r14, %rdi
shlq $0x5, %rdi
addq 0x10(%rsp), %rdi
movq 0x180(%rsp), %rdx
callq 0x8180
jmp 0x3237b
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3133c
movq %r14, %rdi
shlq $0x5, %rdi
addq 0x10(%rsp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x86f0
testq %r14, %r14
jne 0x323bc
movl 0x180(%rsp), %eax
movl %eax, 0x1500(%rsp)
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x323aa
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0x323bc
leaq 0x70(%rsp), %rdi
leaq 0x1500(%rsp), %rdx
callq 0x33074
incq %r14
jmp 0x322c0
movq %rbp, %rdi
callq 0x80f0
movq 0xcfc15(%rip), %r13     # 0x101fe8
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r14
leaq 0x160(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x32ee6
movq %r14, %xmm0
punpckldq 0x96cb5(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x96cbd(%rip), %xmm0    # 0xc90c0
movq 0x160(%rsp), %rdi
movq 0x168(%rsp), %rax
subq %rdi, %rax
je 0x32440
sarq $0x2, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorps %xmm2, %xmm2
cvtsi2sdl (%rdi,%rcx,4), %xmm2
addsd %xmm2, %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x3242a
jmp 0x32444
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jne 0x32a37
jp 0x32a37
testq %rdi, %rdi
je 0x32475
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movl $0x11, %edx
movq %r13, %rdi
leaq 0x99e24(%rip), %rsi     # 0xcc2a8
callq 0x84e0
movq 0x30(%rsp), %rax
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %r13, %rdi
callq 0x84e0
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbp, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x324ee
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x8480
incq %r12
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rax
subq %r14, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jne 0x3226e
movq 0xcfad6(%rip), %rdi     # 0x101fe8
leaq 0x99da1(%rip), %rsi     # 0xcc2ba
movl $0x13, %edx
callq 0x84e0
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0xcfab5(%rip), %rdi     # 0x101fe8
callq 0x82f0
movq %rax, %rbx
leaq 0x99d8c(%rip), %rsi     # 0xcc2ce
movl $0x9, %edx
movq %rax, %rdi
callq 0x84e0
movq 0x10(%rsp), %rcx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
mulq 0x8(%rcx)
shrq %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x82f0
movq %rax, %rbx
leaq 0x97af5(%rip), %rsi     # 0xca06f
movl $0x2, %edx
movq %rax, %rdi
callq 0x84e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %rbx
leaq 0x178(%rsp), %rdi
callq 0x32f66
leaq 0x178(%rsp), %rdi
callq 0x85e0
imulq $0x55555556, %rbx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movl %eax, %eax
movq %rax, 0x1500(%rsp)
movl $0x1, %edx
movq %rax, %rsi
shrq $0x1e, %rsi
xorl %eax, %esi
imull $0x6c078965, %esi, %eax # imm = 0x6C078965
addl %edx, %eax
movq %rax, 0x1500(%rsp,%rdx,8)
incq %rdx
cmpq $0x270, %rdx            # imm = 0x270
jne 0x325f4
movq $0x270, 0x2880(%rsp) # imm = 0x270
decl %ecx
movl $0x0, 0xb8(%rsp)
movl %ecx, 0xbc(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x3294d
leaq 0x60(%rsp), %rbx
leaq 0xa0(%rsp), %r14
xorl %r15d, %r15d
leaq 0x50(%rsp), %r13
leaq 0x90(%rsp), %r12
movq %r15, %rcx
shlq $0x5, %rcx
movq %rbx, 0x50(%rsp)
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2ba06
movq %r13, %rdi
leaq 0x99c48(%rip), %rsi     # 0xcc2d8
callq 0x88c0
movl $0x200, %edi            # imm = 0x200
callq 0x8470
movq %rax, %rbp
movq 0x50(%rsp), %rsi
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
movq 0x70(%rsp), %rax
movq %r15, 0xd8(%rsp)
movslq (%rax,%r15,4), %rbx
movq 0xc0(%rsp), %r15
movq 0xc8(%rsp), %r13
movq %r14, 0x90(%rsp)
movq %r12, %rdi
leaq 0x9b2e4(%rip), %rdx     # 0xcd9cb
movq %rdx, %rsi
callq 0x28a52
subq %r15, %r13
sarq $0x5, %r13
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0xf(%rsp), %rcx
callq 0x32fe0
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x3272b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x8480
movq %rbp, 0xb0(%rsp)
cmpl $0x3, %ebx
jl 0x32813
imulq $0x55555556, %rbx, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movq %rcx, 0xe0(%rsp)
xorl %ebp, %ebp
leaq 0xb8(%rsp), %rdi
leaq 0x1500(%rsp), %rsi
movq %rdi, %rdx
callq 0x33214
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq %rsi, %rcx
cmpq %rdx, %rsi
je 0x32802
leal (%rax,%rax,2), %eax
movslq %eax, %r13
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %rdx, %rsi
addq %rbx, %rsi
movl $0x3, %ecx
movq %r12, %rdi
movq %r13, %rdx
callq 0x84a0
movq 0xe8(%rsp), %rdi
addq %rbx, %rdi
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
callq 0x8180
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x327e2
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x8480
incq %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq %rcx, %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %rbx
cmpq %r15, %rax
ja 0x32792
incl %ebp
cmpl 0xe0(%rsp), %ebp
jne 0x3275a
jmp 0x3281d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
cmpq %rsi, %rcx
leaq 0x60(%rsp), %rbx
je 0x328ff
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0xc0(%rsp), %rax
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq 0xb0(%rsp), %rdi
callq 0x84e0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r13, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0xe8(%rsp), %rax
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq 0xb0(%rsp), %rdi
callq 0x84e0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r13, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0xe8(%rsp), %rdi
movq 0x8(%rdi,%r15), %rdx
addq %r15, %rdi
xorl %esi, %esi
leaq 0x9b0f2(%rip), %rcx     # 0xcd9cb
xorl %r8d, %r8d
callq 0x86c0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
incq %rbp
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rbp, %rax
ja 0x32830
leaq 0xe8(%rsp), %rdi
callq 0x2e784
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x32923
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xd8(%rsp), %r15
incq %r15
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rcx, %r15
leaq 0x50(%rsp), %r13
jne 0x32666
leaq 0x178(%rsp), %rdi
callq 0x8430
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x32974
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0xc0(%rsp), %rdi
callq 0x2e784
leaq 0x10(%rsp), %rdi
callq 0x2e784
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x329b0
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x329d5
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x329fa
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x30(%rsp), %rdi
callq 0x2e784
xorl %eax, %eax
addq $0x2888, %rsp           # imm = 0x2888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x99814(%rip), %rdi     # 0xcc233
leaq 0x9981c(%rip), %rsi     # 0xcc242
leaq 0x9982c(%rip), %rcx     # 0xcc259
movl $0x42, %edx
callq 0x82c0
leaq 0x9983b(%rip), %rdi     # 0xcc279
leaq 0x997fd(%rip), %rsi     # 0xcc242
leaq 0x9980d(%rip), %rcx     # 0xcc259
movl $0x54, %edx
callq 0x82c0
jmp 0x32c2a
jmp 0x32a7f
jmp 0x32acd
movq %rax, %r12
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0x32bc9
jmp 0x32aee
jmp 0x32a73
movq %rax, %r12
jmp 0x32bce
jmp 0x32acd
jmp 0x32aee
movq %rax, %r12
jmp 0x32b6b
jmp 0x32a89
movq %rax, %r12
jmp 0x32b54
movq %rax, %r12
movl $0x200, %esi            # imm = 0x200
movq %rbp, %rdi
jmp 0x32abe
movq %rax, %r12
jmp 0x32ac3
movq %rax, %r12
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x32ac3
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x60(%rsp), %rbx
jmp 0x32b54
movq %rax, %r12
jmp 0x32b78
movq %rax, %r12
movl $0x208, %esi            # imm = 0x208
movq %rbp, %rdi
jmp 0x32b11
movq %rax, %r12
jmp 0x32ba9
jmp 0x32aee
jmp 0x32b1d
movq %rax, %r12
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x32b78
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x32b78
movq %rax, %r12
jmp 0x32b47
movq %rax, %r12
jmp 0x32b42
movq %rax, %r12
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x32b42
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x60(%rsp), %rbx
leaq 0xe8(%rsp), %rdi
callq 0x2e784
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x32b6b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x178(%rsp), %rdi
callq 0x8430
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x32b92
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0xc0(%rsp), %rdi
callq 0x2e784
leaq 0x10(%rsp), %rdi
callq 0x2e784
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x32bce
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x32bf3
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x32c18
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x30(%rsp), %rdi
callq 0x2e784
movq %r12, %rdi
callq 0x8840
movq %rax, %rdi
callq 0x288e1