// File: sharmaeklavya2[P]ddos-on-anycast/src/lib/network_grow.cpp
// Function: Network::vgrow(GrowParams const&, int)
void Network::vgrow(const GrowParams& grow_params, int seed) {

    int n_leaves_rough = depthwise.back().size();
    depthwise.emplace_back();
    int expected_children = grow_params.num_children * n_leaves_rough;
    depthwise.back().reserve(expected_children);
    reserve(size() + expected_children);
    rng_t rng1(seed);

    rng_t rng2(rng1());
    for(int u: depthwise[depthwise.size()-2]) {
        if(!is_virtual(u)) {
            rng_t rng3(rng2());
            int n = do_sigma_n(grow_params.num_children, grow_params.num_children_sigma, rng3);
            int vfirst = make_new_vertices(n, nid[u]);
            int vend = vfirst + n;
            for(int v=vfirst; v<vend; ++v) {
                depth[v] = depth[u]+1;
                depthwise.back().push_back(v);
                add_upward_edge(v, u);
                // optionally add extra upstreams
                rng_t rng4(rng3());
                while(runidist(0, 1, rng4) < grow_params.prob_multi_upstream) {
                    int u2;
                    if(in_nbrs[u].size() + side_nbrs[u].size() == 0 ||
                        runidist(0, 1, rng4) < grow_params.prob_self_multi_upstream) {
                        u2 = u;
                    }
                    else {
                        u2 = sample(in_nbrs[u], side_nbrs[u], rng4);
                    }
                    add_upward_edge(v, u2);
                }
            }
        }
    }

    // add side edges
    rng2.seed(rng1());
    for(int v: depthwise.back()) {
        rng_t rng3(rng2());
        while(runidist(0, 1, rng3) < grow_params.prob_side_peering) {
            ivec weights, items;
            items.reserve(up_nbrs[v].size());
            weights.reserve(up_nbrs[v].size());
            for(int u: up_nbrs[v]) {
                if(down_nbrs[u].size() > 1) {
                    items.push_back(u);
                    weights.push_back(down_nbrs[u].size()-1);
                }
            }
            int u;
            if(weights.empty()) {
                u = sample(up_nbrs[v], rng3);
            }
            else {
                u = weighed_sample(items, weights, rng3);
            }
            int u2 = u;
            if(in_nbrs[u].size() + side_nbrs[u].size() > 0 &&
                runidist(0, 1, rng3) > grow_params.prob_self_side_peering) {
                u2 = sample(in_nbrs[u], side_nbrs[u], rng3);
            }
            int v2 = sample_other(down_nbrs[u2], v, rng3);
            if(v2 != v) {
                add_side_edge(v, v2);
            }
        }
    }
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movl %edx, 0x164(%rsp)
movq 0x170(%rsp), %rdi
movq %rdi, 0x58(%rsp)
addq $0xa8, %rdi
callq 0xa0d0
movq %rax, %rdi
callq 0x4f00
movq 0x58(%rsp), %rdi
movl %eax, 0x160(%rsp)
addq $0xa8, %rdi
callq 0xa1a0
movq 0x58(%rsp), %rdi
movq 0x168(%rsp), %rax
movl (%rax), %eax
imull 0x160(%rsp), %eax
movl %eax, 0x15c(%rsp)
addq $0xa8, %rdi
callq 0xa0d0
movq %rax, %rdi
movslq 0x15c(%rsp), %rsi
callq 0xa200
movq 0x58(%rsp), %rdi
callq 0x4950
movq 0x58(%rsp), %rdi
movl %eax, %esi
addl 0x15c(%rsp), %esi
callq 0xa310
movslq 0x164(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x9f10
leaq 0x150(%rsp), %rdi
callq 0x9f40
movq %rax, %rsi
leaq 0x148(%rsp), %rdi
callq 0x9f10
movq 0x58(%rsp), %rdi
movq %rdi, %rax
addq $0xa8, %rax
movq %rax, 0x60(%rsp)
addq $0xa8, %rdi
callq 0x4ee0
movq 0x60(%rsp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x46a0
movq %rax, 0x140(%rsp)
movq 0x140(%rsp), %rdi
callq 0x5bf0
movq %rax, 0x138(%rsp)
movq 0x140(%rsp), %rdi
callq 0x5a70
movq %rax, 0x130(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x9fe0
testb $0x1, %al
jne 0x9660
jmp 0x9925
leaq 0x138(%rsp), %rdi
callq 0xa020
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x12c(%rsp)
movl 0x12c(%rsp), %esi
callq 0x4830
testb $0x1, %al
jne 0x9911
leaq 0x148(%rsp), %rdi
callq 0x9f40
movq %rax, %rsi
leaq 0x120(%rsp), %rdi
callq 0x9f10
movq 0x168(%rsp), %rax
movl (%rax), %edi
movq 0x168(%rsp), %rax
movsd 0x8(%rax), %xmm0
leaq 0x120(%rsp), %rsi
callq 0x9db0
movq 0x58(%rsp), %rdi
movl %eax, 0x11c(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x54(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0x4860
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %esi
movl (%rax), %edx
callq 0x2720
movl %eax, 0x118(%rsp)
movl 0x118(%rsp), %eax
addl 0x11c(%rsp), %eax
movl %eax, 0x114(%rsp)
movl 0x118(%rsp), %eax
movl %eax, 0x110(%rsp)
movl 0x110(%rsp), %eax
cmpl 0x114(%rsp), %eax
jge 0x990f
movq 0x58(%rsp), %rdi
addq $0x30, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x4860
movq 0x58(%rsp), %rdi
movl (%rax), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
addq $0x30, %rdi
movslq 0x110(%rsp), %rsi
callq 0x4860
movl 0x50(%rsp), %ecx
movq 0x58(%rsp), %rdi
movl %ecx, (%rax)
addq $0xa8, %rdi
callq 0xa0d0
movq %rax, %rdi
leaq 0x110(%rsp), %rsi
callq 0x46f0
movq 0x58(%rsp), %rdi
movl 0x110(%rsp), %esi
movl 0x12c(%rsp), %edx
callq 0x2960
leaq 0x120(%rsp), %rdi
callq 0x9f40
movq %rax, %rsi
leaq 0x108(%rsp), %rdi
callq 0x9f10
xorl %edi, %edi
movl $0x1, %esi
leaq 0x108(%rsp), %rdx
callq 0x9e50
movaps %xmm0, %xmm1
movq 0x168(%rsp), %rax
movsd 0x10(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x98f7
movq 0x58(%rsp), %rdi
addq $0x48, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq 0x58(%rsp), %rdi
movq %rax, 0x48(%rsp)
addq $0x60, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq %rax, %rcx
movq 0x48(%rsp), %rax
addq %rcx, %rax
cmpq $0x0, %rax
je 0x987d
xorl %edi, %edi
movl $0x1, %esi
leaq 0x108(%rsp), %rdx
callq 0x9e50
movaps %xmm0, %xmm1
movq 0x168(%rsp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x988d
movl 0x12c(%rsp), %eax
movl %eax, 0x104(%rsp)
jmp 0x98da
movq 0x58(%rsp), %rdi
addq $0x48, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x46a0
movq 0x58(%rsp), %rdi
movq %rax, 0x40(%rsp)
addq $0x60, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x46a0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
leaq 0x108(%rsp), %rdx
callq 0xa3b0
movl %eax, 0x104(%rsp)
movq 0x58(%rsp), %rdi
movl 0x110(%rsp), %esi
movl 0x104(%rsp), %edx
callq 0x2960
jmp 0x97d3
jmp 0x98f9
movl 0x110(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x110(%rsp)
jmp 0x972e
jmp 0x9911
jmp 0x9913
leaq 0x138(%rsp), %rdi
callq 0xa0b0
jmp 0x9642
leaq 0x150(%rsp), %rdi
callq 0x9f40
movq %rax, %rsi
leaq 0x148(%rsp), %rdi
callq 0xa4c0
movq 0x58(%rsp), %rdi
addq $0xa8, %rdi
callq 0xa0d0
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x5bf0
movq %rax, 0xf0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x5a70
movq %rax, 0xe8(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x9fe0
testb $0x1, %al
jne 0x99a3
jmp 0x9d91
leaq 0xf0(%rsp), %rdi
callq 0xa020
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x9f40
movq %rax, %rsi
leaq 0xd8(%rsp), %rdi
callq 0x9f10
xorl %edi, %edi
movl $0x1, %esi
leaq 0xd8(%rsp), %rdx
callq 0x9e50
movaps %xmm0, %xmm1
movq 0x168(%rsp), %rax
movsd 0x20(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x9d7d
leaq 0xc0(%rsp), %rdi
callq 0x6950
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x6950
movq 0x58(%rsp), %rdi
addq $0x78, %rdi
movslq 0xe4(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0xa200
jmp 0x9a50
movq 0x58(%rsp), %rdi
addq $0x78, %rdi
movslq 0xe4(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq %rax, %rsi
leaq 0xc0(%rsp), %rdi
callq 0xa200
jmp 0x9a80
movq 0x58(%rsp), %rdi
addq $0x78, %rdi
movslq 0xe4(%rsp), %rsi
callq 0x46a0
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
callq 0x5bf0
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rdi
callq 0x5a70
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x9fe0
testb $0x1, %al
jne 0x9ae6
jmp 0x9bb6
leaq 0x88(%rsp), %rdi
callq 0xa020
movq 0x58(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
addq $0x90, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
cmpq $0x1, %rax
jbe 0x9ba2
leaq 0xa8(%rsp), %rdi
leaq 0x7c(%rsp), %rsi
callq 0x46f0
jmp 0x9b35
movq 0x58(%rsp), %rdi
addq $0x90, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
decl %eax
movl %eax, 0x78(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x46c0
jmp 0x9b6d
jmp 0x9ba2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x5020
leaq 0xc0(%rsp), %rdi
callq 0x5020
jmp 0x9d99
jmp 0x9ba4
leaq 0x88(%rsp), %rdi
callq 0xa0b0
jmp 0x9ac8
leaq 0xc0(%rsp), %rdi
callq 0x86a0
testb $0x1, %al
jne 0x9bc9
jmp 0x9bff
movq 0x58(%rsp), %rdi
addq $0x78, %rdi
movslq 0xe4(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
leaq 0xd8(%rsp), %rsi
callq 0xa520
movl %eax, 0x34(%rsp)
jmp 0x9bf5
movl 0x34(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x9c2a
leaq 0xa8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0xa590
movl %eax, 0x30(%rsp)
jmp 0x9c22
movl 0x30(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x58(%rsp), %rdi
movl 0x74(%rsp), %eax
movl %eax, 0x70(%rsp)
addq $0x48, %rdi
movslq 0x74(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq 0x58(%rsp), %rdi
movq %rax, 0x28(%rsp)
addq $0x60, %rdi
movslq 0x74(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
callq 0x4f00
movq %rax, %rcx
movq 0x28(%rsp), %rax
addq %rcx, %rax
cmpq $0x0, %rax
jbe 0x9cfd
xorl %edi, %edi
movl $0x1, %esi
leaq 0xd8(%rsp), %rdx
callq 0x9e50
movsd %xmm0, 0x20(%rsp)
jmp 0x9c9a
movsd 0x20(%rsp), %xmm0
movq 0x168(%rsp), %rax
ucomisd 0x28(%rax), %xmm0
jbe 0x9cfd
movq 0x58(%rsp), %rdi
addq $0x48, %rdi
movslq 0x74(%rsp), %rsi
callq 0x46a0
movq 0x58(%rsp), %rdi
movq %rax, 0x10(%rsp)
addq $0x60, %rdi
movslq 0x74(%rsp), %rsi
callq 0x46a0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
leaq 0xd8(%rsp), %rdx
callq 0xa3b0
movl %eax, 0x1c(%rsp)
jmp 0x9cf5
movl 0x1c(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x58(%rsp), %rdi
addq $0x90, %rdi
movslq 0x70(%rsp), %rsi
callq 0x46a0
movq %rax, %rdi
movl 0xe4(%rsp), %esi
leaq 0xd8(%rsp), %rdx
callq 0xa870
movl %eax, 0xc(%rsp)
jmp 0x9d30
movl 0xc(%rsp), %eax
movl %eax, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0xe4(%rsp), %eax
je 0x9d5e
movq 0x58(%rsp), %rdi
movl 0xe4(%rsp), %esi
movl 0x6c(%rsp), %edx
callq 0x2870
jmp 0x9d5c
jmp 0x9d5e
leaq 0xa8(%rsp), %rdi
callq 0x5020
leaq 0xc0(%rsp), %rdi
callq 0x5020
jmp 0x99d6
jmp 0x9d7f
leaq 0xf0(%rsp), %rdi
callq 0xa0b0
jmp 0x9985
addq $0x178, %rsp            # imm = 0x178
retq
movq 0xa0(%rsp), %rdi
callq 0x21f0
nopw %cs:(%rax,%rax)