// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::mapToTour(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Node*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, Node*>>>&)
vector<int> GPX2Support::mapToTour(GPX2Structs::NodeMap& mapOffspring)
{
    vector<int> offspring;
    deque<string> nextToVisit;
    vector<string> isAlreadyVisited;

    bool notAlreadyVisited{ false };
    bool notToVisit{ false };

    Node* city = mapOffspring.begin()->second; 

    isAlreadyVisited.push_back(mapOffspring.begin()->first);

    offspring.push_back(stoi(city->getId())); // begin the linearization by the first node of the map and inserts it in the offspring

    nextToVisit.push_back(city->getEdges()[0].first);

    while (!nextToVisit.empty()) {

        isAlreadyVisited.push_back(nextToVisit.front());
        city = mapOffspring[nextToVisit.front()];
        nextToVisit.pop_front();
        // criates a city object and inserts it in the tour
        offspring.push_back(stoi(city->getId()));

        for (Node::node n : city->getEdges()) {

            notAlreadyVisited = find(isAlreadyVisited.begin(), isAlreadyVisited.end(), n.first) == isAlreadyVisited.end();
            notToVisit = find(nextToVisit.begin(), nextToVisit.end(), n.first) == nextToVisit.end();

            if (notAlreadyVisited && notToVisit) {
                nextToVisit.push_back(n.first);
            }
        } 
    }

    return (offspring);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x8(%rsp)
andq $0x0, 0x10(%rdi)
leaq 0x60(%rsp), %rdi
callq 0x25e64
leaq 0x10(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq 0x18(%r14), %rsi
movq 0x40(%rsi), %rbx
addq $0x20, %rsi
callq 0x14efa
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x21bf4
leaq 0x38(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x6d40
leaq 0xb0(%rsp), %rsi
movl %eax, (%rsi)
movq 0x8(%rsp), %rdi
callq 0xbea4
movq %r14, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x56f8
movq %rbx, %rdi
callq 0x21c02
movq (%rax), %rsi
leaq 0x60(%rsp), %rdi
callq 0x25ce4
leaq 0x38(%rsp), %r13
leaq 0xb0(%rsp), %r15
movq 0x70(%rsp), %rsi
cmpq %rsi, 0x90(%rsp)
je 0x24892
leaq 0x10(%rsp), %rdi
callq 0x14efa
movq 0x70(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x20910
movq (%rax), %r14
leaq 0x60(%rsp), %rdi
callq 0x25dba
movq %r13, %rdi
movq %r14, %rsi
callq 0x21bf4
movq %r13, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x6d40
movl %eax, 0xb0(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xbea4
movq %r13, %rdi
callq 0x56f8
movq %r14, %rdi
callq 0x21c02
movq (%rax), %r14
movq 0x8(%rax), %rbp
cmpq %rbp, %r14
je 0x2475b
movq %r13, %rdi
movq %r14, %rsi
callq 0x209fc
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x1abd1
movq %rax, %r12
movq 0x18(%rsp), %rbx
movups 0x70(%rsp), %xmm0
movups 0x80(%rsp), %xmm1
movups 0x90(%rsp), %xmm2
movups 0xa0(%rsp), %xmm3
movaps %xmm0, 0xf0(%rsp)
movaps %xmm1, 0x100(%rsp)
movaps %xmm2, 0xd0(%rsp)
movaps %xmm3, 0xe0(%rsp)
movq %r15, %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movq %r13, %rcx
callq 0x25d2c
cmpq %rbx, %r12
jne 0x24881
movq 0x90(%rsp), %rax
cmpq %rax, 0xb0(%rsp)
jne 0x24881
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x25ce4
movq %r13, %rdi
callq 0x56f8
addq $0x28, %r14
jmp 0x247d7
leaq 0x10(%rsp), %rdi
callq 0x709c
leaq 0x60(%rsp), %rdi
callq 0x25d6e
movq 0x8(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x248d4
jmp 0x248d4
movq %rax, %rbx
jmp 0x248fc
jmp 0x248d4
jmp 0x248db
jmp 0x248d4
jmp 0x248d4
jmp 0x248db
jmp 0x248d4
jmp 0x248db
movq %rax, %rbx
jmp 0x248e8
jmp 0x248db
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x56f8
leaq 0x10(%rsp), %rdi
callq 0x709c
leaq 0x60(%rsp), %rdi
callq 0x25d6e
movq 0x8(%rsp), %rdi
callq 0x6e4c
movq %rbx, %rdi
callq 0x5610