// File: /workspace/github_cpp_makefile_star2_O1/gabrielfelipeg[P]TravellingSalesman-GeneticAlgo/src/population.cpp
// Function: Population::crossingOver(Individual&, Individual&)
std::pair < Individual, Individual > Population::crossingOver(Individual &a, Individual &b){
    int left = rand()%a.chromosome.size();
    int right = std::min(left + (a.chromosome.size() / 3), a.chromosome.size() - 1);
    std::vector <int> freq1(a.chromosome.size(), 0);
    std::vector <int> freq2(a.chromosome.size(), 0);
    Individual ret1(std::vector<int>(a.chromosome.size(), -1));
    Individual ret2(std::vector<int>(a.chromosome.size(), -1));

    for(int i = left; i <= right; i++){
        ret1.chromosome[i] = a.chromosome[i];
        ret2.chromosome[i] = b.chromosome[i];
        freq1[ret1.chromosome[i]]++;
        freq2[ret2.chromosome[i]]++;
    }

    bool conflito = true;
    while(conflito){
        conflito = false;
        for(int i = 0; i < ret1.chromosome.size(); i++){
            if(ret1.chromosome[i] == -1 && freq1[b.chromosome[i]]){
                conflito = true;
                ret1.chromosome[i] = a.chromosome[i];
                freq1[ret1.chromosome[i]]++;
            }
        }
    }
    conflito = true;
    while(conflito){
        conflito = false;
        for(int i = 0; i < ret2.chromosome.size(); i++){
            if(ret2.chromosome[i] == -1 && freq2[a.chromosome[i]]){
                conflito = true;
                ret2.chromosome[i] = b.chromosome[i];
                freq2[ret2.chromosome[i]]++;
            }
        }
    }

    for(int i = 0; i < a.chromosome.size(); i++){
        if(ret1.chromosome[i] == -1){
            ret1.chromosome[i] = b.chromosome[i];
        }
        if(ret2.chromosome[i] == -1){
            ret2.chromosome[i] = a.chromosome[i];
        }
    }
    return {ret1, ret2};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, 0x80(%rsp)
callq 0x1040
cltq
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
xorl %r13d, %r13d
xorl %edx, %edx
divq %rsi
movq %rdx, 0x78(%rsp)
movslq %edx, %rbx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %rsi, %rax
mulq %rcx
movq %rdx, %r12
shrq %r12
addq %rbx, %r12
leaq -0x1(%rsi), %rax
cmpq %r12, %rax
cmovbq %rax, %r12
leaq 0x48(%rsp), %rdx
movl %r13d, (%rdx)
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rbp
movq %rbp, %rcx
callq 0x1a70
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
movl %r13d, (%rbp)
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x1a70
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
leaq 0x10(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0xa0(%rsp), %rdi
leaq 0x44(%rsp), %rcx
callq 0x1a70
leaq 0x28(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x185c
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x24ab
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
leaq 0x44(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x88(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x1a70
leaq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x185c
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2502
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
cmpl %r12d, 0x78(%rsp)
jg 0x2552
movq (%r15), %rax
movq 0x28(%rsp), %rcx
movq (%r14), %rdx
movq 0x10(%rsp), %rsi
movq 0x60(%rsp), %rdi
movq 0x48(%rsp), %r8
movslq %r12d, %r9
movl (%rax,%rbx,4), %r10d
movl %r10d, (%rcx,%rbx,4)
movl (%rdx,%rbx,4), %r10d
movl %r10d, (%rsi,%rbx,4)
movslq (%rcx,%rbx,4), %r10
incl (%rdi,%r10,4)
movslq (%rsi,%rbx,4), %r10
incl (%r8,%r10,4)
leaq 0x1(%rbx), %r10
cmpq %r9, %rbx
movq %r10, %rbx
jl 0x2526
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
cmpq %rax, %rcx
movq 0x80(%rsp), %rbx
je 0x25c0
movq (%r14), %rsi
movq 0x60(%rsp), %rdi
movq (%r15), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpl $-0x1, (%rax,%r9,4)
jne 0x25ad
movslq (%rsi,%r9,4), %r11
cmpl $0x0, (%rdi,%r11,4)
je 0x25ad
movslq (%r8,%r9,4), %r10
movl %r10d, (%rax,%r9,4)
incl (%rdi,%r10,4)
movb $0x1, %r10b
incq %r9
cmpq %r9, %rdx
jne 0x258c
cmpq %rax, %rcx
je 0x25c0
testb $0x1, %r10b
jne 0x257b
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
cmpq %rax, %rcx
je 0x2626
movq (%r15), %rsi
movq 0x48(%rsp), %rdi
movq (%r14), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpl $-0x1, (%rax,%r9,4)
jne 0x2613
movslq (%rsi,%r9,4), %r11
cmpl $0x0, (%rdi,%r11,4)
je 0x2613
movslq (%r8,%r9,4), %r10
movl %r10d, (%rax,%r9,4)
incl (%rdi,%r10,4)
movb $0x1, %r10b
incq %r9
cmpq %r9, %rdx
jne 0x25f2
cmpq %rax, %rcx
je 0x2626
testb $0x1, %r10b
jne 0x25e1
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
je 0x2674
sarq $0x2, %rcx
movq 0x28(%rsp), %rdx
movq (%r14), %rsi
movq 0x10(%rsp), %rdi
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %r8d, %r8d
cmpl $-0x1, (%rdx,%r8,4)
jne 0x265d
movl (%rsi,%r8,4), %r9d
movl %r9d, (%rdx,%r8,4)
cmpl $-0x1, (%rdi,%r8,4)
jne 0x266c
movl (%rax,%r8,4), %r9d
movl %r9d, (%rdi,%r8,4)
incq %r8
cmpq %r8, %rcx
jne 0x264e
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x2d80
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x269d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x26b4
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x26cb
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x26e2
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2730
movq 0x20(%rsp), %rsi
jmp 0x2723
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2730
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
jmp 0x2730
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2766
movq 0x38(%rsp), %rsi
jmp 0x2759
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x2766
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
jmp 0x2766
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2782
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
jmp 0x2782
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2799
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq %rbx, %rdi
callq 0x11c0
nop