// File: /workspace/github_cpp_makefile_star2_O1/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 0x3dea
movl %r15d, 0x1c(%rsp)
movl %ebp, (%rsp)
movq %rbx, 0x28(%rsp)
shrq $0x20, %rbx
movq %rbx, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, (%r14)
jle 0x3c8a
movl (%rsp), %eax
negl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %r13
negl %r13d
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, (%r14)
jle 0x3c83
movl %ebx, %eax
movq 0x28(%rsp), %rcx
subl %ecx, %eax
movl %eax, %r15d
negl %r15d
cmovsl %eax, %r15d
xorl %r12d, %r12d
movl %ebx, %ebp
xorl %ecx, %ebp
leal (%r12,%r13), %eax
movl %ebp, %ecx
orl %eax, %ecx
je 0x3c7b
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
addl %r15d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x2230
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incl %r12d
cmpl (%r14), %r12d
jl 0x3c45
incl %ebx
cmpl (%r14), %ebx
jl 0x3c25
movl (%r14), %ecx
testl %ecx, %ecx
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r12
je 0x3d2a
movl 0x1c(%rsp), %edx
imull %ebx, %edx
movl (%rsp), %eax
negl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%rsp)
addl %r12d, %edx
movl %edx, %r13d
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
cmpq %r15, %r13
je 0x3d0b
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, 0x10(%rsp)
movsd (%rsp), %xmm1
callq 0x2230
movsd 0x10(%rsp), %xmm1
divsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm1
movq 0x30(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
incq %r15
movl (%r14), %ecx
movl %ecx, %eax
imull %eax, %eax
cmpq %rax, %r15
jb 0x3cc4
movslq %ebx, %rax
sarq $0x20, %rbx
leaq (%rax,%rax,2), %r12
leaq 0x50(%rsp), %r15
callq 0x2060
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x12ba(%rip), %xmm0     # 0x5008
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movq %rcx, %rax
testq %rdx, %rdx
jle 0x3d91
movq %rcx, %rax
movq %rdx, %rsi
shrq %rsi
movsd (%rax,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3d89
leaq (%rax,%rsi,8), %rax
addq $0x8, %rax
notq %rsi
addq %rdx, %rsi
movq %rsi, %rdx
testq %rsi, %rsi
jg 0x3d6d
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 0x3a48
jmp 0x3d3a
jmp 0x3dc7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3de1
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x2240
nop