// File: ekg[P]sgd2/src/sgd2.hpp
// Function: sgd2::maxmin_bfs_weighted(std::vector<std::vector<sgd2::edge, std::allocator<sgd2::edge>>, std::allocator<std::vector<sgd2::edge, std::allocator<sgd2::edge>>>> const&, unsigned long, std::vector<double, std::allocator<double>>&, std::vector<unsigned long, std::allocator<unsigned long>>&)
void maxmin_bfs_weighted(const std::vector<std::vector<edge>>& graph, const uint64_t p, std::vector<double>& mins, std::vector<uint64_t>& argmins)
{
    uint64_t n = graph.size();
    std::vector<bool> visited(n, false);
    std::vector<double> d(n, std::numeric_limits<double>::max()); // init 'tentative' distances to infinity

    // I am not using a fibonacci heap. I AM NOT USING A FIBONACCI HEAP
    // edges are used 'invisibly' here
    std::priority_queue<edge, std::vector<edge>, edge_comp> pq;

    d[p] = 0;
    pq.push(edge(p,0));

    while (!pq.empty())
    {
        uint64_t current = pq.top().target;
        double d_pi = pq.top().weight;
        pq.pop();
        
        if (!visited[current]) // ignore redundant elements in queue
        {
            visited[current] = true;

            if (d_pi < mins[current])
            {
                mins[current] = d_pi;
                argmins[current] = p;
            }
            for (edge e : graph[current])
            {
                // here the edge is not 'invisible'
                uint64_t next = e.target;
                double weight = e.weight;

                if (d_pi + weight < d[next]) // update tentative value of d 
                {
                    d[next] = d_pi + weight;
                    pq.push(edge(next, d[next]));
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0xbaa0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x148(%rbp)
movb $0x0, -0x51(%rbp)
leaq -0x52(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0xa5e0
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rcx
leaq -0x50(%rbp), %rdi
leaq -0x51(%rbp), %rdx
callq 0xa600
jmp 0x6bf4
leaq -0x52(%rbp), %rdi
callq 0xa680
movq -0x28(%rbp), %rax
movq %rax, -0x158(%rbp)
callq 0xa6a0
movsd %xmm0, -0x88(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0xa6b0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rcx
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0xa6d0
jmp 0x6c48
leaq -0x89(%rbp), %rdi
callq 0xa750
leaq -0xb0(%rbp), %rdi
callq 0xa770
jmp 0x6c62
movq -0x10(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0xa7a0
movq $0x0, (%rax)
movq -0x10(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xa4c0
jmp 0x6c8b
leaq -0xb0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa7c0
jmp 0x6ca0
jmp 0x6ca2
leaq -0xb0(%rbp), %rdi
callq 0xa810
movb %al, -0x159(%rbp)
jmp 0x6cb6
movb -0x159(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6cc7
jmp 0x702b
leaq -0xb0(%rbp), %rdi
callq 0xa830
movq %rax, -0x168(%rbp)
jmp 0x6cdc
movq -0x168(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa830
movq %rax, -0x170(%rbp)
jmp 0x6d02
movq -0x170(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa850
jmp 0x6d24
movq -0xc8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xa8a0
movq %rdx, -0x180(%rbp)
movq %rax, -0x178(%rbp)
jmp 0x6d44
movq -0x180(%rbp), %rax
movq -0x178(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xa900
xorb $-0x1, %al
testb $0x1, %al
jne 0x6d77
jmp 0x7026
movq -0xc8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xa8a0
movq %rdx, -0x190(%rbp)
movq %rax, -0x188(%rbp)
jmp 0x6d97
movq -0x190(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq %rax, -0xe8(%rbp)
leaq -0xf0(%rbp), %rdi
movl $0x1, %esi
callq 0xa930
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x198(%rbp)
movq -0x18(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0xa7a0
movsd -0x198(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6eb2
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movq -0x18(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0xa7a0
movsd -0x1a8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x20(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x9ee0
movq -0x1a0(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x6eb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x52(%rbp), %rdi
callq 0xa680
jmp 0x7064
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x89(%rbp), %rdi
callq 0xa750
jmp 0x705b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x7052
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xaa60
jmp 0x7052
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0xbad0
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0xbaf0
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
callq 0xbb20
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0xbb50
testb $0x1, %al
jne 0x6f0b
jmp 0x7024
leaq -0x100(%rbp), %rdi
callq 0xbb90
movq (%rax), %rcx
movq %rcx, -0x118(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x110(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x120(%rbp)
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0xd0(%rbp), %xmm0
addsd -0x128(%rbp), %xmm0
movsd %xmm0, -0x1b0(%rbp)
movq -0x120(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0xa7a0
movsd -0x1b0(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7011
movsd -0xd0(%rbp), %xmm0
movsd -0x128(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x1c8(%rbp)
movq -0x120(%rbp), %rsi
leaq -0x80(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0xa7a0
movsd -0x1c8(%rbp), %xmm0
movq -0x1c0(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x120(%rbp), %rsi
movq %rsi, -0x1b8(%rbp)
callq 0xa7a0
movq -0x1b8(%rbp), %rsi
movsd (%rax), %xmm0
leaq -0x138(%rbp), %rdi
callq 0xa4c0
jmp 0x6ffa
leaq -0xb0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xa7c0
jmp 0x700f
jmp 0x7011
jmp 0x7013
leaq -0x100(%rbp), %rdi
callq 0xbbb0
jmp 0x6eef
jmp 0x7026
jmp 0x6ca2
leaq -0xb0(%rbp), %rdi
callq 0xaa60
leaq -0x80(%rbp), %rdi
callq 0xaa80
leaq -0x50(%rbp), %rdi
callq 0xaae0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0xaa80
leaq -0x50(%rbp), %rdi
callq 0xaae0
movq -0x60(%rbp), %rdi
callq 0x22a0
nopl (%rax)