// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]sgd2/src/sgd2.hpp
// Function: sgd2::MSSP_unweighted(std::vector<std::vector<unsigned long, std::allocator<unsigned long>>, std::allocator<std::vector<unsigned long, std::allocator<unsigned long>>>> const&, std::vector<unsigned long, std::allocator<unsigned long>> const&)
std::vector<term_sparse> MSSP_unweighted(const std::vector<std::vector<uint64_t>>& graph, const std::vector<uint64_t>& closest_pivots)
{
    uint64_t n = graph.size();

    // get pivots and their regions, but in sets
    std::unordered_map<uint64_t, std::unordered_set<uint64_t>> regions;
    for (uint64_t i = 0; i < n; i++)
    {
        if (regions.find(closest_pivots[i]) == regions.end())
        {
            regions[closest_pivots[i]] = std::unordered_set<uint64_t>();
        }
        regions[closest_pivots[i]].insert(i);
    }

    std::unordered_map<uint64_t, std::unordered_map<uint64_t, term_sparse>> termsDict;
    for (const auto& region : regions)
    {
        // q contains next to visit
        std::queue<uint64_t> q;
        std::vector<uint64_t> d(n, -1);

        uint64_t p = region.first;
        q.push(p);
        d[p] = 0;

        // q2 contains visited vertices' distances for s calculation
        std::queue<uint64_t> q2;
        uint64_t s = 0;
        q2.push(0);

        while (!q.empty())
        {
            uint64_t current = q.front();
            q.pop();

            for (uint64_t next : graph[current])
            {
                if (d[next] == -1)
                {
                    q.push(next);
                    d[next] = d[current] + 1;

                    // empty the second queue enough to calculate s
                    while (!q2.empty() && q2.front() <= d[next]/2)
                    {
                        q2.pop();
                        s += 1;
                    }
                    if (region.second.find(next) != region.second.end())
                    {
                        q2.push(d[next]);
                    }

                    uint64_t i = next;
                    if (i < p)
                    {
                        if (termsDict.find(i) == termsDict.end())
                            termsDict[i] = std::unordered_map<uint64_t, term_sparse>();
                        if (termsDict[i].find(p) == termsDict[i].end())
                            termsDict[i].insert({ p, term_sparse(i, p, d[next]) });

                        termsDict[i].at(p).w_ij = s / ((double)d[next] * d[next]);
                    }
                    else
                    {
                        if (termsDict.find(p) == termsDict.end())
                            termsDict[p] = std::unordered_map<uint64_t, term_sparse>();
                        if (termsDict[p].find(i) == termsDict[p].end())
                            termsDict[p].insert({ i, term_sparse(p, i, d[next]) });

                        termsDict[p].at(i).w_ji = s / ((double)d[next] * d[next]);
                    }
                }
            }
        }
    }
    // 1-stress
    for (uint64_t i=0; i<n; i++)
    {
        for (uint64_t j : graph[i])
        {
            if (i < j)
            {
                if (termsDict.find(i) == termsDict.end())
                    termsDict[i] = std::unordered_map<uint64_t, term_sparse>();
                if (termsDict[i].find(j) == termsDict[i].end())
                    termsDict[i].insert({ j, term_sparse(i, j, 1) });
                else
                    termsDict[i].at(j).d = 1;

                termsDict[i].at(j).w_ij = termsDict[i].at(j).w_ji = 1;
            }
        }
    }
    std::vector<term_sparse> terms;
    for (const auto& i : termsDict)
    {
        for (const auto& j : i.second)
        {
            terms.push_back(j.second);
        }
    }
    return terms;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdx, %rbx
movq %rdi, -0x118(%rbp)
movq 0x8(%rsi), %rax
movq %rsi, -0xa8(%rbp)
subq (%rsi), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, -0x80(%rbp)
leaq -0x1d8(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
xorl %esi, %esi
leaq -0x208(%rbp), %r14
leaq -0xf8(%rbp), %r15
leaq -0x1d0(%rbp), %r12
movq %rsi, -0x1d0(%rbp)
cmpq -0x80(%rbp), %rsi
jae 0x3c79
shlq $0x3, %rsi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0x8fbe
testq %rax, %rax
jne 0x3c49
andq $0x0, -0xd8(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x1, -0xf0(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0xd8(%rbp) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq -0x1d0(%rbp), %rsi
shlq $0x3, %rsi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0x9048
movq %rax, %rdi
movq %r15, %rsi
callq 0x678e
movq %r15, %rdi
callq 0x68ba
movq -0x1d0(%rbp), %rsi
shlq $0x3, %rsi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0x9048
movq %rax, %rdi
movq %r12, %rsi
callq 0x72ea
movq -0x1d0(%rbp), %rsi
incq %rsi
jmp 0x3bc2
leaq -0x138(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
leaq -0x158(%rbp), %rax
movq %rax, -0xa0(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movl $0x3f800000, 0x10(%rax) # imm = 0x3F800000
movupd %xmm0, 0x18(%rax)
movq -0x1f8(%rbp), %rbx
leaq -0x1d0(%rbp), %r13
leaq -0x168(%rbp), %r14
testq %rbx, %rbx
je 0x41a4
leaq -0xf8(%rbp), %rdi
callq 0x5fa8
orq $-0x1, -0x1d0(%rbp)
leaq -0x98(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq %r13, %rdx
leaq -0x78(%rbp), %rcx
callq 0x5f48
movq 0x8(%rbx), %rax
movq %rax, -0x30(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x7ad8
movq -0x30(%rbp), %rax
movq -0x98(%rbp), %rcx
andq $0x0, (%rcx,%rax,8)
movq %r13, %rdi
callq 0x5fa8
andq $0x0, -0x78(%rbp)
movq %r13, %rdi
leaq -0x78(%rbp), %rsi
callq 0x9398
movq %rbx, -0x120(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x128(%rbp)
xorl %ebx, %ebx
movq -0xe8(%rbp), %rax
cmpq %rax, -0xc8(%rbp)
je 0x4175
movq (%rax), %r15
leaq -0xf8(%rbp), %rdi
callq 0x7d34
movq -0xa8(%rbp), %rax
movq (%rax), %rax
movq %r15, -0x130(%rbp)
imulq $0x18, %r15, %rcx
movq (%rax,%rcx), %r15
movq 0x8(%rax,%rcx), %r12
cmpq %r12, %r15
je 0x3d4c
movq (%r15), %rax
movq %rax, -0x40(%rbp)
movq -0x98(%rbp), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x416c
leaq -0xf8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7ad8
movq -0x98(%rbp), %rax
movq -0x130(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
incq %rcx
movq -0x40(%rbp), %rdx
movq %rcx, (%rax,%rdx,8)
movq -0x1c0(%rbp), %rax
cmpq %rax, -0x1a0(%rbp)
je 0x3e0c
movq -0x40(%rbp), %rcx
movq -0x98(%rbp), %rdx
movq (%rdx,%rcx,8), %rcx
shrq %rcx
cmpq %rcx, (%rax)
ja 0x3e0c
movq %r13, %rdi
callq 0x7d34
incq %rbx
jmp 0x3dd8
movq -0x128(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x9466
testq %rax, %rax
je 0x3e38
movq -0x40(%rbp), %rsi
shlq $0x3, %rsi
addq -0x98(%rbp), %rsi
movq %r13, %rdi
callq 0x7ad8
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rbx, %xmm0
movdqa %xmm0, -0x180(%rbp)
cmpq -0x30(%rbp), %rax
jae 0x3fe4
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9488
testq %rax, %rax
jne 0x3ebc
andq $0x0, -0x58(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x1, -0x70(%rbp)
pxor %xmm0, %xmm0
movdqu %xmm0, -0x20(%rax)
movl $0x3f800000, -0x58(%rbp) # imm = 0x3F800000
movdqu %xmm0, -0x8(%rax)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %r14
movq %r14, %rsi
callq 0x691e
movq %r14, %rdi
leaq -0x168(%rbp), %r14
callq 0x6a4a
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9862
movq %rax, %r14
leaq -0x168(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x9512
testq %r14, %r14
leaq -0x168(%rbp), %r14
jne 0x3f5c
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9512
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rsi
movq -0x98(%rbp), %rdi
movsd (%rdi,%rsi,8), %xmm0
unpcklps 0x7142(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x714a(%rip), %xmm0     # 0xb070
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
leaq -0x48(%rbp), %rsi
movupd %xmm0, -0x10(%rsi)
movq %rdx, -0x78(%rbp)
movq %rcx, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x98ec
movq -0x40(%rbp), %rax
movq -0x98(%rbp), %rcx
movq (%rcx,%rax,8), %xmm0
movdqa %xmm0, -0x110(%rbp)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9c1c
movsd 0x70cc(%rip), %xmm1     # 0xb060
movapd -0x180(%rbp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x70c9(%rip), %xmm2     # 0xb070
subpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
addsd %xmm3, %xmm0
movapd -0x110(%rbp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
jmp 0x416c
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9488
testq %rax, %rax
jne 0x4049
andq $0x0, -0x58(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x1, -0x70(%rbp)
pxor %xmm0, %xmm0
movdqu %xmm0, -0x20(%rax)
movl $0x3f800000, -0x58(%rbp) # imm = 0x3F800000
movdqu %xmm0, -0x8(%rax)
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %r14
movq %r14, %rsi
callq 0x691e
movq %r14, %rdi
leaq -0x168(%rbp), %r14
callq 0x6a4a
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9862
movq %rax, %r14
leaq -0x168(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x9512
testq %r14, %r14
leaq -0x168(%rbp), %r14
jne 0x40e9
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9512
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
movq -0x98(%rbp), %rdi
movsd (%rdi,%rsi,8), %xmm0
unpcklps 0x6fb5(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x6fbd(%rip), %xmm0     # 0xb070
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
leaq -0x48(%rbp), %rsi
movupd %xmm0, -0x10(%rsi)
movq %rdx, -0x78(%rbp)
movq %rcx, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x98ec
movq -0x40(%rbp), %rax
movq -0x98(%rbp), %rcx
movq (%rcx,%rax,8), %xmm0
movdqa %xmm0, -0x110(%rbp)
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9c1c
movsd 0x6f3f(%rip), %xmm1     # 0xb060
movapd -0x180(%rbp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x6f3c(%rip), %xmm2     # 0xb070
subpd %xmm2, %xmm3
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
addsd %xmm3, %xmm0
movapd -0x110(%rbp), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
addsd %xmm3, %xmm1
mulsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
addq $0x8, %r15
jmp 0x3d8d
movq %r13, %rdi
callq 0x66ee
leaq -0x98(%rbp), %rdi
callq 0x7894
leaq -0xf8(%rbp), %rdi
callq 0x66ee
movq -0x120(%rbp), %rbx
movq (%rbx), %rbx
jmp 0x3cc3
xorl %eax, %eax
leaq -0x168(%rbp), %rbx
leaq -0x1d0(%rbp), %r14
movq %rax, -0x1d0(%rbp)
cmpq -0x80(%rbp), %rax
jae 0x4374
movq -0xa8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %r15
movq 0x8(%rcx,%rax), %r12
cmpq %r12, %r15
je 0x4365
movq (%r15), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, -0x1d0(%rbp)
jae 0x435c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9488
testq %rax, %rax
jne 0x4267
andq $0x0, -0xd8(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x1, -0xf0(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0xd8(%rbp) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq %rax, %rdi
leaq -0xf8(%rbp), %r13
movq %r13, %rsi
callq 0x691e
movq %r13, %rdi
callq 0x6a4a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x9862
movq %rax, %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
testq %r13, %r13
je 0x42b8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x9c1c
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x10(%rax)
jmp 0x4312
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq -0x1d0(%rbp), %rcx
movq -0x78(%rbp), %rdx
leaq -0xd8(%rbp), %rsi
xorpd %xmm0, %xmm0
movupd %xmm0, (%rsi)
movq %rdx, -0xf8(%rbp)
movq %rcx, -0xf0(%rbp)
movq %rdx, -0xe8(%rbp)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, -0xe0(%rbp)
movq %rax, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x98ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x9c1c
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x20(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9512
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x9c1c
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x18(%rax)
addq $0x8, %r15
jmp 0x41dc
movq -0x1d0(%rbp), %rax
incq %rax
jmp 0x41b4
xorpd %xmm0, %xmm0
movq -0x118(%rbp), %r14
movupd %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x43b9
movq %rax, -0xa0(%rbp)
leaq 0x20(%rax), %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x4389
leaq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0x652a
jmp 0x43a3
leaq -0x168(%rbp), %rdi
callq 0x6aae
leaq -0x208(%rbp), %rdi
callq 0x6b8c
movq %r14, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x68ba
jmp 0x4496
jmp 0x4403
movq %rax, %rbx
jmp 0x447e
jmp 0x4463
movq %rax, %rbx
jmp 0x4472
jmp 0x444e
jmp 0x440c
movq %rax, %rbx
jmp 0x4496
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x6a4a
jmp 0x448a
jmp 0x444e
jmp 0x444e
jmp 0x444e
movq %rax, %rbx
movq %r14, %rdi
callq 0x9c3c
jmp 0x448a
jmp 0x444e
jmp 0x4463
jmp 0x443e
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x6a4a
jmp 0x4466
jmp 0x4463
movq %rax, %rbx
jmp 0x448a
jmp 0x4463
jmp 0x4463
jmp 0x4463
jmp 0x4463
jmp 0x4463
jmp 0x4463
jmp 0x4463
jmp 0x4463
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x66ee
leaq -0x98(%rbp), %rdi
callq 0x7894
leaq -0xf8(%rbp), %rdi
callq 0x66ee
leaq -0x168(%rbp), %rdi
callq 0x6aae
leaq -0x208(%rbp), %rdi
callq 0x6b8c
movq %rbx, %rdi
callq 0x2210