// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/randomGraphGenerators.c
// Function: barabasiAlbert
struct Graph* barabasiAlbert(int n, int edgesAddedPerVertex, struct Graph* core, struct GraphPool* gp) {
	// min degree of core needs to be 1
	if ((getMinDegree(core) == 0) || (n < core->n) || (edgesAddedPerVertex > core->n)) {
		return NULL;
	}

	//m <= m_0
	struct Graph* g = getGraph(gp);
	setVertexNumber(g, n);

	// TODO copying of core can be sped up by directly copying in initialized vertex array of g
	for (int v=0; v<core->n; ++v) {
		// copy vertex into g
		g->vertices[v] = core->vertices[v];
		core->vertices[v] = NULL;

		// store degree of vertex in ->d for fast access
		g->vertices[v]->d = degree(g->vertices[v]);

		// set label of v
		g->vertices[v]->label = intLabel(1);
		g->vertices[v]->isStringMaster = 1;
	}
	g->m = core->m;

	for (int v=core->n; v<n; ++v) {
		g->vertices[v] = getVertex(gp->vertexPool);
		g->vertices[v]->number = v;
		g->vertices[v]->label = intLabel(1);
		g->vertices[v]->isStringMaster = 1;
	}

	for (int v=core->n; v<n; ++v) {
		for (int i=0; i<edgesAddedPerVertex; ++i) {
			int randV = rand() % (2 * g->m);
			int find = 0;
			for (int w=0; w<v; ++w) {
				find += g->vertices[w]->d;
				if (randV < find) {
					if (!isNeighbor(g, v, w)) {
						addEdgeBetweenVertices(v, w, intLabel(1), g, gp);
						g->vertices[v]->d += 1;
						g->vertices[w]->d += 1;
						g->vertices[v]->neighborhood->isStringMaster = 1;
					}
					break;
				}
			}
		}
	}
	return g;
}

// Assembly:
subq $0x58, %rsp
movl %edi, 0x4c(%rsp)
movl %esi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x40(%rsp), %rdi
callq 0xb970
cmpl $0x0, %eax
je 0x29f4f
movl 0x4c(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl (%rcx), %eax
jl 0x29f4f
movl 0x48(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x29f5d
movq $0x0, 0x50(%rsp)
jmp 0x2a267
movq 0x38(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movl 0x4c(%rsp), %esi
callq 0xaa00
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x2a046
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa440
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x28(%rax)
movl $0x1, %edi
callq 0x14ae0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x24(%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x29f82
movq 0x40(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x2a0f6
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, %rdx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x18(%rax)
movl $0x1, %edi
callq 0x14ae0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x24(%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x2a061
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x2a25d
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x48(%rsp), %eax
jge 0x2a24b
callq 0x1220
movq 0x30(%rsp), %rcx
movl 0x4(%rcx), %ecx
shll %ecx
cltd
idivl %ecx
movl %edx, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x2a239
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %eax
addl 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x18(%rsp), %eax
jge 0x2a227
movq 0x30(%rsp), %rdi
movl 0x24(%rsp), %esi
movl 0x14(%rsp), %edx
callq 0xb490
cmpb $0x0, %al
jne 0x2a225
movl 0x24(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x10(%rsp)
movl $0x1, %edi
callq 0x14ae0
movl 0xc(%rsp), %edi
movl 0x10(%rsp), %esi
movq %rax, %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
callq 0xb670
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x24(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl $0x1, 0x28(%rax)
jmp 0x2a239
jmp 0x2a229
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x2a14b
jmp 0x2a23b
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x2a117
jmp 0x2a24d
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x2a101
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)