// File: /workspace/github_c_makefile_star2_O3/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 0x146a9
movq %rax, %rbx
leaq 0x13259(%rip), %rsi     # 0x200fd
movq %r12, %rdi
callq 0x11d0
testq %rax, %rax
je 0xd02e
movq %rax, %r14
movq %rbx, %rcx
addq $0x4, %rcx
leaq 0x136b6(%rip), %rsi     # 0x2057c
movq %rax, %rdi
movq %rbx, %rdx
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
jne 0xd043
movl (%rbx), %esi
movq %rbx, %rdi
callq 0x7e6c
testq %rax, %rax
je 0xd060
cmpl $0x0, (%rbx)
movslq %ebp, %r13
jle 0xcf5c
leaq 0x1369d(%rip), %r12     # 0x205a0
xorl %ebp, %ebp
movq 0x10(%r15), %rdi
callq 0x1447e
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 0xd080
incq %rbp
movslq (%rbx), %rax
cmpq %rax, %rbp
jl 0xcf05
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jle 0xd056
xorl %ebp, %ebp
movq 0x18(%r15), %rdi
callq 0x141f1
movq %rax, %r12
movq %r13, %rdi
callq 0x1190
movq %rax, (%r12)
movq %r14, %rdi
leaq 0x1360f(%rip), %rsi     # 0x2059d
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1060
cmpl $0x3, %eax
jne 0xd0a4
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 0x7cfe
cmpl $0x0, 0x4(%rsp)
je 0xd01d
movq 0x18(%r15), %rsi
movq %r12, %rdi
callq 0x7bec
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 0x7cfe
incl %ebp
movq 0x10(%rsp), %rax
cmpl (%rax), %ebp
jl 0xcf6c
jmp 0xd056
leaq 0x135a4(%rip), %rdi     # 0x205d9
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
jmp 0xd092
leaq 0x13574(%rip), %rdi     # 0x205be
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x10b0
movq %r14, %rdi
callq 0x1090
jmp 0xd092
leaq 0x1377a(%rip), %rdi     # 0x207e1
callq 0x1070
movq %r14, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
jmp 0xd092
leaq 0x134fd(%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 0x134fc(%rip), %rdi     # 0x205a7
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0xd056