// File: /workspace/github_cpp_makefile_star2_O3/Manca[P]algorithms2/./assignment4.hpp
// Function: assignment4::floyd_warshall(std::unordered_map<int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>>>&, int, int&)
bool floyd_warshall(Graph& graph, int n, int& shortest)
    {
        PROFILE("Initialize Floyd-Warshall")
        std::vector<std::vector<std::vector<int>>> A;       // a 3D array
        // setup sizes (we will store only kth and k-1th result)
        A.resize(2);
        for (int i = 0; i < 2; i++)
        {
            A[i].resize(n+1);
            for (int j = 0; j <= n; j++)
                A[i][j].resize(n+1);
        }
        
        for (int i = 1; i <= n; i++)             // i,j are vertices (from 1 to 1000)
            for (int j = 1; j <= n; j++)
            {
                int cost;
                if (i == j)   A[0][i][j] = 0;
                else if (ijConnected(i, j, graph, cost)) A[0][i][j] = cost;
                else if (i != j)  A[0][i][j] = INT32_MAX/2 -1;
            }

        PROFILE_STOP();

        // the algorithm
        PROFILE("Floyd-Warshall algorithm");
        for (int k = 1; k <= n; k++)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    A[1][i][j] = std::min(A[0][i][j], A[0][i][k] + A[0][k][j]);
                    A[0][i][j] = A[1][i][j];    // store currently computed value at zero position (previous - interchange)
                }

                // check for negative cycles (if current i-th iteration reveals cycle, abort!)
                if (A[1][i][i] < 0)
                {
                    std::cout << "Negative cycle!! Vertex: " << i << ". Total weight: " << A[1][i][i] << std::endl;
                    PROFILE_STOP();
                    return false;
                }
            }
           
        }
        PROFILE_STOP();

        // find the shortest shortest path
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (i == j) continue;
                if (A[1][i][j] < shortest) shortest = A[1][i][j];
            }
        }

        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r13
