// File: /workspace/github_cpp_makefile_star2_O3/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 $0x108, %rsp            # imm = 0x108
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, 0x78(%rsp)
leal -0x1(%r14), %ecx
movl %ecx, %eax
imull %edi, %eax
movl %eax, %r13d
shrl $0x1f, %r13d
addl %eax, %r13d
sarl %r13d
cmpl %esi, %r13d
jle 0x65eb
movl %ecx, 0x38(%rsp)
movl %esi, 0x3c(%rsp)
movq %rbx, 0x58(%rsp)
movslq %r14d, %r15
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r12
movq %rbx, (%r12)
leaq 0x60(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0x6766
movq %rbx, (%r12)
leaq 0xd8(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, 0x30(%rsp)
movq %r15, %rsi
callq 0x6766
movl %r14d, %ebp
testl %r14d, %r14d
jle 0x627e
xorl %ebx, %ebx
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0x5daa
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
movq 0x60(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
movq %r12, %rdi
callq 0x5daa
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
movq 0xd8(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x623f
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movslq %r13d, %rsi
callq 0x6888
testl %r14d, %r14d
jle 0x6357
movl $0x1, %ebx
xorl %r12d, %r12d
leaq 0x1(%r12), %r13
cmpq 0x30(%rsp), %r13
jge 0x6348
movq %rbx, %r15
movq 0x60(%rsp), %rax
movsd (%rax,%r12,8), %xmm0
subsd (%rax,%r15,8), %xmm0
movq 0xd8(%rsp), %rax
movsd (%rax,%r12,8), %xmm1
subsd (%rax,%r15,8), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movl %r15d, 0xa0(%rsp)
movl %r12d, 0xa4(%rsp)
movsd %xmm0, 0xa8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x632a
movupd 0xa0(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x633c
leaq 0x10(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x6fc8
incq %r15
cmpq %r15, %rbp
jne 0x62bf
incq %rbx
movq %r13, %r12
cmpq %rbp, %r13
jne 0x62ac
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x6393
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 0x70ef
movq %r15, %rdi
movq %r12, %rsi
callq 0x71a2
leaq 0xa0(%rsp), %rdi
movl %r14d, %esi
callq 0x6934
xorpd %xmm0, %xmm0
leaq 0xf0(%rsp), %rdi
movapd %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
movq %rax, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x4, %rsi
callq 0x6980
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x4, %rsi
leaq 0x40(%rsp), %rdi
callq 0x6a1a
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x64df
leaq 0xa0(%rsp), %r14
leaq 0xf0(%rsp), %rbx
leaq 0x8(%rsp), %r13
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x4(%r15), %esi
movl %esi, 0xc(%rsp)
movl (%r15), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rdi
callq 0x6aac
movl %eax, %ebp
movl 0x8(%rsp), %esi
movq %r14, %rdi
callq 0x6aac
cmpl %eax, %ebp
jne 0x649c
movsd 0x30(%rsp), %xmm0
mulsd 0x61c6(%rip), %xmm0     # 0xc620
callq 0x2230
movsd %xmm0, 0x80(%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
movq %r13, %rdx
callq 0x6740
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x64c0
movsd 0x80(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x64d2
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
movq %r14, %rdi
callq 0x6ada
movq 0x58(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r13, %rdx
callq 0x6740
jmp 0x64d2
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x7780
addq $0x10, %r15
cmpq %r12, %r15
jne 0x6417
movl 0x3c(%rsp), %esi
subl 0x38(%rsp), %esi
xorpd %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rcx
callq 0xbb08
movq 0x80(%rsp), %r14
movq 0x88(%rsp), %rbx
cmpq %rbx, %r14
movq 0x58(%rsp), %r15
je 0x6567
movslq (%r14), %rdx
shlq $0x3, %rdx
addq 0xf0(%rsp), %rdx
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x654e
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r15)
jmp 0x6556
movq %r15, %rdi
callq 0x789c
addq $0x4, %r14
cmpq %rbx, %r14
jne 0x6528
movq 0x80(%rsp), %r14
testq %r14, %r14
je 0x6574
movq %r14, %rdi
callq 0x2150
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6583
callq 0x2150
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x6595
callq 0x2150
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x65a7
callq 0x2150
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x65b9
callq 0x2150
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x65c8
callq 0x2150
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x65da
callq 0x2150
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x6647
callq 0x2150
jmp 0x6647
movl $0x0, 0xa0(%rsp)
testl %r14d, %r14d
jle 0x6647
xorl %eax, %eax
leaq 0xa0(%rsp), %r15
leaq 0x60(%rsp), %r12
incl %eax
movl %eax, 0x60(%rsp)
cmpl %r14d, %eax
jge 0x663b
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6740
movl 0x60(%rsp), %eax
incl %eax
movl %eax, 0x60(%rsp)
cmpl %r14d, %eax
jl 0x6615
movl 0xa0(%rsp), %eax
incl %eax
movl %eax, 0xa0(%rsp)
cmpl %r14d, %eax
jl 0x660a
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6666
jmp 0x66b9
movq %rax, %rbx
jmp 0x66dd
jmp 0x6681
jmp 0x66b9
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x6684
callq 0x2150
jmp 0x6684
jmp 0x6681
jmp 0x6681
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x6693
callq 0x2150
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x66a5
callq 0x2150
leaq 0xa0(%rsp), %rdi
callq 0x6b22
jmp 0x66bc
movq %rax, %rbx
jmp 0x66cb
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x66cb
callq 0x2150
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x66dd
callq 0x2150
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x66ec
callq 0x2150
movq %rbx, %rdi
callq 0x2220