// File: /workspace/github_cpp_makefile_star2_O1/sharmaeklavya2[P]ddos-on-anycast/src/lib/graph_gen.cpp
// Function: make_random_connected_graph(int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&, int)
void make_random_connected_graph(int n, int approx_m, ipvec& l, int seed) {
    // Make a connected graph with (n vertices and approximately approx_m edges).
    // Returns the number of nodes in this graph. Returns the anti-symmetric edge list in l.
    // int n = std::max(1, int(std::normal_distribution<double>(n, n * 0.25)(rng));

    rng_t rng(seed);

    int max_edges = n * (n-1) / 2;
    if(approx_m >= max_edges) {
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                l.emplace_back(i, j);
            }
        }
        return;
    }

    // get distance between all points
    vector<double> xcoords(n, 0.0), ycoords(n, 0.0);
    for(int i=0; i<n; ++i) {
        xcoords[i] = runidist(0, 1, rng);
        ycoords[i] = runidist(0, 1, rng);
    }

    typedef std::tuple<double, int, int> diitrip;
    vector<diitrip> all_edges;
    all_edges.reserve(max_edges);
    for(int i=0; i<n; ++i) {
        for(int j=i+1; j<n; ++j) {
            diitrip t(norm(xcoords[i]-xcoords[j], ycoords[i]-ycoords[j]), i, j);
            all_edges.push_back(t);
        }
    }
    std::sort(all_edges.begin(), all_edges.end());

    // create MST
    DisjointSets ds(n);
    int n_components = n;
    ipvec edges2; vector<double> weights2;
    edges2.reserve(all_edges.size());
    weights2.reserve(all_edges.size());
    double weight_sum = 0;
    // all_edges2.reserve(all_edges.size());
    for(const diitrip& t: all_edges) {
        int i, j; double norm;
        std::tie(norm, i, j) = t;
        int i2 = ds.find(i), j2 = ds.find(j);
        if(i2 == j2) {
            double weight = std::exp(-norm/2);
            weight_sum += weight;
            edges2.emplace_back(i, j);
            weights2.push_back(weight);
        }
        else {
            n_components--;
            ds.unite(i, j);
            l.emplace_back(i, j);
        }
    }
    approx_m -= n-1;

    ivec indices;
    multi_sample(weights2, approx_m, indices, rng);
    for(int index: indices) {
        l.push_back(edges2[index]);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %rbx
movl %edi, %r14d
movslq %ecx, %rcx
movabsq $0x200000005, %rdx      # imm = 0x200000005
movq %rcx, %rax
mulq %rdx
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0x1e, %rax
movq %rax, %rdx
shlq $0x1f, %rdx
subq %rdx, %rax
leaq (%rcx,%rax), %rdx
cmpq $0x1, %rdx
adcq %rcx, %rax
movq %rax, 0x68(%rsp)
leal -0x1(%r14), %ecx
movl %ecx, %eax
imull %edi, %eax
movl %eax, %ebp
shrl $0x1f, %ebp
addl %eax, %ebp
sarl %ebp
cmpl %esi, %ebp
jle 0x66db
movl %ecx, 0x28(%rsp)
movl %esi, 0x2c(%rsp)
movq %rbx, 0x48(%rsp)
movslq %r14d, %r15
xorl %ebx, %ebx
leaq 0x88(%rsp), %r12
movq %rbx, (%r12)
leaq 0x50(%rsp), %rdi
leaq 0xc8(%rsp), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0x6850
movq %rbx, (%r12)
leaq 0xc8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, %rsi
callq 0x6850
movl %r14d, %r13d
testl %r14d, %r14d
jle 0x6386
xorl %ebx, %ebx
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0x5eb2
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
movq 0x50(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
movq %r15, %rdi
callq 0x5eb2
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
movq 0xc8(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
cmpq %rbx, %r13
jne 0x6347
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movslq %ebp, %rsi
callq 0x6968
testl %r14d, %r14d
jle 0x6459
movl $0x1, %ebx
xorl %r15d, %r15d
leaq 0x1(%r15), %r12
cmpq %r13, %r12
jae 0x644a
movq %rbx, %rbp
movq 0x50(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
subsd (%rax,%rbp,8), %xmm0
movq 0xc8(%rsp), %rax
movsd (%rax,%r15,8), %xmm1
subsd (%rax,%rbp,8), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movl %ebp, 0x88(%rsp)
movl %r15d, 0x8c(%rsp)
movsd %xmm0, 0x90(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x642c
movupd 0x88(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x643e
leaq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x70a2
incq %rbp
cmpq %rbp, %r13
jne 0x63c4
incq %rbx
movq %r12, %r15
cmpq %r13, %r12
jne 0x63b4
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x6495
movq %r12, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x71c9
movq %r15, %rdi
movq %r12, %rsi
callq 0x727c
leaq 0x88(%rsp), %rdi
movl %r14d, %esi
callq 0x6a14
xorpd %xmm0, %xmm0
leaq 0xe0(%rsp), %rdi
movapd %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x4, %rsi
callq 0x6a60
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x4, %rsi
leaq 0x30(%rsp), %rdi
callq 0x6afa
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x65de
leaq 0x88(%rsp), %r14
leaq 0xe0(%rsp), %rbx
leaq 0x8(%rsp), %r13
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0xc0(%rsp)
movl 0x4(%r15), %esi
movl %esi, 0xc(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rdi
callq 0x6b88
movl %eax, %ebp
movl 0x8(%rsp), %esi
movq %r14, %rdi
callq 0x6b88
cmpl %eax, %ebp
jne 0x659e
movsd 0xc0(%rsp), %xmm0
mulsd 0x70be(%rip), %xmm0     # 0xd620
callq 0x2230
movsd %xmm0, 0x70(%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
movq %r13, %rdx
callq 0x682a
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x65c2
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x65d1
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movq %r14, %rdi
callq 0x6bb6
movq 0x48(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r13, %rdx
callq 0x682a
jmp 0x65d1
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x7858
addq $0x10, %r15
cmpq %r12, %r15
jne 0x6519
movl 0x2c(%rsp), %esi
subl 0x28(%rsp), %esi
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rcx
callq 0xbcfc
movq 0x70(%rsp), %rbx
movq 0x78(%rsp), %r14
cmpq %r14, %rbx
movq 0x48(%rsp), %r15
je 0x6655
movslq (%rbx), %rdx
shlq $0x3, %rdx
addq 0xe0(%rsp), %rdx
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x6644
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r15)
jmp 0x664c
movq %r15, %rdi
callq 0x7974
addq $0x4, %rbx
cmpq %r14, %rbx
jne 0x661e
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x6664
callq 0x2150
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6673
callq 0x2150
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x6685
callq 0x2150
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x6697
callq 0x2150
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x66a9
callq 0x2150
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x66b8
callq 0x2150
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x66ca
callq 0x2150
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x6733
callq 0x2150
jmp 0x6733
movl $0x0, 0x88(%rsp)
testl %r14d, %r14d
jle 0x6733
leaq 0x88(%rsp), %r15
leaq 0x50(%rsp), %r12
movl 0x88(%rsp), %eax
incl %eax
movl %eax, 0x50(%rsp)
cmpl %r14d, %eax
jge 0x671e
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x682a
movl 0x50(%rsp), %eax
jmp 0x66ff
movl 0x88(%rsp), %eax
incl %eax
movl %eax, 0x88(%rsp)
cmpl %r14d, %eax
jl 0x66f8
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6752
jmp 0x67a2
movq %rax, %rbx
jmp 0x67c6
jmp 0x676a
jmp 0x67a2
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x676d
callq 0x2150
jmp 0x676d
jmp 0x676a
jmp 0x676a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x677c
callq 0x2150
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x678e
callq 0x2150
leaq 0x88(%rsp), %rdi
callq 0x6bfe
jmp 0x67a5
movq %rax, %rbx
jmp 0x67b4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x67b4
callq 0x2150
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x67c6
callq 0x2150
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x67d5
callq 0x2150
movq %rbx, %rdi
callq 0x2220
nop