// File: 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:
subq $0x258, %rsp            # imm = 0x258
movq %rdi, 0x68(%rsp)
movq %rdi, %rax
movq %rax, 0x70(%rsp)
movq %rdi, 0x250(%rsp)
movq %rsi, 0x248(%rsp)
movb $0x0, 0x247(%rsp)
callq 0xfdf0
leaq 0x1f0(%rsp), %rdi
callq 0x70690
jmp 0x6da30
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x1e3e0
movb $0x0, 0x1c7(%rsp)
movb $0x0, 0x1c6(%rsp)
movq 0x248(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x1b0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x70c00
movq 0x20(%rax), %rax
movq %rax, 0x1b8(%rsp)
movq 0x248(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x1a8(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x70c00
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x37210
jmp 0x6dab1
movq 0x1b8(%rsp), %rsi
leaq 0x180(%rsp), %rdi
callq 0x66190
jmp 0x6dac8
xorl %eax, %eax
movl %eax, %esi
leaq 0x180(%rsp), %rdi
movl $0xa, %edx
callq 0x9460
movl %eax, 0x5c(%rsp)
jmp 0x6dae4
movq 0x68(%rsp), %rdi
movl 0x5c(%rsp), %eax
movl %eax, 0x1a4(%rsp)
leaq 0x1a4(%rsp), %rsi
callq 0x1a720
jmp 0x6db03
leaq 0x180(%rsp), %rdi
callq 0x6988
movq 0x1b8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x50(%rsp)
jmp 0x6db24
movq 0x50(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x60c40
movq %rax, %rsi
leaq 0x1f0(%rsp), %rdi
callq 0x706a0
jmp 0x6db44
jmp 0x6db46
leaq 0x1f0(%rsp), %rdi
callq 0x70700
xorb $-0x1, %al
testb $0x1, %al
jne 0x6db5e
jmp 0x6debb
leaq 0x1f0(%rsp), %rdi
callq 0x70970
movq %rax, %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x37210
jmp 0x6db7d
movq 0x248(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x70970
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x60c60
movq %rax, 0x48(%rsp)
jmp 0x6dbab
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1b8(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x709a0
movq 0x1b8(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0x66190
jmp 0x6dbdf
xorl %eax, %eax
movl %eax, %esi
leaq 0x158(%rsp), %rdi
movl $0xa, %edx
callq 0x9460
movl %eax, 0x3c(%rsp)
jmp 0x6dbfb
movq 0x68(%rsp), %rdi
movl 0x3c(%rsp), %eax
movl %eax, 0x17c(%rsp)
leaq 0x17c(%rsp), %rsi
callq 0x1a720
jmp 0x6dc1a
leaq 0x158(%rsp), %rdi
callq 0x6988
movq 0x1b8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x30(%rsp)
jmp 0x6dc3b
movq 0x30(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rdi
callq 0x60f80
movq %rax, 0x148(%rsp)
movq 0x150(%rsp), %rdi
callq 0x60fb0
movq %rax, 0x140(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x60fe0
testb $0x1, %al
jne 0x6dc90
jmp 0x6deb6
leaq 0x148(%rsp), %rdi
callq 0x61020
movq %rax, %rsi
leaq 0x118(%rsp), %rdi
callq 0x61030
jmp 0x6dcaf
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1e310
movq 0x20(%rsp), %rdi
movq %rax, 0x108(%rsp)
callq 0x1e340
movq %rax, 0x100(%rsp)
movq 0x108(%rsp), %rdi
movq 0x100(%rsp), %rsi
leaq 0x118(%rsp), %rdx
callq 0x49c90
movq %rax, 0x28(%rsp)
jmp 0x6dcff
movq 0x28(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x1e340
movq %rax, 0xf8(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x55c20
movb %al, 0x1c7(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x1f0(%rsp), %rsi
movq %rsi, 0x8(%rsp)
callq 0x70860
movq 0x8(%rsp), %rsi
leaq 0x98(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x70890
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
leaq 0x118(%rsp), %rcx
callq 0x707e0
jmp 0x6dd94
leaq 0x78(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x70890
leaq 0xd8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x707c0
andb $0x1, %al
movb %al, 0x1c6(%rsp)
testb $0x1, 0x1c7(%rsp)
je 0x6de97
testb $0x1, 0x1c6(%rsp)
je 0x6de97
leaq 0x1f0(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x706a0
jmp 0x6ddf4
jmp 0x6de97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x6df1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x6dee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x6988
jmp 0x6dee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x6988
jmp 0x6dee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x610b0
jmp 0x6dee9
leaq 0x118(%rsp), %rdi
callq 0x610b0
leaq 0x148(%rsp), %rdi
callq 0x610c0
jmp 0x6dc72
jmp 0x6db46
movb $0x1, 0x247(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0xa2c0
leaq 0x1f0(%rsp), %rdi
callq 0x70900
testb $0x1, 0x247(%rsp)
jne 0x6df0f
jmp 0x6df05
leaq 0x1c8(%rsp), %rdi
callq 0xa2c0
leaq 0x1f0(%rsp), %rdi
callq 0x70900
jmp 0x6df1c
movq 0x68(%rsp), %rdi
callq 0x9af0
movq 0x70(%rsp), %rax
addq $0x258, %rsp            # imm = 0x258
retq
movq 0x68(%rsp), %rdi
callq 0x9af0
movq 0x1e8(%rsp), %rdi
callq 0x6850
nopw %cs:(%rax,%rax)