// File: roornelas[P]small-world/./graph.hpp
// Function: Graph::add_long_edges(std::pair<int, int>, int, int)
double add_long_edges(pair<int, int> vertex, int q, int r) {

		//cout << "Adding long edges of " << "(" << vertex.first << ", " << vertex.second << ") \n ";
		double norm_const = 0;
		int vertex_index = vertex.first * side_length + vertex.second;
		vector<double> cdf;

		cdf.resize(side_length * side_length);

		for (int i = 0; i < side_length; i++) {
			for (int j = 0; j < side_length; j++) {
				if (!(vertex.first == i && vertex.second == j)) {
					norm_const +=  pow(lattice_distance(vertex, make_pair(i, j)), -r);
				}
			}
		}

		double total = 0;


		for (int i = 0; i < side_length * side_length; i++) {
			double diff = (i == vertex_index) ? 0 : pow(lattice_distance(vertex, make_pair(i / side_length, i % side_length)), -r) / norm_const;
			total += diff;
			cdf[i] = total;
		}

		for (int i = 0; i < q; i++) {
			double random = ((double) rand() / (RAND_MAX));
			vector<double>::iterator low = std::upper_bound(cdf.begin(), cdf.end(), random);
			int cdf_index = distance(cdf.begin(), low);

			pair<int, int> neighbor = make_pair(cdf_index / side_length, cdf_index % side_length);

			add_edge(make_pair(vertex, neighbor));
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rsi, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movq $0x0, -0x20(%rbp)
movl (%rax), %edx
movl -0x8(%rbp), %eax
movl -0x4(%rbp), %ecx
imull %edx, %eax
addl %ecx, %eax
movl %eax, -0x24(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x8e40
movq -0x108(%rbp), %rax
movq -0x100(%rbp), %rdi
movl (%rax), %eax
imull %eax, %eax
movl %eax, %esi
callq 0x8e60
jmp 0x8a98
movl $0x0, -0x50(%rbp)
movq -0x108(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl (%rcx), %eax
jge 0x8b74
movl $0x0, -0x54(%rbp)
movq -0x108(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl (%rcx), %eax
jge 0x8b64
movl -0x8(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x8ada
movl -0x4(%rbp), %eax
cmpl -0x54(%rbp), %eax
je 0x8b54
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x7d80
movq %rax, -0x110(%rbp)
jmp 0x8af8
movq -0x110(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x35f0
movl %eax, %edi
movl -0x18(%rbp), %esi
negl %esi
callq 0x8ef0
movsd %xmm0, -0x118(%rbp)
jmp 0x8b26
movsd -0x118(%rbp), %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x8b54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x9060
jmp 0x8e33
jmp 0x8b56
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x8ab8
jmp 0x8b66
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x8a9f
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x108(%rbp), %rdx
movl -0x74(%rbp), %eax
movl (%rdx), %ecx
imull (%rdx), %ecx
cmpl %ecx, %eax
jge 0x8c98
movl -0x74(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x8bb2
xorps %xmm0, %xmm0
movsd %xmm0, -0x120(%rbp)
jmp 0x8c48
movq -0x108(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x74(%rbp), %eax
movl (%rcx), %esi
cltd
idivl %esi
movl %eax, -0x94(%rbp)
movl -0x74(%rbp), %eax
movl (%rcx), %ecx
cltd
idivl %ecx
movl %edx, -0x98(%rbp)
leaq -0x94(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3af0
movq %rax, -0x128(%rbp)
jmp 0x8bfc
movq -0x128(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x35f0
movl %eax, %edi
movl -0x18(%rbp), %esi
negl %esi
callq 0x8ef0
movsd %xmm0, -0x130(%rbp)
jmp 0x8c33
movsd -0x130(%rbp), %xmm0
divsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movslq -0x74(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x8f20
movsd -0x138(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x8b83
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x8e31
callq 0x2070
cvtsi2sd %eax, %xmm0
movsd 0x4346(%rip), %xmm1     # 0xd008
divsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x8f90
movq -0x148(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x8fc0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x8f40
movq %rax, -0x140(%rbp)
jmp 0x8d1b
movq -0x140(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x8f90
movq %rax, -0xd0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x8ff0
movq %rax, -0x150(%rbp)
jmp 0x8d63
movq -0x108(%rbp), %rcx
movq -0x150(%rbp), %rax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl (%rcx), %esi
cltd
idivl %esi
movl %eax, -0xe4(%rbp)
movl -0xc4(%rbp), %eax
movl (%rcx), %ecx
cltd
idivl %ecx
movl %edx, -0xe8(%rbp)
leaq -0xe4(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3af0
movq %rax, -0x158(%rbp)
jmp 0x8db5
movq -0x158(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x9030
movq %rdx, -0x168(%rbp)
movq %rax, -0x160(%rbp)
jmp 0x8de3
movq -0x108(%rbp), %rdi
movq -0x168(%rbp), %rax
movq -0x160(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
callq 0x7f40
jmp 0x8e1b
jmp 0x8e1d
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x8ca2
ud2
movq -0x48(%rbp), %rdi
callq 0x22a0
nopl (%rax)