// File: /workspace/github_cpp_makefile_star2_O2/drarwood[P]gags/GA.cpp
// Function: CrossoverPMX(std::vector<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::allocator<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>&, std::vector<int, std::allocator<int>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::allocator<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>&)
void CrossoverPMX(vector<vector<string> >& p, vector<int>& r, vector<string>& s, vector<vector<string> >& chrXY, map<string, int>& chrXAlleles, map<string, int>& chrYAlleles) {
    
    // define crossover points
    int xoverA = rand() % p[r[0]].size();
    int xoverB = rand() % p[r[0]].size();
    if (xoverA > xoverB) {
        int t  = xoverA;
        xoverA = xoverB;
        xoverB = t;
    }
    
    // Record elements in crossover region in maps: id -> index and map IDs across chromosomes within crossover region
    map<string,string> chrXxOverAlleleMap;
    map<string,string> chrYxOverAlleleMap;
    map<string,string>::iterator it;
    
    for (int i = xoverA; i <= xoverB; ++i) {    
        chrXxOverAlleleMap[p[r[1]][i]] = p[r[0]][i];
        chrYxOverAlleleMap[p[r[0]][i]] = p[r[1]][i];
    }
 
    // Perform the PMX crossover        
    for (int i = 0; i < p[r[0]].size(); ++i) {
        
        if (i < xoverA || i > xoverB) {
            
            // if element not in chromosomal crossover region associated with orginal chr Y
            it = chrXxOverAlleleMap.find(p[r[0]][i]);
            if (it == chrXxOverAlleleMap.end()) {
                chrXY[0].push_back(p[r[0]][i]);
                chrXAlleles[p[r[0]][i]] = 0;
            }
            else {
                string newAllele = chrXxOverAlleleMap[p[r[0]][i]];
                it = chrXxOverAlleleMap.find(newAllele);
                while (it != chrXxOverAlleleMap.end()) {
                    newAllele = chrXxOverAlleleMap[newAllele];
                    it = chrXxOverAlleleMap.find(newAllele);
                } 
                chrXY[0].push_back(newAllele);
                chrXAlleles[newAllele] = 0;
            }
            
            // if element not in chromosomal crossover region associated with orginal chr X
            it = chrYxOverAlleleMap.find(p[r[1]][i]);
            if (it == chrYxOverAlleleMap.end()) {
                chrXY[1].push_back(p[r[1]][i]);
                chrYAlleles[p[r[1]][i]] = 0;
            }
            else {
                string newAllele = chrYxOverAlleleMap[p[r[1]][i]];
                it = chrYxOverAlleleMap.find(newAllele);
                while (it != chrYxOverAlleleMap.end()) {
                    newAllele = chrYxOverAlleleMap[newAllele];
                    it = chrYxOverAlleleMap.find(newAllele);
                } 
                chrXY[1].push_back(newAllele);
                chrYAlleles[newAllele] = 0;
            }            
        }
        else { 
            //CROSSOVER REGION
            chrXY[0].push_back(p[r[1]][i]);
            chrXY[1].push_back(p[r[0]][i]);
            chrXAlleles[p[r[1]][i]] = 0;
            chrYAlleles[p[r[0]][i]] = 0;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x10(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r13
callq 0x30b0
cltq
movq (%r15), %rcx
movslq (%rcx), %rcx
movq (%r13), %rdx
imulq $0x18, %rcx, %rcx
movq 0x8(%rdx,%rcx), %rsi
subq (%rdx,%rcx), %rsi
sarq $0x5, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %rbx
callq 0x30b0
cltq
movq (%r15), %rcx
movslq (%rcx), %rcx
movq (%r13), %rdx
imulq $0x18, %rcx, %rcx
movq 0x8(%rdx,%rcx), %rsi
subq (%rdx,%rcx), %rsi
sarq $0x5, %rsi
xorl %edx, %edx
divq %rsi
cmpl %edx, %ebx
movl %edx, %esi
movslq %edx, %rax
movl %edx, %ecx
cmovgl %ebx, %ecx
cmovll %ebx, %esi
movl %esi, 0x20(%rsp)
leaq 0x40(%rsp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
leaq 0x70(%rsp), %rdx
andl $0x0, (%rdx)
andq $0x0, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
andq $0x0, 0x20(%rdx)
movslq %ebx, %rbp
cmpq %rbp, %rax
cmovlq %rax, %rbp
movslq %ecx, %rax
movq %rax, 0x28(%rsp)
leaq 0x38(%rsp), %rbx
leaq 0x68(%rsp), %r14
movq %r15, (%rsp)
cmpq 0x28(%rsp), %rbp
jg 0x73cb
movq (%r15), %rax
movslq (%rax), %rcx
movq (%r13), %rdx
imulq $0x18, %rcx, %rcx
movq (%rdx,%rcx), %r15
movslq 0x4(%rax), %rax
imulq $0x18, %rax, %rax
movq %rbp, %r12
shlq $0x5, %r12
movq (%rdx,%rax), %rsi
addq %r12, %rsi
movq %rbx, %rdi
callq 0x7c42
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3160
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rcx
movq (%r13), %rdx
imulq $0x18, %rcx, %rcx
movq (%rdx,%rcx), %r15
movslq (%rax), %rax
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rsi
addq %r12, %rsi
movq %r14, %rdi
callq 0x7c42
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3160
incq %rbp
movq (%rsp), %r15
leaq 0x40(%rsp), %r12
jmp 0x7336
movslq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %r8d, %r8d
leaq 0x38(%rsp), %rbp
leaq 0x68(%rsp), %rbx
leaq 0x98(%rsp), %r14
movq (%r15), %rcx
movslq (%rcx), %rdx
movq (%r13), %rax
imulq $0x18, %rdx, %rdx
movq (%rax,%rdx), %rsi
movq 0x8(%rax,%rdx), %rdx
subq %rsi, %rdx
sarq $0x5, %rdx
cmpq %r8, %rdx
jbe 0x76f1
cmpq 0x30(%rsp), %r8
movq %r8, 0x20(%rsp)
jl 0x74c6
cmpq 0x28(%rsp), %r8
jg 0x74c6
movq 0x8(%rsp), %rdx
movq (%rdx), %rdi
movslq 0x4(%rcx), %rcx
imulq $0x18, %rcx, %rcx
movq %r8, %r15
shlq $0x5, %r15
movq (%rax,%rcx), %rsi
addq %r15, %rsi
callq 0x7c16
movq %r13, %r12
movq (%rsp), %r13
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
callq 0x7c16
movq (%r13), %rax
movslq 0x4(%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
movq 0x18(%rsp), %rdi
callq 0x4b44
andl $0x0, (%rax)
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
addq (%rcx,%rax), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x4b44
jmp 0x76d6
movq %r8, %r15
shlq $0x5, %r15
addq %r15, %rsi
movq %rbp, %rdi
callq 0x8408
cmpq %r12, %rax
je 0x756a
movq (%rsp), %rax
movq (%rax), %rax
movslq (%rax), %rax
movq (%r13), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
movq %rbp, %rdi
callq 0x7c42
movq %r14, %rdi
movq %rax, %rsi
callq 0x3320
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8408
cmpq %r12, %rax
je 0x7540
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7c42
movq %r14, %rdi
movq %rax, %rsi
callq 0x3160
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8408
jmp 0x7518
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r14, %rsi
callq 0x7c16
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x4b44
andl $0x0, (%rax)
movq %r14, %rdi
callq 0x3120
jmp 0x75bf
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r13, %r12
movq (%rsp), %r13
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
callq 0x7c16
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
movq 0x18(%rsp), %rdi
callq 0x4b44
andl $0x0, (%rax)
movq %r12, %r13
leaq 0x40(%rsp), %r12
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rax
movq (%r13), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x8408
leaq 0x70(%rsp), %rcx
cmpq %rcx, %rax
je 0x7686
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rax
movq (%r13), %rcx
imulq $0x18, %rax, %rax
addq (%rcx,%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7c42
movq %r14, %rdi
movq %rax, %rsi
callq 0x3320
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8408
movq (%rsp), %r15
leaq 0x70(%rsp), %rcx
cmpq %rcx, %rax
je 0x7658
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7c42
movq %r14, %rdi
movq %rax, %rsi
callq 0x3160
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8408
jmp 0x762b
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
movq %r14, %rsi
callq 0x7c16
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x4b44
andl $0x0, (%rax)
movq %r14, %rdi
callq 0x3120
jmp 0x76e4
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
movq %r13, %r12
movq (%rsp), %r13
movq (%r13), %rax
movslq 0x4(%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rsi
addq %r15, %rsi
callq 0x7c16
movq (%r13), %rax
movslq 0x4(%rax), %rax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
addq (%rcx,%rax), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x4b44
andl $0x0, (%rax)
movq %r13, %r15
movq %r12, %r13
leaq 0x40(%rsp), %r12
movq 0x20(%rsp), %r8
incq %r8
jmp 0x73ea
leaq 0x68(%rsp), %rdi
callq 0x7cd4
leaq 0x38(%rsp), %rdi
callq 0x7cd4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7734
jmp 0x7734
jmp 0x7729
jmp 0x7729
jmp 0x7734
jmp 0x7734
jmp 0x7729
jmp 0x7729
jmp 0x7729
movq %rax, %rbx
jmp 0x7744
jmp 0x7734
jmp 0x7734
jmp 0x7734
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3120
leaq 0x68(%rsp), %rdi
callq 0x7cd4
leaq 0x38(%rsp), %rdi
callq 0x7cd4
movq %rbx, %rdi
callq 0x3410