// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movl (%rdi), %r15d
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl %r15d, %esi
imull %esi, %esi
callq 0x3f1c
movq %rbx, 0x28(%rsp)
shrq $0x20, %rbx
movl (%r14), %ecx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
testl %ecx, %ecx
movq %rbx, 0x48(%rsp)
movl %ebp, 0x10(%rsp)
movl %r15d, 0x24(%rsp)
jle 0x3dbd
negl %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rsp)
movl %ebx, %r13d
negl %r13d
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
testl %ecx, %ecx
jle 0x3db7
movl %ebx, %eax
movq 0x28(%rsp), %rdx
subl %edx, %eax
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
xorl %r12d, %r12d
movl %ebx, %ebp
xorl %edx, %ebp
leal (%r12,%r13), %eax
movl %ebp, %edx
orl %eax, %edx
je 0x3daf
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %r15d, %ecx
xorps %xmm0, %xmm0
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
cmpl %ecx, %r12d
jl 0x3d76
incl %ebx
cmpl %ecx, %ebx
jl 0x3d58
testl %ecx, %ecx
movq 0x28(%rsp), %rbx
movq 0x48(%rsp), %r12
je 0x3e5f
movl 0x24(%rsp), %edx
imull %ebx, %edx
movl 0x10(%rsp), %eax
negl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
addl %r12d, %edx
movl %edx, %r13d
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
cmpq %r15, %r13
jne 0x3e01
xorpd %xmm0, %xmm0
jmp 0x3e43
movl %r15d, %eax
cltd
idivl %ecx
subl %ebx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
subl %r12d, %edx
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
addl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm1, 0x18(%rsp)
movsd 0x10(%rsp), %xmm1
callq 0x2230
movsd 0x18(%rsp), %xmm1
divsd 0x8(%rsp), %xmm0
movl (%r14), %ecx
addsd %xmm0, %xmm1
movq 0x30(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
movl %ecx, %eax
imull %eax, %eax
cmpq %rax, %r15
jb 0x3df6
movslq %ebx, %rax
sarq $0x20, %rbx
leaq (%rax,%rax,2), %r12
leaq 0x50(%rsp), %r15
callq 0x2060
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x11ad(%rip), %xmm0     # 0x5030
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
movq %rcx, %rax
testq %rsi, %rsi
jle 0x3ec3
movq %rsi, %rdx
shrq %rdx
movsd (%rax,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3ebb
leaq (%rax,%rdx,8), %rax
addq $0x8, %rax
notq %rdx
addq %rsi, %rdx
movq %rdx, %rsi
testq %rdx, %rdx
jg 0x3e9f
subq %rcx, %rax
shrq $0x3, %rax
cltd
idivl (%r14)
shlq $0x20, %rdx
orq %rdx, %rax
movq 0x8(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%rbx,8), %rdi
movq %rax, 0x50(%rsp)
addq $0x8, %rdi
movq %r15, %rsi
callq 0x3b92
jmp 0x3e6f
jmp 0x3ef9
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3f13
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x2240
nop