// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::totalDistance(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*>>>&)
int GPX2Support::totalDistance(GPX2Structs::NodeMap& graph) 
{ // Distancia total para percorrer o grafo
    deque<string> nextToVisit;
    vector<string> isAlreadyVisited;
    int totalDistance{ 0 };
    bool notAlreadyVisited{ false };
    bool notToVisit{ false };

    Node *city = graph.begin()->second, *last = nullptr; // Reduzir chamadas (Node dentro do map)
    isAlreadyVisited.push_back(graph.begin()->first);

    nextToVisit.push_back(city->getEdges()[0].first);
    totalDistance += city->getEdges()[0].second;

    while (!nextToVisit.empty()) {
        isAlreadyVisited.push_back(nextToVisit.front());
        city = graph[nextToVisit.front()];
        nextToVisit.pop_front();

        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);
                totalDistance += n.second;
            }
        }
        last = city;
    }
    for (Node::node n : last->getEdges()) {
        if (n.first.compare(graph.begin()->first) == 0) {
            totalDistance += n.second;
        }
    }
    return totalDistance;
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x230(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x70690
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x1e3e0
movl $0x0, 0x1c4(%rsp)
movb $0x0, 0x1c3(%rsp)
movb $0x0, 0x1c2(%rsp)
movq 0x230(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x1b0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x70c00
movq 0x20(%rax), %rax
movq %rax, 0x1b8(%rsp)
movq $0x0, 0x1a8(%rsp)
movq 0x230(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x1a0(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x70c00
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x37210
jmp 0x6f724
movq 0x1b8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x58(%rsp)
jmp 0x6f738
movq 0x58(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x60c40
movq %rax, %rsi
leaq 0x1e0(%rsp), %rdi
callq 0x706a0
jmp 0x6f758
movq 0x1b8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x50(%rsp)
jmp 0x6f76c
movq 0x50(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x60c40
movsd 0x20(%rax), %xmm1
cvtsi2sdl 0x1c4(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c4(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x70700
xorb $-0x1, %al
testb $0x1, %al
jne 0x6f7af
jmp 0x6fa7e
leaq 0x1e0(%rsp), %rdi
callq 0x70970
movq %rax, %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x37210
jmp 0x6f7ce
movq 0x230(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x70970
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x60c60
movq %rax, 0x48(%rsp)
jmp 0x6f7fc
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1b8(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x709a0
movq 0x1b8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x38(%rsp)
jmp 0x6f82d
movq 0x38(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x188(%rsp), %rdi
callq 0x60f80
movq %rax, 0x180(%rsp)
movq 0x188(%rsp), %rdi
callq 0x60fb0
movq %rax, 0x178(%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x60fe0
testb $0x1, %al
jne 0x6f882
jmp 0x6fa69
leaq 0x180(%rsp), %rdi
callq 0x61020
movq %rax, %rsi
leaq 0x150(%rsp), %rdi
callq 0x61030
jmp 0x6f8a1
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x1e310
movq 0x28(%rsp), %rdi
movq %rax, 0x140(%rsp)
callq 0x1e340
movq %rax, 0x138(%rsp)
movq 0x140(%rsp), %rdi
movq 0x138(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0x49c90
movq %rax, 0x30(%rsp)
jmp 0x6f8f1
movq 0x30(%rsp), %rax
movq %rax, 0x148(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x1e340
movq %rax, 0x130(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x55c20
movb %al, 0x1c3(%rsp)
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
leaq 0x1e0(%rsp), %rsi
movq %rsi, 0x10(%rsp)
callq 0x70860
movq 0x10(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x70890
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x110(%rsp), %rdi
leaq 0x150(%rsp), %rcx
callq 0x707e0
jmp 0x6f986
leaq 0xb0(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x70890
leaq 0x110(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x707c0
andb $0x1, %al
movb %al, 0x1c2(%rsp)
testb $0x1, 0x1c3(%rsp)
je 0x6fa4a
testb $0x1, 0x1c2(%rsp)
je 0x6fa4a
leaq 0x1e0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x706a0
jmp 0x6f9e8
movsd 0x170(%rsp), %xmm1
cvtsi2sdl 0x1c4(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c4(%rsp)
jmp 0x6fa4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x6fbc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x610b0
jmp 0x6fbc9
leaq 0x150(%rsp), %rdi
callq 0x610b0
leaq 0x180(%rsp), %rdi
callq 0x610c0
jmp 0x6f864
movq 0x1b8(%rsp), %rax
movq %rax, 0x1a8(%rsp)
jmp 0x6f797
movq 0x1a8(%rsp), %rdi
callq 0x661c0
movq %rax, 0x8(%rsp)
jmp 0x6fa92
movq 0x8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x60f80
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x60fb0
movq %rax, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x60fe0
testb $0x1, %al
jne 0x6fae7
jmp 0x6fb9a
leaq 0xa0(%rsp), %rdi
callq 0x61020
movq %rax, %rsi
leaq 0x70(%rsp), %rdi
callq 0x61030
jmp 0x6fb03
movq 0x230(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x70c00
movq %rax, %rsi
leaq 0x70(%rsp), %rdi
callq 0x6060
movl %eax, 0x4(%rsp)
jmp 0x6fb32
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
jne 0x6fb7e
movsd 0x90(%rsp), %xmm1
cvtsi2sdl 0x1c4(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c4(%rsp)
jmp 0x6fb7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x610b0
jmp 0x6fbc9
leaq 0x70(%rsp), %rdi
callq 0x610b0
leaq 0xa0(%rsp), %rdi
callq 0x610c0
jmp 0x6fac9
movl 0x1c4(%rsp), %eax
movl %eax, (%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0xa2c0
leaq 0x1e0(%rsp), %rdi
callq 0x70900
movl (%rsp), %eax
addq $0x238, %rsp            # imm = 0x238
retq
leaq 0x1c8(%rsp), %rdi
callq 0xa2c0
leaq 0x1e0(%rsp), %rdi
callq 0x70900
movq 0x198(%rsp), %rdi
callq 0x6850