movl %esi, %ebx
movq %rdi, 0x50(%rsp)
callq 0x88f8
movq %rax, %r12
leaq 0x38(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8de4(%rip), %rsi      # 0xe813
leaq 0x8df6(%rip), %rdx      # 0xe82c
leaq 0x28(%rsp), %rdi
callq 0xbb78
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x8942
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x5a5c
callq 0x21f0
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x2, %esi
callq 0x9000
movq %rbx, (%rsp)
leal 0x1(%rbx), %eax
movslq %eax, %r12
movq %rax, 0x8(%rsp)
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %rbx
movb $0x1, %bpl
xorl %eax, %eax
leaq (%rax,%rax,2), %r14
leaq (,%r14,8), %rdi
addq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x907c
cmpl $0x0, (%rsp)
js 0x5ad8
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rdi
addq %r15, %rdi
movq %r12, %rsi
callq 0x90fe
addq $0x18, %r15
cmpq %r15, %rbx
jne 0x5abb
movl $0x1, %eax
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x5a99
movq %r13, 0x48(%rsp)
cmpl $0x0, (%rsp)
jle 0x5b61
movl 0x8(%rsp), %r14d
movl $0x1, %r12d
xorl %ebx, %ebx
leaq 0x28(%rsp), %r13
leaq (%r12,%r12,2), %r15
movl $0x1, %ebp
leaq (%rbx,%rbp), %rdx
xorl %ecx, %ecx
movq %r12, %rax
cmpq $0x1, %rdx
je 0x5b3f
movl %r12d, %edi
movl %ebp, %esi
movq 0x50(%rsp), %rdx
movq %r13, %rcx
callq 0x597f
movl $0x3ffffffe, %ecx       # imm = 0x3FFFFFFE
testb %al, %al
je 0x5b3c
movl 0x28(%rsp), %ecx
movq %rbp, %rax
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movq (%rdx,%r15,8), %rdx
movl %ecx, (%rdx,%rax,4)
incq %rbp
cmpq %rbp, %r14
jne 0x5b0e
incq %r12
decq %rbx
cmpq %r14, %r12
jne 0x5b05
callq 0x88f8
movq 0x48(%rsp), %r12
movq (%rsp), %rbx
movq %rax, %rdi
callq 0x898c
callq 0x88f8
movq %rax, %r15
leaq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %r14
movq %r14, (%rdi)
leaq 0x8c9a(%rip), %rsi      # 0xe82d
leaq 0x8cab(%rip), %rdx      # 0xe845
callq 0xbb78
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x8942
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x5bbb
callq 0x21f0
testl %ebx, %ebx
jle 0x5ce2
movl %ebx, %eax
movl 0x8(%rsp), %ecx
movl $0x1, %edx
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
movq (%rdi), %rsi
movq 0x18(%rdi), %rdi
leaq (%rdx,%rdx,2), %r8
movq (%rsi,%r8,8), %r8
movl $0x1, %r15d
leaq (,%r15,8), %r9
leaq (%r9,%r9,2), %r9
movq (%rsi,%r9), %r10
movq (%rdi,%r9), %r9
movl $0x1, %r11d
movl (%r8,%r11,4), %ebx
addl (%r10,%rdx,4), %ebx
movl (%r10,%r11,4), %r14d
cmpl %r14d, %ebx
cmovgel %r14d, %ebx
movl %ebx, (%r9,%r11,4)
movl %ebx, (%r10,%r11,4)
incq %r11
cmpq %r11, %rcx
jne 0x5c04
cmpl $0x0, (%r9,%r15,4)
js 0x5c4e
incq %r15
cmpq %rcx, %r15
jne 0x5bea
cmpq %rax, %rdx
leaq 0x1(%rdx), %rsi
setae %bpl
movq %rsi, %rdx
cmpq %rcx, %rsi
jne 0x5bd0
jmp 0x5ce5
movq 0xf383(%rip), %rdi      # 0x14fd8
leaq 0x8bea(%rip), %rsi      # 0xe846
movl $0x19, %edx
callq 0x2240
movq 0xf36b(%rip), %rdi      # 0x14fd8
movl %r15d, %esi
callq 0x2340
movq %rax, %rbx
leaq 0x8be1(%rip), %rsi      # 0xe860
movl $0x10, %edx
movq %rax, %rdi
callq 0x2240
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x2340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2190
callq 0x88f8
movq %rax, %rdi
callq 0x898c
jmp 0x5d4b
movb $0x1, %bpl
callq 0x88f8
movq (%rsp), %rbx
movq %rax, %rdi
callq 0x898c
testl %ebx, %ebx
jle 0x5d4b
movl (%r12), %edx
movq 0x10(%rsp), %rax
movl 0x8(%rsp), %ecx
leaq -0x1(%rcx), %rsi
movl $0x1, %edi
xorl %r8d, %r8d
leaq (%rdi,%rdi,2), %r9
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x5d38
movq 0x18(%rax), %r11
movq (%r11,%r9,8), %r11
movl 0x4(%r11,%r10,4), %r11d
cmpl %edx, %r11d
jge 0x5d38
movl %r11d, (%r12)
movl %r11d, %edx
incq %r10
cmpq %r10, %rsi
jne 0x5d1a
incq %rdi
incq %r8
cmpq %rcx, %rdi
jne 0x5d13
leaq 0x10(%rsp), %rdi
callq 0x9130
andb $0x1, %bpl
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x5da4
callq 0x21f0
jmp 0x5da4
jmp 0x5da1
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x5dae
callq 0x21f0
jmp 0x5dae
movq %rax, %rbx
jmp 0x5dae
jmp 0x5da1
jmp 0x5da1
jmp 0x5da1
jmp 0x5da1
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x9130
movq %rbx, %rdi
callq 0x2350