// File: /workspace/github_cpp_makefile_star2_O3/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 0x133a8(%rip), %rax     # 0x43c78
movl (%rax), %eax
decl %eax
leaq 0x40(%rsp), %rbx
movl $0x0, (%rbx)
movl %eax, 0x4(%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq %rax, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
leaq 0x11fd7(%rip), %r13     # 0x428d8
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc0b4
movl %eax, %r12d
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc0b4
cmpl %r12d, %eax
je 0x30901
movl %r12d, %r13d
cmoval %eax, %r13d
cmovbl %eax, %r12d
movq %rsp, %rbp
movl %r12d, %r12d
leaq (,%r12,4), %rbx
movq (%r15), %rdx
addq %rbx, %rdx
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x3095f
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x30969
leaq 0x20(%rsp), %rdi
callq 0xc1a6
addq (%r14), %rbx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x30987
movl (%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x30992
movq %rbp, %rdi
movq %rbx, %rdx
callq 0xc1a6
incl %r12d
cmpl %r13d, %r12d
jbe 0x30933
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x309fb
movl $0x1, %ebx
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x8(%r15), %rsi
leaq (%rax,%r12,4), %rdx
callq 0xc30a
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq (%r14), %rdi
movq 0x8(%r14), %rsi
shlq $0x2, %r12
addq 0x20(%rsp), %r12
movq %r12, %rdx
callq 0xc30a
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl %ebx, %r12d
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incl %ebx
cmpq %r12, %rcx
ja 0x309ad
leaq 0x13276(%rip), %rax     # 0x43c78
cmpl $0x0, (%rax)
je 0x30a86
xorl %ebx, %ebx
leaq 0x20(%rsp), %r12
movq %rsp, %r13
xorl %ebp, %ebp
movq (%r15), %rdx
movl (%rdx,%rbx), %eax
cmpl $-0x1, %eax
je 0x30a42
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x30a37
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x30a42
addq %rbx, %rdx
movq %r13, %rdi
callq 0xc1a6
movq (%r14), %rdx
movl (%rdx,%rbx), %eax
cmpl $-0x1, %eax
je 0x30a71
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x30a66
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x30a71
addq %rbx, %rdx
movq %r12, %rdi
callq 0xc1a6
incq %rbp
leaq 0x131fd(%rip), %rax     # 0x43c78
movl (%rax), %eax
addq $0x4, %rbx
cmpq %rax, %rbp
jb 0x30a13
movq %rsp, %rbx
movq %rbx, %rdi
callq 0xf1cc
movq 0x38(%rsp), %r15
movl %eax, %ebp
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xf1cc
cmpl %eax, %ebp
cmovlq %rbx, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0xb078
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x30acd
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x30ae3
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x30aff
jmp 0x30aff
jmp 0x30aff
jmp 0x30aff
jmp 0x30aff
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x30b19
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x30b2f
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq %rbx, %rdi
callq 0x5660