// File: /workspace/github_cpp_makefile_star2_O3/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
xorl %ebx, %ebx
movq %rbx, 0x10(%rdi)
xorps %xmm0, %xmm0
movq %rdi, 0x10(%rsp)
movups %xmm0, (%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 0x2fae6
leaq 0x40(%rsp), %rdi
movq %rbx, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq %r14, 0x58(%rsp)
movq 0x18(%r14), %rsi
movq 0x40(%rsi), %r12
addq $0x20, %rsi
callq 0x1aa0a
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x29f56
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 0x5500
cmpq %r14, (%r15)
je 0x2db52
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2db5e
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x22, %ecx
je 0x2db5e
testl %ecx, %ecx
jne 0x2d8a8
movq 0x8(%rsp), %rcx
movl %ebx, (%rcx)
movl %eax, 0x60(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x2d8c7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x2d8d1
leaq 0x60(%rsp), %rdx
callq 0xf0f0
leaq 0x28(%rsp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x2d8ec
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53b0
movq %r12, %rdi
callq 0x29f78
movq (%rax), %rsi
leaq 0x80(%rsp), %rdi
callq 0x2f9ea
movq 0x90(%rsp), %rsi
cmpq %rsi, 0xb0(%rsp)
je 0x2db0c
leaq 0x18(%rsp), %rbp
leaq 0x40(%rsp), %rdi
callq 0x1aa0a
movq 0x90(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x28dba
movq (%rax), %r14
leaq 0x80(%rsp), %rdi
callq 0x2faa2
movq %rbp, %rdi
movq %r14, %rsi
callq 0x29f56
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rax
movl (%rax), %r15d
movl $0x0, (%rax)
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
movl $0xa, %edx
callq 0x5500
cmpq %r13, 0xd0(%rsp)
je 0x2db46
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x2db3a
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x22, %ecx
je 0x2db3a
testl %ecx, %ecx
jne 0x2d9c2
movq 0x8(%rsp), %rcx
movl %r15d, (%rcx)
movl %eax, 0x60(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x2d9e1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x2d9eb
leaq 0x60(%rsp), %rdx
callq 0xf0f0
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2da02
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53b0
movq %r14, %rdi
callq 0x29f78
movq (%rax), %r13
movq 0x8(%rax), %r15
cmpq %r15, %r13
je 0x2daf6
movq %rbx, 0x18(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x82fa
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbp, %rdx
callq 0x219d3
movq %rax, %r14
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 0x300dc
cmpq %r12, %r14
jne 0x2dad6
movq 0xb0(%rsp), %rax
cmpq %rax, 0xf8(%rsp)
jne 0x2dad6
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0x2f9ea
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2daed
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53b0
addq $0x28, %r13
jmp 0x2da11
movq 0x90(%rsp), %rsi
cmpq %rsi, 0xb0(%rsp)
jne 0x2d91f
leaq 0x40(%rsp), %rdi
callq 0x8206
leaq 0x80(%rsp), %rdi
callq 0x2fa58
movq 0x10(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3740(%rip), %rdi      # 0x31281
callq 0x5540
leaq 0x3734(%rip), %rdi      # 0x31281
callq 0x5240
leaq 0x3728(%rip), %rdi      # 0x31281
callq 0x5240
leaq 0x371c(%rip), %rdi      # 0x31281
callq 0x5540
movq %rax, %r14
jmp 0x2db89
jmp 0x2dbba
jmp 0x2dbba
jmp 0x2dbba
movq %rax, %r14
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2db89
movq 0x8(%rsp), %rax
movl %ebx, (%rax)
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x2dbce
jmp 0x2dbdb
jmp 0x2dbc1
jmp 0x2dbba
jmp 0x2dbba
jmp 0x2dbba
movq %rax, %r14
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2dbc4
movq 0x8(%rsp), %rax
movl %r15d, (%rax)
jmp 0x2dbc4
jmp 0x2dbc1
movq %rax, %r14
jmp 0x2dbdb
jmp 0x2dbc1
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2dbdb
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53b0
leaq 0x40(%rsp), %rdi
callq 0x8206
leaq 0x80(%rsp), %rdi
callq 0x2fa58
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2dc0b
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x53b0
movq %r14, %rdi
callq 0x5660