// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
addq $0xa8, %rdi
movq 0xb0(%r14), %rax
movq -0x10(%rax), %r15
subq -0x18(%rax), %r15
shrq $0x2, %r15
callq 0x4872
movslq (%rbx), %rax
movslq %r15d, %r15
imulq %rax, %r15
movq 0xb0(%r14), %rdi
addq $-0x18, %rdi
movq %r15, %rsi
callq 0x4892
movq 0x20(%r14), %rsi
subq 0x18(%r14), %rsi
shrq $0x2, %rsi
addl %r15d, %esi
movq %r14, %rdi
callq 0x4922
movslq %ebp, %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
adcq $0x0, %rdx
imulq $0xbc8f, %rdx, %rax     # imm = 0xBC8F
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, %rsi
adcq $0x0, %rsi
movq 0xb0(%r14), %rax
movq -0x30(%rax), %rcx
movq -0x28(%rax), %rdx
leaq 0x40(%rsp), %rbp
movq %rdx, 0x20(%rsp)
cmpq %rdx, %rcx
je 0x4569
movl (%rcx), %r13d
movslq %r13d, %r15
movq 0x18(%r14), %rax
cmpl $0x0, (%rax,%r15,4)
jg 0x4560
movq %rcx, 0x30(%rsp)
imulq $0xbc8f, %rsi, %rax     # imm = 0xBC8F
xorl %edx, %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
divq %rcx
cmpq $0x1, %rdx
movq %rdx, 0x28(%rsp)
movq %rdx, %rax
adcq $0x0, %rax
movq %rax, 0x60(%rsp)
movl (%rbx), %r12d
movsd 0x8(%rbx), %xmm0
ucomisd 0x708c(%rip), %xmm0     # 0xb488
jne 0x4400
jnp 0x444e
cvtsi2sd %r12d, %xmm1
movsd %xmm1, 0x8(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x40(%rsp)
movsd %xmm0, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
callq 0x4de0
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %r12d
cmpl $0x2, %r12d
pushq $0x1
popq %rax
cmovll %eax, %r12d
movq (%r14), %rax
movl (%rax,%r15,4), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x257a
movl %eax, %ecx
addl %r12d, %ecx
movl %ecx, 0x8(%rsp)
movl %eax, (%rsp)
cmpl 0x8(%rsp), %eax
jge 0x4551
movq 0x30(%r14), %rcx
movl (%rcx,%r15,4), %edx
incl %edx
cltq
movl %edx, (%rcx,%rax,4)
movq 0xb0(%r14), %rdi
addq $-0x18, %rdi
movq %rsp, %rsi
callq 0x3326
movl (%rsp), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x26c2
imulq $0xbc8f, 0x60(%rsp), %rax # imm = 0xBC8F
xorl %edx, %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
divq %rcx
movq %rdx, 0x60(%rsp)
cmpq $0x1, %rdx
adcq $0x0, %rdx
movq %rdx, 0x40(%rsp)
movq %rbp, %rdi
callq 0x47d8
movsd 0x10(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4547
imulq $0x18, %r15, %r12
movq 0x48(%r14), %rax
movq 0x8(%rax,%r12), %rcx
subq (%rax,%r12), %rcx
movq 0x60(%r14), %rax
movq 0x8(%rax,%r12), %rsi
subq (%rax,%r12), %rsi
sarq $0x2, %rcx
sarq $0x2, %rsi
movl %r13d, %edx
addq %rcx, %rsi
je 0x453a
movq %rbp, %rdi
callq 0x47d8
movsd 0x18(%rbx), %xmm1
ucomisd %xmm0, %xmm1
movl %r13d, %edx
ja 0x453a
movq 0x48(%r14), %rdi
addq %r12, %rdi
addq 0x60(%r14), %r12
movq %r12, %rsi
movq %rbp, %rdx
callq 0x4989
movl %eax, %edx
movl (%rsp), %esi
movq %r14, %rdi
callq 0x26c2
jmp 0x44cb
movl (%rsp), %eax
incl %eax
jmp 0x4469
movq 0x30(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rsi
addq $0x4, %rcx
jmp 0x43a3
imulq $0xbc8f, 0x18(%rsp), %rax # imm = 0xBC8F
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divq %rcx
cmpq $0x1, %rdx
adcq $0x0, %rdx
movq 0xb0(%r14), %rax
movq -0x18(%rax), %rcx
movq -0x10(%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0x60(%rsp), %r13
leaq 0x40(%rsp), %rbp
cmpq 0x18(%rsp), %rcx
je 0x47a0
movq %rcx, 0x20(%rsp)
movslq (%rcx), %r15
imulq $0xbc8f, %rdx, %rax     # imm = 0xBC8F
xorl %edx, %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
divq %rcx
cmpq $0x1, %rdx
movq %rdx, 0x28(%rsp)
movq %rdx, %rax
adcq $0x0, %rax
movq %rax, (%rsp)
imulq $0x18, %r15, %r12
movq %r15, 0x30(%rsp)
movq %r12, 0x8(%rsp)
movq %rsp, %rdi
callq 0x47d8
movsd 0x20(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x478d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movapd %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movq 0x78(%r14), %rax
movq 0x8(%rax,%r12), %rsi
subq (%rax,%r12), %rsi
sarq $0x2, %rsi
movq %r13, %rdi
callq 0x4892
movq 0x78(%r14), %rax
movq 0x8(%rax,%r12), %rsi
subq (%rax,%r12), %rsi
sarq $0x2, %rsi
movq %rbp, %rdi
callq 0x4892
movq 0x78(%r14), %rax
movq (%rax,%r12), %r15
movq 0x8(%rax,%r12), %r12
cmpq %r12, %r15
je 0x46c3
movslq (%r15), %rax
movl %eax, 0x14(%rsp)
movq 0x90(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
subq (%rcx,%rax), %rdx
cmpq $0x5, %rdx
jb 0x46bd
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0x3326
movslq 0x14(%rsp), %rax
movq 0x90(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
subq (%rcx,%rax), %rdx
shrq $0x2, %rdx
decl %edx
movl %edx, 0x3c(%rsp)
movq %rbp, %rdi
leaq 0x3c(%rsp), %rsi
callq 0x37be
addq $0x4, %r15
jmp 0x465a
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x46df
movq %r13, %rdi
movq %rbp, %rsi
movq %rsp, %rdx
callq 0x4a83
jmp 0x46f0
movq 0x78(%r14), %rdi
addq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0x4a25
movslq %eax, %r12
imulq $0x18, %r12, %r15
movq 0x48(%r14), %rax
movq 0x60(%r14), %rcx
movq 0x8(%rax,%r15), %rdx
subq (%rax,%r15), %rdx
sarq $0x2, %rdx
movq 0x8(%rcx,%r15), %rax
subq (%rcx,%r15), %rax
sarq $0x2, %rax
addq %rdx, %rax
je 0x4746
movq %rsp, %rdi
callq 0x47d8
ucomisd 0x28(%rbx), %xmm0
jbe 0x4746
movq 0x48(%r14), %rdi
addq %r15, %rdi
addq 0x60(%r14), %r15
movq %r15, %rsi
movq %rsp, %rdx
callq 0x4989
movslq %eax, %r12
imulq $0x18, %r12, %rdi
addq 0x90(%r14), %rdi
movq 0x30(%rsp), %r15
movl %r15d, %esi
movq %rsp, %rdx
callq 0x4bf1
cmpl %r15d, %eax
je 0x4773
movq %r14, %rdi
movl %r15d, %esi
movl %eax, %edx
callq 0x264c
movq %r13, %rdi
callq 0x3660
movq %rbp, %rdi
callq 0x3660
movq 0x8(%rsp), %r12
jmp 0x45e8
movq 0x20(%rsp), %rcx
addq $0x4, %rcx
movq 0x28(%rsp), %rdx
jmp 0x45a2
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x47b9
jmp 0x47b9
jmp 0x47b9
jmp 0x47b9
jmp 0x47b9
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3660
leaq 0x40(%rsp), %rdi
callq 0x3660
movq %rbx, %rdi
callq 0x21f0