// File: Manca[P]algorithms1/./assignment4.hpp
// Function: assignment4::constructNewGraph(std::map<int, std::vector<int, std::allocator<int>>, std::less<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>>>>&, std::vector<int, std::allocator<int>> const&)
Graph constructNewGraph(Graph& originalGraph, const timesList& fTimes)
    {
        Graph newGraph;
        
        // First fTimes should have exactly n+1 elements of the originalGraph
        // assuming vertex labels start from 1 to n.
        assert(fTimes.size() == originalGraph.size()+1);
        
        for (size_t i = 1; i < fTimes.size(); i++)
        {
            // if the vertex in original graph doesn't have outgoing edges
            if (originalGraph[i].size() == 0)
            {
                // just construct it with updated key in a new graph
                newGraph[fTimes[i]] = std::vector<int>();
                continue;
            }
            
            for (int neighbor : originalGraph[i])
            {
                
                // neighbors of i-th vertex of original graph are
                // vertices with new names taken from the finishing times list
                newGraph[fTimes[i]].push_back(fTimes[neighbor]);
            }
        }
        
        return newGraph;
    }

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x38(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movb $0x0, 0xaf(%rsp)
callq 0x8760
movq 0xb0(%rsp), %rdi
callq 0x7f90
movq %rax, 0x40(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x8690
movq %rax, %rcx
movq 0x40(%rsp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x32db
jmp 0x32fa
leaq 0x16d7b(%rip), %rdi     # 0x1a05d
leaq 0x16d3e(%rip), %rsi     # 0x1a027
movl $0x72, %edx
leaq 0x16d90(%rip), %rcx     # 0x1a085
callq 0x2140
movq $0x1, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x7f90
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x34f4
movq 0xb8(%rsp), %rdi
movl 0xa0(%rsp), %eax
movl %eax, 0x9c(%rsp)
leaq 0x9c(%rsp), %rsi
callq 0x8770
movq %rax, 0x20(%rsp)
jmp 0x335b
movq 0x20(%rsp), %rdi
callq 0x7f90
cmpq $0x0, %rax
jne 0x3410
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x7f80
movq 0xb0(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x7fb0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x8530
movq %rax, 0x18(%rsp)
jmp 0x33b6
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x8720
leaq 0x70(%rsp), %rdi
callq 0x8300
jmp 0x34db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x351d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x8300
jmp 0x351d
movq 0xb8(%rsp), %rdi
movl 0xa0(%rsp), %eax
movl %eax, 0x64(%rsp)
leaq 0x64(%rsp), %rsi
callq 0x8770
movq %rax, 0x10(%rsp)
jmp 0x3434
movq 0x10(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x8360
movq %rax, 0x58(%rsp)
movq 0x68(%rsp), %rdi
callq 0x8480
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8620
testb $0x1, %al
jne 0x3471
jmp 0x34d9
leaq 0x58(%rsp), %rdi
callq 0x8660
movl (%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x7fb0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x8530
movq %rax, 0x8(%rsp)
jmp 0x34aa
movq 0xb0(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0x7fb0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x7fd0
jmp 0x34cb
jmp 0x34cd
leaq 0x58(%rsp), %rdi
callq 0x8670
jmp 0x345c
jmp 0x34db
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x3306
movb $0x1, 0xaf(%rsp)
testb $0x1, 0xaf(%rsp)
jne 0x3510
movq 0x30(%rsp), %rdi
callq 0x8860
movq 0x38(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x8860
movq 0x90(%rsp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)