// File: /workspace/github_cpp_makefile_star2_O1/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 0x13640(%rip), %rax     # 0x43c88
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 0x1226f(%rip), %r13     # 0x428e8
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc08c
movl %eax, %r12d
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc08c
cmpl %r12d, %eax
je 0x30679
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 0x306d7
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x306e1
leaq 0x20(%rsp), %rdi
callq 0xc17e
addq (%r14), %rbx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x306ff
movl (%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x3070a
movq %rbp, %rdi
movq %rbx, %rdx
callq 0xc17e
incl %r12d
cmpl %r13d, %r12d
jbe 0x306ab
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x30773
movl $0x1, %ebx
xorl %r12d, %r12d
movq (%r15), %rdi
movq 0x8(%r15), %rsi
leaq (%rax,%r12,4), %rdx
callq 0xc2e2
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq (%r14), %rdi
movq 0x8(%r14), %rsi
shlq $0x2, %r12
addq 0x20(%rsp), %r12
movq %r12, %rdx
callq 0xc2e2
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 0x30725
leaq 0x1350e(%rip), %rax     # 0x43c88
cmpl $0x0, (%rax)
je 0x307fe
xorl %ebx, %ebx
leaq 0x20(%rsp), %r12
movq %rsp, %r13
xorl %ebp, %ebp
movq (%r15), %rdx
movl (%rdx,%rbx), %eax
cmpl $-0x1, %eax
je 0x307ba
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x307af
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x307ba
addq %rbx, %rdx
movq %r13, %rdi
callq 0xc17e
movq (%r14), %rdx
movl (%rdx,%rbx), %eax
cmpl $-0x1, %eax
je 0x307e9
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x307de
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x307e9
addq %rbx, %rdx
movq %r12, %rdi
callq 0xc17e
incq %rbp
leaq 0x13495(%rip), %rax     # 0x43c88
movl (%rax), %eax
addq $0x4, %rbx
cmpq %rax, %rbp
jb 0x3078b
movq %rsp, %rbx
movq %rbx, %rdi
callq 0xf1c0
movq 0x38(%rsp), %r15
movl %eax, %ebp
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xf1c0
cmpl %eax, %ebp
cmovlq %rbx, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0xb05c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x30845
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3085b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x30877
jmp 0x30877
jmp 0x30877
jmp 0x30877
jmp 0x30877
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x30891
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x308a7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %rbx, %rdi
callq 0x5670