// File: ekg[P]sgd2/src/sgd2.hpp
// Function: sgd2::build_graph_weighted(unsigned long, unsigned long, unsigned long*, unsigned long*, double*)
std::vector<std::vector<edge>> build_graph_weighted(uint64_t n, uint64_t m, uint64_t* I, uint64_t* J, double* V)
{
    // used to make graph undirected, in case graph is not already
    std::vector<std::unordered_map<uint64_t, double>> undirected(n);
    std::vector<std::vector<edge>> graph(n);

    for (uint64_t ij=0; ij<m; ij++)
    {
        uint64_t i = I[ij], j = J[ij];
        if (i >= n || j >= n)
            throw "i or j bigger than n";

        double v = V[ij];
        if (v <= 0)
            throw "v less or equal 0";

        if (i != j && undirected[j].find(i) == undirected[j].end()) // if key not there
        {
            undirected[i].insert({j, v});
            undirected[j].insert({i, v});
            graph[i].push_back(edge(j, v));
            graph[j].push_back(edge(i, v));
        }
        else
        {
            if (undirected[j][i] != v)
                throw "graph weights not symmetric";
        }
    }
    return graph;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x110(%rbp)
movq %rdi, %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0xa1f0
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0xa210
jmp 0x30a8
leaq -0x49(%rbp), %rdi
callq 0xa280
movb $0x0, -0x5d(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x5e(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0xa2a0
movq -0x110(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
callq 0xa2c0
jmp 0x30ec
leaq -0x5e(%rbp), %rdi
callq 0xa330
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x3454
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x313f
movq -0x78(%rbp), %rax
cmpq -0x10(%rbp), %rax
jb 0x31bc
movl $0x8, %edi
callq 0x2080
movq %rax, %rdi
leaq 0x1af29(%rip), %rax     # 0x1e07c
movq %rax, (%rdi)
movq 0x2ae63(%rip), %rsi     # 0x2dfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2290
jmp 0x3495
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0xa280
jmp 0x348c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x5e(%rbp), %rdi
callq 0xa330
jmp 0x3483
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xa520
jmp 0x3483
movq -0x30(%rbp), %rax
movq -0x68(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x3204
movl $0x8, %edi
callq 0x2080
movq %rax, %rdi
leaq 0x1aee2(%rip), %rax     # 0x1e0ce
movq %rax, (%rdi)
movq 0x2adca(%rip), %rsi     # 0x2dfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2290
jmp 0x3495
movq -0x70(%rbp), %rcx
xorl %eax, %eax
cmpq -0x78(%rbp), %rcx
movb %al, -0x121(%rbp)
je 0x327b
movq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa380
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0xa3a0
movq %rax, -0x130(%rbp)
jmp 0x3238
movq -0x130(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa380
movq %rax, %rdi
callq 0xa3d0
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xa350
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x328a
jmp 0x33de
movq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa380
movq %rax, -0x138(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0xa440
jmp 0x32b4
movq -0x138(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa400
movb %dl, -0x141(%rbp)
movq %rax, -0x140(%rbp)
jmp 0x32d6
movb -0x141(%rbp), %al
movq -0x140(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movb %al, -0xa8(%rbp)
movq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa380
movq %rax, -0x150(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0xa440
jmp 0x331a
movq -0x150(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa400
movb %dl, -0x159(%rbp)
movq %rax, -0x158(%rbp)
jmp 0x333c
movq -0x110(%rbp), %rdi
movb -0x159(%rbp), %al
movq -0x158(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movb %al, -0xc8(%rbp)
movq -0x70(%rbp), %rsi
callq 0xa470
movq %rax, -0x168(%rbp)
movq -0x78(%rbp), %rsi
movsd -0x80(%rbp), %xmm0
leaq -0xe0(%rbp), %rdi
callq 0xa4c0
jmp 0x3384
movq -0x168(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa490
jmp 0x3399
movq -0x110(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xa470
movq %rax, -0x170(%rbp)
movq -0x70(%rbp), %rsi
movsd -0x80(%rbp), %xmm0
leaq -0xf0(%rbp), %rdi
callq 0xa4c0
jmp 0x33c7
movq -0x170(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xa490
jmp 0x33dc
jmp 0x3441
movq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xa380
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0xa4f0
movq %rax, -0x178(%rbp)
jmp 0x3400
movq -0x178(%rbp), %rax
movsd (%rax), %xmm0
ucomisd -0x80(%rbp), %xmm0
jne 0x3416
jp 0x3416
jmp 0x343f
movl $0x8, %edi
callq 0x2080
movq %rax, %rdi
leaq 0x1acb6(%rip), %rax     # 0x1e0e0
movq %rax, (%rdi)
movq 0x2ab8c(%rip), %rsi     # 0x2dfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2290
jmp 0x3495
jmp 0x3441
jmp 0x3443
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x30fd
movb $0x1, -0x5d(%rbp)
testb $0x1, -0x5d(%rbp)
jne 0x346a
movq -0x110(%rbp), %rdi
callq 0xa520
leaq -0x48(%rbp), %rdi
callq 0xa580
movq -0x108(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0xa580
movq -0x58(%rbp), %rdi
callq 0x22a0
nopw %cs:(%rax,%rax)