// File: 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:
subq $0x108, %rsp            # imm = 0x108
movq %rdx, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
leaq 0x2b03b(%rip), %rax     # 0x9dda8
movl (%rax), %edx
subl $0x1, %edx
leaq 0xe8(%rsp), %rdi
xorl %esi, %esi
callq 0x10800
leaq 0xd0(%rsp), %rdi
callq 0xfdf0
leaq 0xb8(%rsp), %rdi
callq 0xfdf0
leaq 0x29c66(%rip), %rsi     # 0x9ca08
leaq 0xe8(%rsp), %rdi
callq 0x10850
movl %eax, 0x2c(%rsp)
jmp 0x72db5
movl 0x2c(%rsp), %eax
movl %eax, 0xb4(%rsp)
leaq 0x29c41(%rip), %rsi     # 0x9ca08
leaq 0xe8(%rsp), %rdi
callq 0x10850
movl %eax, 0x28(%rsp)
jmp 0x72dda
movl 0x28(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl 0xb0(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jae 0x72e54
movl 0xb0(%rsp), %eax
movl %eax, 0xa0(%rsp)
movl 0xb4(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0xb4(%rsp)
jmp 0x72e54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x9af0
leaq 0xd0(%rsp), %rdi
callq 0x9af0
jmp 0x73178
jmp 0x72e56
movl 0xb4(%rsp), %eax
cmpl 0xb0(%rsp), %eax
je 0x72d9b
movl 0xb4(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xb0(%rsp), %eax
ja 0x72ee7
movq 0x38(%rsp), %rdi
movl 0x9c(%rsp), %eax
movl %eax, %esi
callq 0x10830
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x10880
jmp 0x72ead
movq 0x30(%rsp), %rdi
movl 0x9c(%rsp), %eax
movl %eax, %esi
callq 0x10830
movq %rax, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x10880
jmp 0x72ed2
jmp 0x72ed4
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x72e78
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
movq %rax, 0x20(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x107e0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x73054
movq 0x38(%rsp), %rdi
callq 0x10130
movq 0x38(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0x10160
movq %rax, 0x80(%rsp)
movl 0x98(%rsp), %eax
movl %eax, %esi
leaq 0xd0(%rsp), %rdi
callq 0x10830
movq %rax, %rdx
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x73190
movq %rax, 0x18(%rsp)
jmp 0x72f75
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, 0x90(%rsp)
callq 0x10130
movq %rax, 0x78(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x11b00
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x10830
movq 0x30(%rsp), %rdi
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
callq 0x10130
movq 0x30(%rsp), %rdi
movq %rax, 0x68(%rsp)
callq 0x10160
movq %rax, 0x60(%rsp)
movl 0x98(%rsp), %eax
movl %eax, %esi
leaq 0xb8(%rsp), %rdi
callq 0x10830
movq %rax, %rdx
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x73190
movq %rax, 0x10(%rsp)
jmp 0x73003
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
callq 0x10130
movq %rax, 0x58(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11b00
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x10830
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x72ef2
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
leaq 0x2ad41(%rip), %rcx     # 0x9dda8
cmpl (%rcx), %eax
jae 0x730f3
movq 0x38(%rsp), %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x10830
cmpl $-0x1, (%rax)
je 0x730a8
movq 0x38(%rsp), %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x10830
movq %rax, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x10880
jmp 0x730a6
jmp 0x730a8
movq 0x30(%rsp), %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x10830
cmpl $-0x1, (%rax)
je 0x730e1
movq 0x30(%rsp), %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x10830
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x10880
jmp 0x730df
jmp 0x730e1
jmp 0x730e3
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x7305c
leaq 0xd0(%rsp), %rdi
callq 0x1b240
movl %eax, 0xc(%rsp)
jmp 0x73106
leaq 0xb8(%rsp), %rdi
callq 0x1b240
movl %eax, 0x8(%rsp)
jmp 0x73119
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
cmpl %ecx, %eax
jge 0x73133
leaq 0xd0(%rsp), %rax
movq %rax, (%rsp)
jmp 0x73141
leaq 0xb8(%rsp), %rax
movq %rax, (%rsp)
jmp 0x73141
movq 0x40(%rsp), %rdi
movq (%rsp), %rsi
callq 0xfcd0
jmp 0x73151
leaq 0xb8(%rsp), %rdi
callq 0x9af0
leaq 0xd0(%rsp), %rdi
callq 0x9af0
movq 0x48(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0xa8(%rsp), %rdi
callq 0x6850
nopw %cs:(%rax,%rax)
nop