// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/cross/OX/OX.cpp
// Function: OX::crossover(std::vector<int, std::allocator<int>>, std::vector<int, std::allocator<int>>)
vector<int> OX::crossover(vector<int> t1, vector<int> t2){
    uniform_int_distribution<int> dist(0,Globals::TOUR_SIZE-1);
    vector<int> tmp1,tmp2;
    unsigned cut1, cut2;
    
    do{
        cut1 = (unsigned)dist(Globals::urng);
        cut2 = (unsigned)dist(Globals::urng);
        if(cut2<cut1){
            unsigned tmp{cut2};
            cut2 = cut1;
            cut1 = tmp;
        }
        // cout<<"cut1 "<<cut1<<" cut2 "<<cut2<<endl;
    }while(cut1==cut2);


    for (unsigned i{ cut1 }; i <= cut2; i++) {
        tmp2.push_back(t1[i]);
        tmp1.push_back(t2[i]);
    }

    // cout<<"tmp"<<endl;
    // for(int i : tmp1){
    //     cout<<i<<" ";
    // }cout<<endl;

    // for(int i : tmp2){
    //     cout<<i<<" ";
    // }cout<<endl;

    // for(unsigned i=0;i<Globals::TOUR_SIZE;i++){
    //     if(find(tmp1.begin(),tmp1.end(),t1[i])!=tmp1.end()){
    //         t1[i] = -1;
    //     }
    //     if(find(tmp2.begin(),tmp2.end(),t2[i])!=tmp2.end()){
    //         t2[i] = -1;
    //     }
    // }

    for(unsigned i=0;i<tmp1.size();i++){
        t1[find(t1.begin(),t1.end(),tmp1[i]) - t1.begin()] = -1;
        t2[find(t2.begin(),t2.end(),tmp2[i]) - t2.begin()] = -1;
    }

    // cout<<"end"<<endl;
    // for(int i : t1){
    //     cout<<i<<" ";
    // }cout<<endl;

    // for(int i : t2){
    //     cout<<i<<" ";
    // }cout<<endl;

    for(unsigned i=0;i<Globals::TOUR_SIZE;i++){
        if(t1[i]!=-1){
            tmp1.push_back(t1[i]);
        }
        if(t2[i]!=-1){
            tmp2.push_back(t2[i]);
        }
    }

    return getFitness(tmp1)<getFitness(tmp2)?tmp1:tmp2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x38(%rsp)
leaq 0x174d0(%rip), %rax     # 0x3dc68
movl (%rax), %eax
leaq 0x40(%rsp), %r12
andl $0x0, (%r12)
decl %eax
movl %eax, 0x4(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x160fe(%rip), %r13     # 0x3c8c8
movq %r12, %rdi
movq %r13, %rsi
callq 0x94da
movl %eax, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x94da
cmpl %ebp, %eax
je 0x267ca
movl %ebp, %r12d
cmoval %eax, %r12d
cmovbl %eax, %ebp
movq %rsp, %r13
cmpl %r12d, %ebp
ja 0x26820
movl %ebp, %ebx
shlq $0x2, %rbx
movq (%r15), %rsi
addq %rbx, %rsi
leaq 0x20(%rsp), %rdi
callq 0x94e2
addq (%r14), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x94e2
incl %ebp
jmp 0x267f3
xorl %ebx, %ebx
movl %ebx, %ebx
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x2686c
movq (%r15), %rdi
movq 0x8(%r15), %rsi
leaq (%rax,%rbx,4), %rdx
callq 0xa3c6
orl $-0x1, (%rax)
movq (%r14), %rdi
movq 0x8(%r14), %rsi
leaq (,%rbx,4), %rdx
addq 0x20(%rsp), %rdx
callq 0xa3c6
orl $-0x1, (%rax)
incl %ebx
jmp 0x26822
xorl %ebx, %ebx
leaq 0x20(%rsp), %r12
movq %rsp, %r13
xorl %ebp, %ebp
leaq 0x173e9(%rip), %rax     # 0x3dc68
movl (%rax), %eax
cmpq %rax, %rbp
jae 0x268b7
movq (%r15), %rsi
cmpl $-0x1, (%rsi,%rbx)
je 0x2689a
addq %rbx, %rsi
movq %r13, %rdi
callq 0x94e2
movq (%r14), %rsi
cmpl $-0x1, (%rsi,%rbx)
je 0x268ae
addq %rbx, %rsi
movq %r12, %rdi
callq 0x94e2
incq %rbp
addq $0x4, %rbx
jmp 0x26878
movq %rsp, %rbx
movq %rbx, %rdi
callq 0xc060
movq 0x38(%rsp), %r15
movl %eax, %ebp
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xc060
cmpl %eax, %ebp
cmovlq %rbx, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x9210
leaq 0x20(%rsp), %rdi
callq 0x6e4c
movq %rsp, %rdi
callq 0x6e4c
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26915
jmp 0x26915
jmp 0x26915
jmp 0x26915
jmp 0x26915
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6e4c
movq %rsp, %rdi
callq 0x6e4c
movq %rbx, %rdi
callq 0x5610