// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x10(%rsp)
movq $0x0, 0x10(%rdi)
leaq 0x80(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x2f88c
leaq 0x40(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x18(%r13), %rsi
movq 0x40(%rsi), %r12
addq $0x20, %rsi
callq 0x1a992
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x29d42
movq 0x18(%rsp), %r14
callq 0x5060
movl (%rax), %ebx
movq %rax, 0x8(%rsp)
movl $0x0, (%rax)
leaq 0xd0(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x5510
cmpq %r14, (%r15)
je 0x2d910
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2d91c
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x22, %ecx
je 0x2d91c
testl %ecx, %ecx
jne 0x2d65e
movq 0x8(%rsp), %rcx
movl %ebx, (%rcx)
movl %eax, 0x60(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x2d67d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x2d687
leaq 0x60(%rsp), %rdx
callq 0xf0e2
leaq 0x28(%rsp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x2d6a2
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53c0
movq %r12, %rdi
callq 0x29d64
movq (%rax), %rsi
leaq 0x80(%rsp), %rdi
callq 0x2f798
movq 0x90(%rsp), %rsi
cmpq %rsi, 0xb0(%rsp)
je 0x2d8ca
leaq 0x18(%rsp), %rbp
movq %r13, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1a992
movq 0x90(%rsp), %rsi
movq %r13, %rdi
callq 0x28bca
movq (%rax), %r15
leaq 0x80(%rsp), %rdi
callq 0x2f850
movq %rbp, %rdi
movq %r15, %rsi
callq 0x29d42
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rax
movl (%rax), %r14d
movl $0x0, (%rax)
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
movl $0xa, %edx
callq 0x5510
cmpq %r13, 0xd0(%rsp)
je 0x2d904
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x2d8f8
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x22, %ecx
je 0x2d8f8
testl %ecx, %ecx
jne 0x2d77b
movq 0x8(%rsp), %rcx
movl %r14d, (%rcx)
movl %eax, 0x60(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x2d79a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x2d7a4
leaq 0x60(%rsp), %rdx
callq 0xf0e2
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d7bb
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53c0
movq %r15, %rdi
callq 0x29d64
movq (%rax), %r13
movq 0x8(%rax), %r14
cmpq %r14, %r13
je 0x2d8af
movq %rbx, 0x18(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x82cc
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbp, %rdx
callq 0x218f9
movq %rax, %r15
movq 0x48(%rsp), %r12
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movaps 0xb0(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm3
movaps %xmm0, 0xd0(%rsp)
movaps %xmm1, 0xe0(%rsp)
movaps %xmm2, 0x60(%rsp)
movaps %xmm3, 0x70(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq %rbp, %rcx
callq 0x2fe74
cmpq %r12, %r15
jne 0x2d88f
movq 0xb0(%rsp), %rax
cmpq %rax, 0xf8(%rsp)
jne 0x2d88f
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0x2f798
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d8a6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53c0
addq $0x28, %r13
jmp 0x2d7ca
movq 0x90(%rsp), %rsi
cmpq %rsi, 0xb0(%rsp)
movq 0x58(%rsp), %r13
jne 0x2d6da
leaq 0x40(%rsp), %rdi
callq 0x81e0
leaq 0x80(%rsp), %rdi
callq 0x2f806
movq 0x10(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3982(%rip), %rdi      # 0x31281
callq 0x5550
leaq 0x3976(%rip), %rdi      # 0x31281
callq 0x5240
leaq 0x396a(%rip), %rdi      # 0x31281
callq 0x5240
leaq 0x395e(%rip), %rdi      # 0x31281
callq 0x5550
movq %rax, %r15
jmp 0x2d94c
jmp 0x2d97d
jmp 0x2d97d
movq %rax, %r15
jmp 0x2d9b5
jmp 0x2d97d
movq %rax, %r15
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2d94c
movq 0x8(%rsp), %rax
movl %ebx, (%rax)
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x2d991
jmp 0x2d99e
jmp 0x2d984
jmp 0x2d97d
jmp 0x2d97d
jmp 0x2d97d
movq %rax, %r15
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2d987
movq 0x8(%rsp), %rax
movl %r14d, (%rax)
jmp 0x2d987
jmp 0x2d984
movq %rax, %r15
jmp 0x2d99e
jmp 0x2d984
movq %rax, %r15
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2d99e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53c0
leaq 0x40(%rsp), %rdi
callq 0x81e0
leaq 0x80(%rsp), %rdi
callq 0x2f806
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2d9ce
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r15, %rdi
callq 0x5670