// File: /workspace/github_cpp_makefile_star2_O3/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, 0x30(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %r13
callq 0x30a0
cltq
movq (%r15), %rcx
movslq (%rcx), %rcx
movq (%r13), %rdx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rdx,%rcx,8), %rsi
subq (%rdx,%rcx,8), %rsi
sarq $0x5, %rsi
xorl %r14d, %r14d
xorl %edx, %edx
divq %rsi
movq %rdx, %rbx
callq 0x30a0
cltq
movq (%r15), %rcx
movslq (%rcx), %rcx
movq (%r13), %rdx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rdx,%rcx,8), %rsi
subq (%rdx,%rcx,8), %rsi
sarq $0x5, %rsi
xorl %edx, %edx
divq %rsi
cmpl %edx, %ebx
movl %edx, %ecx
movl %edx, %eax
cmovgl %ebx, %eax
cmovll %ebx, %ecx
movl %ecx, 0x40(%rsp)
movslq %edx, %rcx
leaq 0x90(%rsp), %rdx
movl %r14d, (%rdx)
movq %r14, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %r14, 0x20(%rdx)
leaq 0x60(%rsp), %rdx
movl %r14d, (%rdx)
movq %r14, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movslq %ebx, %rbp
cmpq %rbp, %rcx
cmovlq %rcx, %rbp
movq %r14, 0x20(%rdx)
cltq
movq %rax, 0x48(%rsp)
leaq 0x88(%rsp), %rbx
leaq 0x58(%rsp), %r14
movq %r15, (%rsp)
movq (%r15), %rax
movslq (%rax), %rcx
movq (%r13), %rdx
leaq (%rcx,%rcx,2), %rcx
movq (%rdx,%rcx,8), %r15
movslq 0x4(%rax), %rax
leaq (%rax,%rax,2), %rax
movq %rbp, %r12
shlq $0x5, %r12
movq (%rdx,%rax,8), %rsi
addq %r12, %rsi
movq %rbx, %rdi
callq 0x8b4c
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3150
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rcx
movq (%r13), %rdx
leaq (%rcx,%rcx,2), %rcx
movq (%rdx,%rcx,8), %r15
movslq (%rax), %rax
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rsi
addq %r12, %rsi
movq %r14, %rdi
callq 0x8b4c
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3150
leaq 0x1(%rbp), %rax
cmpq 0x48(%rsp), %rbp
movq %rax, %rbp
movq (%rsp), %r15
jl 0x805f
movq (%r15), %rcx
movslq (%rcx), %rdx
movq (%r13), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rsi
cmpq %rsi, 0x8(%rax,%rdx,8)
je 0x8480
movslq 0x40(%rsp), %rdx
movq %rdx, 0x50(%rsp)
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbp
leaq 0x58(%rsp), %rbx
leaq 0x10(%rsp), %r14
cmpq 0x50(%rsp), %r15
movq %r15, 0x40(%rsp)
jl 0x81df
cmpq 0x48(%rsp), %r15
jg 0x81df
movq 0x8(%rsp), %rdx
movq (%rdx), %rdi
movslq 0x4(%rcx), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %r15
movq (%rax,%rcx,8), %rsi
addq %r15, %rsi
callq 0x8b0e
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
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
callq 0x8b0e
movq (%r13), %rax
movslq 0x4(%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
movq 0x38(%rsp), %rdi
callq 0x57c4
movl $0x0, (%rax)
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
addq (%rcx,%rax,8), %r15
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x57c4
jmp 0x8442
shlq $0x5, %r15
addq %r15, %rsi
movq %rbp, %rdi
callq 0x931c
leaq 0x90(%rsp), %r12
cmpq %r12, %rax
je 0x82b0
movq (%rsp), %rax
movq (%rax), %rax
movslq (%rax), %rax
movq (%r13), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
movq %rbp, %rdi
callq 0x8b4c
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x5c48
movq %rbp, %rdi
movq %r14, %rsi
callq 0x931c
cmpq %r12, %rax
je 0x826f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8b4c
movq %r14, %rdi
movq %rax, %rsi
callq 0x3150
movq %rbp, %rdi
movq %r14, %rsi
callq 0x931c
jmp 0x8247
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r14, %rsi
callq 0x8b0e
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x57c4
movl $0x0, (%rax)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8303
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x8303
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r13, %r12
movq (%rsp), %r13
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
callq 0x8b0e
movq (%r13), %rax
movslq (%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
movq 0x38(%rsp), %rdi
callq 0x57c4
movl $0x0, (%rax)
movq %r12, %r13
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rax
movq (%r13), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x931c
leaq 0x60(%rsp), %rcx
cmpq %rcx, %rax
je 0x83f2
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rax
movq (%r13), %rcx
leaq (%rax,%rax,2), %rax
addq (%rcx,%rax,8), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8b4c
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x5c48
movq %rbx, %rdi
movq %r14, %rsi
callq 0x931c
movq (%rsp), %r15
leaq 0x60(%rsp), %rcx
cmpq %rcx, %rax
je 0x83ad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8b4c
movq %r14, %rdi
movq %rax, %rsi
callq 0x3150
movq %rbx, %rdi
movq %r14, %rsi
callq 0x931c
jmp 0x8380
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
movq %r14, %rsi
callq 0x8b0e
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x57c4
movl $0x0, (%rax)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x844e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0x844e
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
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rsi
addq %r15, %rsi
callq 0x8b0e
movq (%r13), %rax
movslq 0x4(%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
addq (%rcx,%rax,8), %r15
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x57c4
movl $0x0, (%rax)
movq %r13, %r15
movq %r12, %r13
movq 0x40(%rsp), %rax
incq %rax
movq (%r15), %rcx
movq %rax, %r15
movslq (%rcx), %rdx
movq (%r13), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rsi
movq 0x8(%rax,%rdx,8), %rdx
subq %rsi, %rdx
sarq $0x5, %rdx
cmpq %r15, %rdx
ja 0x812a
leaq 0x58(%rsp), %rdi
callq 0x8bc8
leaq 0x88(%rsp), %rdi
callq 0x8bc8
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x84c6
jmp 0x84c6
jmp 0x84bb
jmp 0x84bb
jmp 0x84c6
jmp 0x84c6
jmp 0x84bb
jmp 0x84bb
jmp 0x84bb
movq %rax, %rbx
jmp 0x84e5
jmp 0x84c6
jmp 0x84c6
jmp 0x84c6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x84e5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x58(%rsp), %rdi
callq 0x8bc8
leaq 0x88(%rsp), %rdi
callq 0x8bc8
movq %rbx, %rdi
callq 0x3450