// File: /workspace/github_c_makefile_star2_O1/pwelke[P]GraphMiningTools/loading.c
// Function: readSimpleFormat
struct Graph* readSimpleFormat(char* filename, int undirected, struct GraphPool *p, int strspace) {
	int i;
	int v, w;
	FILE* file = NULL;
	struct VertexList *e, *f;
	struct Graph* g = getGraph(p);

	if ((file = fopen(filename, "r")) ){

		/* read info on the graph */
		if (fscanf(file, "%i %i \n", &(g->n), &(g->m)) == 2) {
			/* create vertex pointer array. The actual vertices are taken from vp*/

			if (!setVertexNumber(g, g->n)) {
				printf("Error allocating memory for vertex array.\n");
				fclose(file);
				free(g);
				return NULL;
			}

			/* read vertex info */
			for (i=0; i<g->n; ++i) {
				g->vertices[i] = getVertex(p->vertexPool);
				g->vertices[i]->label = malloc(strspace * sizeof(char));
				/* the vertex is the primary owner of its label string, other vertices may refer to its 
				string but must not free it, if deleted*/
				g->vertices[i]->isStringMaster = 1;
				if (fscanf(file, "%i %s\n", &(g->vertices[i] ->number), g->vertices[i] ->label) != 2) {
					printf("Error reading vertex %i\n", i);
					return NULL;
				}
			}

			/* read info on edges */
			for (i=0; i< g->m; ++i) { 
				e = getVertexList(p->listPool);
				e->label = malloc(strspace * sizeof(char));
				if (fscanf(file, "%i %i %s\n", &v, &w, e->label) == 3) {
					e->startPoint = g->vertices[v];
					e->endPoint = g->vertices[w];
					/* the edge is the primary owner of its label string, other edges may refer to its 
					string but must not free it, if deleted*/
					e->isStringMaster = 1;

					/* if graph is undirected, add two edges, if it is directed add one edge */
					addEdge(g->vertices[e->startPoint->number], e);
					if (undirected) {
						f = shallowCopyEdge(e, p->listPool);
						f->startPoint = e->endPoint;
						f->endPoint = e->startPoint;
						addEdge(g->vertices[f->startPoint->number], f);						
					}
				} else {
					printf("Error reading edge %i\n", i);
					fclose(file);
					return NULL;
				}
			}


		} else {
			printf("Error reading the file %s\n", filename);
			fclose(file);
			return NULL;
		}
	} else {
		printf("Error opening the file %s\n", filename);
		return NULL;
	}

	fclose(file);
	return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movl %esi, 0x4(%rsp)
movq %rdi, %r12
movq %rdx, %rdi
callq 0x147d7
movq %rax, %rbx
leaq 0x131b5(%rip), %rsi     # 0x200fd
movq %r12, %rdi
callq 0x11d0
testq %rax, %rax
je 0xd0d2
movq %rax, %r14
movq %rbx, %rcx
addq $0x4, %rcx
leaq 0x13612(%rip), %rsi     # 0x2057c
movq %rax, %rdi
movq %rbx, %rdx
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
jne 0xd0e7
movl (%rbx), %esi
movq %rbx, %rdi
callq 0x7e30
testq %rax, %rax
je 0xd104
cmpl $0x0, (%rbx)
movslq %ebp, %r13
jle 0xd000
leaq 0x135f9(%rip), %r12     # 0x205a0
xorl %ebp, %ebp
movq 0x10(%r15), %rdi
callq 0x145b2
movq 0x10(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r13, %rdi
callq 0x1190
movq 0x10(%rbx), %rcx
movq (%rcx,%rbp,8), %rdx
movq %rax, (%rdx)
movq (%rcx,%rbp,8), %rdx
movl $0x1, 0x24(%rdx)
movq (%rdx), %rcx
addq $0x18, %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
jne 0xd124
incq %rbp
movslq (%rbx), %rax
cmpq %rax, %rbp
jl 0xcfa9
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0xd0fa
xorl %ebp, %ebp
movq 0x18(%r15), %rdi
callq 0x1432b
movq %rax, %r12
movq %r13, %rdi
callq 0x1190
movq %rax, (%r12)
movq %r14, %rdi
leaq 0x1356b(%rip), %rsi     # 0x2059d
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1060
cmpl $0x3, %eax
jne 0xd148
movq 0x10(%rbx), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq %rcx, 0x10(%r12)
movslq 0x8(%rsp), %rdx
movq (%rax,%rdx,8), %rdx
movq %rdx, 0x18(%r12)
movl $0x1, 0x28(%r12)
movslq 0x18(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
callq 0x7cd0
cmpl $0x0, 0x4(%rsp)
je 0xd0c1
movq 0x18(%r15), %rsi
movq %r12, %rdi
callq 0x7bc0
movq 0x18(%r12), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%r12), %rdx
movq %rdx, 0x18(%rax)
movq 0x10(%rbx), %rdx
movslq 0x18(%rcx), %rcx
movq (%rdx,%rcx,8), %rdi
movq %rax, %rsi
callq 0x7cd0
incl %ebp
movq 0x10(%rsp), %rax
cmpl (%rax), %ebp
jl 0xd010
jmp 0xd0fa
leaq 0x13500(%rip), %rdi     # 0x205d9
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
jmp 0xd136
leaq 0x134d0(%rip), %rdi     # 0x205be
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
movq %r14, %rdi
callq 0x1090
jmp 0xd136
leaq 0x136d6(%rip), %rdi     # 0x207e1
callq 0x1070
movq %r14, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
jmp 0xd136
leaq 0x13459(%rip), %rdi     # 0x20584
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x10b0
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13458(%rip), %rdi     # 0x205a7
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0xd0fa