// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::tourToMap[abi:cxx11](std::vector<int, std::allocator<int>>&)
GPX2Structs::NodeMap GPX2Support::tourToMap(vector<int> &t)
{
    //Maps the tour to a graph with connections between the nodes
    std::map<string, Node*> aux; 
    double dist = 0;
    vector<int> cities{ t };
    unsigned size = t.size();

    for (unsigned i = 0; i < size; i++) {
        Node* cn = new Node(to_string(cities[i]));
        if(i==0){
            //if the current node is the first one, connect it with the last one and the next
            //Node::node is a pair of string and double, the ID and distance
            dist = distance(cities[size-1],cities[i]);
            cn->getEdges().push_back(Node::node(to_string(cities[size-1]), dist));
            dist = distance(cities[i],cities[i+1]);
            cn->getEdges().push_back(Node::node(to_string(cities[i+1]), dist));
        }else if(i==(size-1)){
            //if the current node is the last one, connect it with the previous and the first node
            dist = distance(cities[i-1],cities[i]);
            cn->getEdges().push_back(Node::node(to_string(cities[i-1]), dist));
            dist = distance(cities[i],cities[0]);
            cn->getEdges().push_back(Node::node(to_string(cities[0]), dist));
        }else{
            //for all the other nodes connect if with the previous and next
            dist = distance(cities[i-1],cities[i]);
            cn->getEdges().push_back(Node::node(to_string(cities[i-1]), dist));
            dist = distance(cities[i],cities[i+1]);
            cn->getEdges().push_back(Node::node(to_string(cities[i+1]), dist));
        }

        aux.insert(make_pair(cn->getId(), cn));
    }

    return (aux); //returns a map with the nodes already instantiated and added 
}

