// File: ekg[P]sgd2/src/sgd2.hpp
// Function: sgd2::build_graph_unweighted(unsigned long, unsigned long, unsigned long*, unsigned long*)
std::vector<std::vector<uint64_t>> build_graph_unweighted(uint64_t n, uint64_t m, uint64_t* I, uint64_t* J)
{
    // used to make graph undirected, in case it is not already
    std::vector<std::unordered_set<uint64_t>> undirected(n);
    std::vector<std::vector<uint64_t>> 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";

        if (i != j && undirected[j].find(i) == undirected[j].end()) // if edge not seen
        {
            undirected[i].insert(j);
            undirected[j].insert(i);
            graph[i].push_back(j);
            graph[j].push_back(i);
        }
    }
    return graph;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x9930
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x9950
jmp 0x28e4
leaq -0x41(%rbp), %rdi
callq 0x99c0
movb $0x0, -0x55(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x56(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x99e0
movq -0xc0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x9a00
jmp 0x2928
leaq -0x56(%rbp), %rdi
callq 0x9a70
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x2b47
movq -0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x297b
movq -0x70(%rbp), %rax
cmpq -0x10(%rbp), %rax
jb 0x29f8
movl $0x8, %edi
callq 0x2080
movq %rax, %rdi
leaq 0x1b6ed(%rip), %rax     # 0x1e07c
movq %rax, (%rdi)
movq 0x2b627(%rip), %rsi     # 0x2dfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2290
jmp 0x2b88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x99c0
jmp 0x2b7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x9a70
jmp 0x2b76
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x9c10
jmp 0x2b76
movq -0x68(%rbp), %rcx
xorl %eax, %eax
cmpq -0x70(%rbp), %rcx
movb %al, -0xd1(%rbp)
je 0x2a63
movq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x9ac0
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x9ae0
movq %rax, -0xe0(%rbp)
jmp 0x2a2c
movq -0xe0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x9ac0
movq %rax, %rdi
callq 0x9b10
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9a90
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x2a72
jmp 0x2b34
movq -0x68(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x9ac0
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x9b40
movb %dl, -0xe9(%rbp)
movq %rax, -0xe8(%rbp)
jmp 0x2a9a
movb -0xe9(%rbp), %al
movq -0xe8(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movb %al, -0x88(%rbp)
movq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x9ac0
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x9b40
movb %dl, -0xf9(%rbp)
movq %rax, -0xf8(%rbp)
jmp 0x2adc
movq -0xc0(%rbp), %rdi
movb -0xf9(%rbp), %al
movq -0xf8(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movb %al, -0x98(%rbp)
movq -0x68(%rbp), %rsi
callq 0x9b80
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x9ba0
jmp 0x2b14
movq -0xc0(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x9b80
movq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x9ba0
jmp 0x2b32
jmp 0x2b34
jmp 0x2b36
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2939
movb $0x1, -0x55(%rbp)
testb $0x1, -0x55(%rbp)
jne 0x2b5d
movq -0xc0(%rbp), %rdi
callq 0x9c10
leaq -0x40(%rbp), %rdi
callq 0x9c70
movq -0xb8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x9c70
movq -0x50(%rbp), %rdi
callq 0x22a0
nopl (%rax,%rax)