// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/randomGraphGenerators.c
// Function: barabasiAlpha
struct Graph* barabasiAlpha(int n, int edgesAddedPerVertex, double alpha, 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) {
		if (rand() <= alpha * RAND_MAX) {
			int w = rand() % v;
			addEdgeBetweenVertices(v, w, intLabel(1), g, gp);
			g->vertices[v]->d += 1;
			g->vertices[w]->d += 1;
			g->vertices[v]->neighborhood->isStringMaster = 1;
		} else {
			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 $0x68, %rsp
movl %edi, 0x5c(%rsp)
movl %esi, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0xb970
cmpl $0x0, %eax
je 0x29b25
movl 0x5c(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl (%rcx), %eax
jl 0x29b25
movl 0x58(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x29b33
movq $0x0, 0x60(%rsp)
jmp 0x29efa
movq 0x40(%rsp), %rdi
callq 0x1fa40
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movl 0x5c(%rsp), %esi
callq 0xaa00
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x29c1c
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa440
movl %eax, %ecx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x28(%rax)
movl $0x1, %edi
callq 0x14ae0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x34(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x24(%rax)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x29b58
movq 0x48(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x29ccc
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f6a0
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x30(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x30(%rsp), %ecx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x18(%rax)
movl $0x1, %edi
callq 0x14ae0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x24(%rax)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x29c37
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x29ef0
callq 0x1220
cvtsi2sd %eax, %xmm1
movsd 0xc1b2(%rip), %xmm0     # 0x35ea8
mulsd 0x50(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x29da0
callq 0x1220
cltd
idivl 0x2c(%rsp)
movl %edx, 0x28(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x14(%rsp)
movl $0x1, %edi
callq 0x14ae0
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
callq 0xb670
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl $0x1, 0x28(%rax)
jmp 0x29ede
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x58(%rsp), %eax
jge 0x29edc
callq 0x1220
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %ecx
shll %ecx
cltd
idivl %ecx
movl %edx, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x29eca
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0x29eb8
movq 0x38(%rsp), %rdi
movl 0x2c(%rsp), %esi
movl 0x18(%rsp), %edx
callq 0xb490
cmpb $0x0, %al
jne 0x29eb6
movl 0x2c(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
movl $0x1, %edi
callq 0x14ae0
movl 0x8(%rsp), %edi
movl 0xc(%rsp), %esi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
callq 0xb670
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl $0x1, 0x28(%rax)
jmp 0x29eca
jmp 0x29eba
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x29ddc
jmp 0x29ecc
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x29da8
jmp 0x29ede
jmp 0x29ee0
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x29cd7
movq 0x38(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)