// Assembly:
subq $0x348, %rsp            # imm = 0x348
movq %rdi, 0xb0(%rsp)
movq %rdi, %rax
movq %rax, 0xb8(%rsp)
movq %rdi, 0x340(%rsp)
movq %rsi, 0x338(%rsp)
movb $0x0, 0x337(%rsp)
callq 0x61750
movq $0x0, 0x328(%rsp)
movq 0x338(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0xfcd0
jmp 0x6fc4a
movq 0x338(%rsp), %rdi
callq 0x107e0
movl %eax, 0x300(%rsp)
movl $0x0, 0x2fc(%rsp)
movl 0x2fc(%rsp), %eax
cmpl 0x300(%rsp), %eax
jae 0x705c2
movl $0x40, %edi
callq 0x64b0
movq %rax, 0xa8(%rsp)
jmp 0x6fc91
movb $0x1, 0x2cf(%rsp)
movl 0x2fc(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x2d0(%rsp), %rdi
callq 0x70ce0
jmp 0x6fcc0
movq 0xa8(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x66160
jmp 0x6fcd7
movb $0x0, 0x2cf(%rsp)
leaq 0x2d0(%rsp), %rdi
callq 0x6988
movq 0xa8(%rsp), %rax
movq %rax, 0x2f0(%rsp)
cmpl $0x0, 0x2fc(%rsp)
jne 0x7001b
movl 0x300(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x10830
movq 0x98(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
movl 0x2fc(%rsp), %eax
movl %eax, %esi
callq 0x10830
movl 0xa0(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0xa4(%rsp)
jmp 0x6fd60
movl 0xa4(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x90(%rsp)
jmp 0x6fd8b
movl 0x300(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x280(%rsp), %rdi
callq 0x70ce0
jmp 0x6fdb4
leaq 0x2a0(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x6fdd3
movq 0x90(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
callq 0x70e20
jmp 0x6fdea
leaq 0x2a0(%rsp), %rdi
callq 0x610b0
leaq 0x280(%rsp), %rdi
callq 0x6988
movl 0x2fc(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x10830
movq 0x80(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x88(%rsp)
movl 0x2fc(%rsp), %eax
incl %eax
movl %eax, %esi
callq 0x10830
movl 0x88(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0x8c(%rsp)
jmp 0x6fe5a
movl 0x8c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x78(%rsp)
jmp 0x6fe82
movl 0x2fc(%rsp), %eax
incl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x238(%rsp), %rdi
callq 0x70ce0
jmp 0x6feab
leaq 0x258(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x6feca
movq 0x78(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x70e20
jmp 0x6fede
leaq 0x258(%rsp), %rdi
callq 0x610b0
leaq 0x238(%rsp), %rdi
callq 0x6988
jmp 0x704de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x7060f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x705e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x6ff66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x2d0(%rsp), %rdi
callq 0x6988
testb $0x1, 0x2cf(%rsp)
jne 0x6ff72
jmp 0x6ff84
movq 0xa8(%rsp), %rdi
movl $0x40, %esi
callq 0x64c0
jmp 0x705e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x6ffc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x2a0(%rsp), %rdi
callq 0x610b0
leaq 0x280(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x70009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x610b0
leaq 0x238(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movl 0x2fc(%rsp), %eax
movl 0x300(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x70281
movl 0x2fc(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x10830
movq 0x68(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x70(%rsp)
movl 0x2fc(%rsp), %eax
movl %eax, %esi
callq 0x10830
movl 0x70(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0x74(%rsp)
jmp 0x7007b
movl 0x74(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x60(%rsp)
jmp 0x700a0
movl 0x2fc(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x1f0(%rsp), %rdi
callq 0x70ce0
jmp 0x700c9
leaq 0x210(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x700e8
movq 0x60(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x70e20
jmp 0x700fc
leaq 0x210(%rsp), %rdi
callq 0x610b0
leaq 0x1f0(%rsp), %rdi
callq 0x6988
movl 0x2fc(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x10830
movq 0x50(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x58(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x10830
movl 0x58(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0x5c(%rsp)
jmp 0x70156
movl 0x5c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x48(%rsp)
jmp 0x7017b
xorl %eax, %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x1a8(%rsp), %rdi
callq 0x70ce0
jmp 0x7019d
leaq 0x1c8(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x701bc
movq 0x48(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x70e20
jmp 0x701d0
leaq 0x1c8(%rsp), %rdi
callq 0x610b0
leaq 0x1a8(%rsp), %rdi
callq 0x6988
jmp 0x704dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x70226
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x610b0
leaq 0x1f0(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x7026f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x610b0
leaq 0x1a8(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movl 0x2fc(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x10830
movq 0x38(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x40(%rsp)
movl 0x2fc(%rsp), %eax
movl %eax, %esi
callq 0x10830
movl 0x40(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0x44(%rsp)
jmp 0x702c8
movl 0x44(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x30(%rsp)
jmp 0x702ed
movl 0x2fc(%rsp), %eax
decl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x160(%rsp), %rdi
callq 0x70ce0
jmp 0x70316
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x70335
movq 0x30(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x70e20
jmp 0x70349
leaq 0x180(%rsp), %rdi
callq 0x610b0
leaq 0x160(%rsp), %rdi
callq 0x6988
movl 0x2fc(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x10830
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x28(%rsp)
movl 0x2fc(%rsp), %eax
incl %eax
movl %eax, %esi
callq 0x10830
movl 0x28(%rsp), %edi
movl (%rax), %esi
callq 0x1b2d0
movl %eax, 0x2c(%rsp)
jmp 0x703aa
movl 0x2c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x328(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x661c0
movq %rax, 0x18(%rsp)
jmp 0x703cf
movl 0x2fc(%rsp), %eax
incl %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x10830
movl (%rax), %esi
leaq 0x118(%rsp), %rdi
callq 0x70ce0
jmp 0x703f8
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x328(%rsp), %rdx
callq 0x70b80
jmp 0x70417
movq 0x18(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x70e20
jmp 0x7042b
leaq 0x138(%rsp), %rdi
callq 0x610b0
leaq 0x118(%rsp), %rdi
callq 0x6988
jmp 0x704dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x70481
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x610b0
leaq 0x160(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x704ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x610b0
leaq 0x118(%rsp), %rdi
callq 0x6988
jmp 0x705e3
jmp 0x704de
movq 0x2f0(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x66190
jmp 0x704f5
leaq 0xf0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x2f0(%rsp), %rdx
callq 0x70bc0
jmp 0x70514
movq 0xb0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x60df0
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x70534
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movq %rcx, 0xc0(%rsp)
movb %al, 0xc8(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x60e80
leaq 0xd0(%rsp), %rdi
callq 0x6988
movl 0x2fc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2fc(%rsp)
jmp 0x6fc69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
jmp 0x705b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x308(%rsp)
movl %eax, 0x304(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x60e80
leaq 0xd0(%rsp), %rdi
callq 0x6988
jmp 0x705e3
movb $0x1, 0x337(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x9af0
testb $0x1, 0x337(%rsp)
jne 0x705ff
jmp 0x705f2
leaq 0x310(%rsp), %rdi
callq 0x9af0
jmp 0x7060f
movq 0xb0(%rsp), %rdi
callq 0x60b90
movq 0xb8(%rsp), %rax
addq $0x348, %rsp            # imm = 0x348
retq
movq 0xb0(%rsp), %rdi
callq 0x60b90
movq 0x308(%rsp), %rdi
callq 0x6850
nopl (%rax)