// File: ekg[P]sgd2/src/main.cpp
// Function: main
int main(void) {
    uint64_t n = 8;
    uint64_t len_I = 9;
    //uint64_t I[len_I] = { 0,0,1,2,3,4,4,5,6 };
    //uint64_t J[len_I] = { 1,2,3,3,4,5,6,7,7 };
    std::vector<uint64_t> I = { 0,0,1,2,3,4,4,5,6 };
    std::vector<uint64_t> J = { 1,2,3,3,4,5,6,7,7 };
    //double V[len_I] = { 1,2,1,1,3,1,2,2,1 };
    //double X[2*n]; // = { 0,0, .1,.1, .2,.2, .3,.3, .4,.4, .5,.5, .6,.6, .7,.7 };
    std::vector<double> X(2*n);
    std::random_device dev;
    // todo, seed with graph topology/contents to get a stable result
    std::mt19937 rng(dev());
    std::uniform_real_distribution<double> dist(0,1);
    for (uint64_t i = 0; i < 2*n; ++i) {
        X[i] = dist(rng);
    }
    //double X[2*n];
    uint64_t p = 10;
    uint64_t t_max = 30;
    double eps = 0.01;
    //layout_sparse_weighted(n, X, len_I, I, J, V, p, t_max, eps);
    sgd2::layout_sparse_unweighted(n, X.data(), I.size(), I.data(), J.data(), p, t_max, eps);
    /*
    for (uint64_t i = 0; i < n; ++i) {
        std::cout << X[i*2] << " " << X[i*2+1] << std::endl;
    }
    */
    draw_svg(n, X, len_I, I, J);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x28f0, %rsp           # imm = 0x28F0
movl $0x0, -0x4(%rbp)
movq $0x8, -0x10(%rbp)
movq $0x9, -0x18(%rbp)
movups 0x15347(%rip), %xmm0    # 0x1e310
movaps %xmm0, -0x60(%rbp)
movups 0x1532c(%rip), %xmm0    # 0x1e300
movaps %xmm0, -0x70(%rbp)
movups 0x15311(%rip), %xmm0    # 0x1e2f0
movaps %xmm0, -0x80(%rbp)
movups 0x152f6(%rip), %xmm0    # 0x1e2e0
movaps %xmm0, -0x90(%rbp)
movq $0x6, -0x50(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x9, -0x38(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x2890(%rbp)
callq 0x9df0
movq -0x2890(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0xbdc0
jmp 0x9039
leaq -0x91(%rbp), %rdi
callq 0x9e90
movups 0x1530c(%rip), %xmm0    # 0x1e358
movaps %xmm0, -0xf0(%rbp)
movups 0x152ee(%rip), %xmm0    # 0x1e348
movaps %xmm0, -0x100(%rbp)
movups 0x152d0(%rip), %xmm0    # 0x1e338
movaps %xmm0, -0x110(%rbp)
movups 0x152b2(%rip), %xmm0    # 0x1e328
movaps %xmm0, -0x120(%rbp)
movq $0x7, -0xe0(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x9, -0xc8(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x2898(%rbp)
callq 0x9df0
movq -0x2898(%rbp), %rcx
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0xbdc0
jmp 0x90d7
leaq -0x121(%rbp), %rdi
callq 0x9e90
movq -0x10(%rbp), %rax
addq %rax, %rax
movq %rax, -0x28a8(%rbp)
leaq -0x141(%rbp), %rdi
movq %rdi, -0x28a0(%rbp)
callq 0xa6b0
movq -0x28a8(%rbp), %rsi
movq -0x28a0(%rbp), %rdx
leaq -0x140(%rbp), %rdi
callq 0xbe40
jmp 0x9120
leaq -0x141(%rbp), %rdi
callq 0xa750
leaq -0x14d0(%rbp), %rdi
callq 0x93e0
jmp 0x913a
leaq -0x14d0(%rbp), %rdi
callq 0x9480
movl %eax, -0x28ac(%rbp)
jmp 0x914e
movl -0x28ac(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x2858(%rbp), %rdi
callq 0x94a0
jmp 0x9166
leaq -0x2868(%rbp), %rdi
xorps %xmm0, %xmm0
movsd 0x14e90(%rip), %xmm1    # 0x1e008
callq 0xb090
jmp 0x917f
movq $0x0, -0x2870(%rbp)
movq -0x2870(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq %rcx
cmpq %rcx, %rax
jae 0x9294
leaq -0x2868(%rbp), %rdi
leaq -0x2858(%rbp), %rsi
callq 0xb0c0
movsd %xmm0, -0x28b8(%rbp)
jmp 0x91be
movq -0x2870(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0xa7a0
movsd -0x28b8(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x2870(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2870(%rbp)
jmp 0x918a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x9e90
jmp 0x93d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x121(%rbp), %rdi
callq 0x9e90
jmp 0x93ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x141(%rbp), %rdi
callq 0xa750
jmp 0x93be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x93b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x14d0(%rbp), %rdi
callq 0x9900
jmp 0x93b2
movq $0xa, -0x2878(%rbp)
movq $0x1e, -0x2880(%rbp)
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, -0x2888(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28d8(%rbp)
leaq -0x140(%rbp), %rdi
callq 0xbeb0
movq %rax, -0x28d0(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x28e0(%rbp)
callq 0xbed0
movq -0x28e0(%rbp), %rdi
movq %rax, -0x28c8(%rbp)
callq 0xbef0
movq %rax, -0x28c0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xbef0
movq -0x28d8(%rbp), %rdi
movq -0x28d0(%rbp), %rsi
movq -0x28c8(%rbp), %rdx
movq -0x28c0(%rbp), %rcx
movq %rax, %r8
movq -0x2878(%rbp), %r9
movq -0x2880(%rbp), %r10
movsd -0x2888(%rbp), %xmm0
movq %rsp, %rax
movq %r10, (%rax)
callq 0x8790
jmp 0x9351
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x140(%rbp), %rsi
leaq -0x30(%rbp), %rcx
leaq -0xc0(%rbp), %r8
callq 0x8b60
jmp 0x9372
movl $0x0, -0x4(%rbp)
leaq -0x14d0(%rbp), %rdi
callq 0x9900
leaq -0x140(%rbp), %rdi
callq 0xaa80
leaq -0xc0(%rbp), %rdi
callq 0xa130
leaq -0x30(%rbp), %rdi
callq 0xa130
movl -0x4(%rbp), %eax
addq $0x28f0, %rsp           # imm = 0x28F0
popq %rbp
retq
leaq -0x140(%rbp), %rdi
callq 0xaa80
leaq -0xc0(%rbp), %rdi
callq 0xa130
leaq -0x30(%rbp), %rdi
callq 0xa130
movq -0xa0(%rbp), %rdi
callq 0x22a0
nop