// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movl (%rdi), %r15d
leaq 0x20(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movl %r15d, %esi
imull %esi, %esi
callq 0x3b7e
movq %rbx, %r13
shrq $0x20, %r13
movq %rbx, 0x10(%rsp)
imull %ebx, %r15d
addl %r13d, %r15d
movl %r15d, (%rsp)
negl %ebp
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rsp)
movl (%r14), %ecx
movq %r13, 0x38(%rsp)
negl %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
cmpl %ecx, %ebx
jge 0x3aa0
movl %ebx, %eax
movq 0x10(%rsp), %rdx
subl %edx, %eax
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
xorl %r12d, %r12d
movl %ebx, %ebp
xorl %edx, %ebp
cmpl %ecx, %r12d
jge 0x3a9c
leal (%r12,%r13), %eax
movl %ebp, %edx
orl %eax, %edx
je 0x3a97
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %r15d, %ecx
cvtsi2sd %ecx, %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x2230
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl (%r14), %ecx
incl %r12d
jmp 0x3a5c
incl %ebx
jmp 0x3a3e
movl (%rsp), %r13d
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movq 0x10(%rsp), %rbx
movl %ecx, %eax
imull %eax, %eax
cmpq %rax, %r15
jae 0x3b15
xorpd %xmm0, %xmm0
cmpq %r15, %r13
je 0x3b01
movl %r15d, %eax
cltd
idivl %ecx
subl %ebx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
subl 0x38(%rsp), %edx
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm1, (%rsp)
movsd 0x18(%rsp), %xmm1
callq 0x2230
movsd (%rsp), %xmm1
divsd 0x8(%rsp), %xmm0
movl (%r14), %ecx
addsd %xmm0, %xmm1
movq 0x20(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
jmp 0x3ab0
leaq 0x40(%rsp), %r15
callq 0x2060
cvtsi2sd %eax, %xmm0
divsd 0x14dd(%rip), %xmm0     # 0x5008
movsd %xmm0, 0x40(%rsp)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x3d81
subq 0x20(%rsp), %rax
shrq $0x3, %rax
cltd
idivl (%r14)
shlq $0x20, %rdx
orq %rax, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x37ee
jmp 0x3b1a
jmp 0x3b68
jmp 0x3b68
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3dba
movq %rbx, %rdi
callq 0x2240
nop