// File: biotomas[P]ipasir/app/genipalsp/genipalsp.cpp
// Function: loadGraph(char const*, bool)
Graph loadGraph(const char* filename, bool backEdges = false) {
	FILE* f = fopen(filename, "r");
	if (f == NULL) {
		log("File '%s' cannot be opened\n", filename);
		exit(1);
	}
	Graph g;
	int c = 0;
	bool edge = true;

	while (c != EOF) {
		c = fgetc(f);

		// problem definition line
		if (c == 'p') {
			char pline[512];
			int i = 0;
			while (c != '\n') {
				pline[i++] = c;
				c = fgetc(f);
			}
			pline[i] = 0;
			if (2 != sscanf(pline, "p edge %d %d", &(g.verticesCount), &(g.edgesCount))) {
				edge = false;
				if (2 != sscanf(pline, "p sp %d %d", &(g.verticesCount), &(g.edgesCount))) {
					log("Failed to parse the problem definition line (%s)\n", pline);
				}
			}
			continue;
		}
		// comment
		if (c == 'c') {
			// skip this line
			while(c != '\n') {
				c = fgetc(f);
			}
			continue;
		}
		// edge
		if (c == 'e' || c == 'a') {
			char pline[512];
			int i = 0;
			while (c != '\n') {
				pline[i++] = c;
				c = fgetc(f);
			}
			pline[i] = 0;
			size_t start, end, weight;
			if (edge && 2 != sscanf(pline, "e %lu %lu", &start , &end)) {
				log("Invalid edge line (%s)\n", pline);
				exit(1);
			}
			if (!edge && 3 != sscanf(pline, "a %lu %lu %lu", &start , &end, &weight)) {
				log("Invalid edge line (%s)\n", pline);
				exit(1);
			}
			while (g.neighbours.size() <= start) {
				g.neighbours.push_back(vector<int>());
			}
			g.neighbours[start].push_back(end);

			if (edge && backEdges) {
				while (g.neighbours.size() <= end) {
					g.neighbours.push_back(vector<int>());
				}
				g.neighbours[end].push_back(start);
			}
			continue;
		}
	}
	fclose(f);
	return g;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movq %rdi, -0x4c8(%rbp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, -0x4c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1e80a(%rip), %rsi     # 0x20dc0
callq 0x21c0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x25e2
movq -0x10(%rbp), %rsi
leaq 0x1ba96(%rip), %rdi     # 0x1e067
movb $0x0, %al
callq 0x2480
movl $0x1, %edi
callq 0x21f0
movq -0x4c8(%rbp), %rdi
movb $0x0, -0x21(%rbp)
callq 0x34a0
movl $0x0, -0x28(%rbp)
movb $0x1, -0x29(%rbp)
cmpl $-0x1, -0x28(%rbp)
je 0x2a07
movq -0x20(%rbp), %rdi
callq 0x2280
movl %eax, -0x4cc(%rbp)
jmp 0x2618
movl -0x4cc(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x70, -0x28(%rbp)
jne 0x2712
movl $0x0, -0x244(%rbp)
cmpl $0xa, -0x28(%rbp)
je 0x2683
movb -0x28(%rbp), %cl
movslq -0x244(%rbp), %rax
movl %eax, %edx
incl %edx
movl %edx, -0x244(%rbp)
movb %cl, -0x240(%rbp,%rax)
movq -0x20(%rbp), %rdi
callq 0x2280
movl %eax, -0x4d0(%rbp)
jmp 0x2667
movl -0x4d0(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x2635
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2a38
movq -0x4c8(%rbp), %rdx
movslq -0x244(%rbp), %rax
movb $0x0, -0x240(%rbp,%rax)
leaq -0x240(%rbp), %rdi
movq %rdx, %rcx
addq $0x4, %rcx
leaq 0x1b9d5(%rip), %rsi     # 0x1e083
movb $0x0, %al
callq 0x2130
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
je 0x270d
movq -0x4c8(%rbp), %rdx
movb $0x0, -0x29(%rbp)
leaq -0x240(%rbp), %rdi
movq %rdx, %rcx
addq $0x4, %rcx
leaq 0x1b9b0(%rip), %rsi     # 0x1e090
movb $0x0, %al
callq 0x2130
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
je 0x270b
leaq 0x1b9a2(%rip), %rdi     # 0x1e09b
xorl %eax, %eax
leaq -0x240(%rbp), %rsi
callq 0x2480
jmp 0x2709
jmp 0x270b
jmp 0x270d
jmp 0x25fd
cmpl $0x63, -0x28(%rbp)
jne 0x2741
jmp 0x271a
cmpl $0xa, -0x28(%rbp)
je 0x273c
movq -0x20(%rbp), %rdi
callq 0x2280
movl %eax, -0x4d4(%rbp)
jmp 0x2731
movl -0x4d4(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x271a
jmp 0x25fd
cmpl $0x65, -0x28(%rbp)
je 0x2751
cmpl $0x61, -0x28(%rbp)
jne 0x2a02
movl $0x0, -0x454(%rbp)
cmpl $0xa, -0x28(%rbp)
je 0x2798
movb -0x28(%rbp), %cl
movslq -0x454(%rbp), %rax
movl %eax, %edx
incl %edx
movl %edx, -0x454(%rbp)
movb %cl, -0x450(%rbp,%rax)
movq -0x20(%rbp), %rdi
callq 0x2280
movl %eax, -0x4d8(%rbp)
jmp 0x278d
movl -0x4d8(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x275b
movslq -0x454(%rbp), %rax
movb $0x0, -0x450(%rbp,%rax)
testb $0x1, -0x29(%rbp)
je 0x27fc
leaq -0x450(%rbp), %rdi
leaq 0x1b912(%rip), %rsi     # 0x1e0cd
leaq -0x460(%rbp), %rdx
leaq -0x468(%rbp), %rcx
movb $0x0, %al
callq 0x2130
movl %eax, %ecx
movl $0x2, %eax
cmpl %ecx, %eax
je 0x27fc
leaq 0x1b8f5(%rip), %rdi     # 0x1e0d7
xorl %eax, %eax
leaq -0x450(%rbp), %rsi
callq 0x2480
jmp 0x27f2
movl $0x1, %edi
callq 0x21f0
testb $0x1, -0x29(%rbp)
jne 0x2858
leaq -0x450(%rbp), %rdi
leaq 0x1b8df(%rip), %rsi     # 0x1e0ef
leaq -0x460(%rbp), %rdx
leaq -0x468(%rbp), %rcx
leaq -0x470(%rbp), %r8
movb $0x0, %al
callq 0x2130
movl %eax, %ecx
movl $0x3, %eax
cmpl %ecx, %eax
je 0x2858
leaq 0x1b899(%rip), %rdi     # 0x1e0d7
xorl %eax, %eax
leaq -0x450(%rbp), %rsi
callq 0x2480
jmp 0x284e
movl $0x1, %edi
callq 0x21f0
jmp 0x285a
movq -0x4c8(%rbp), %rdi
addq $0x8, %rdi
callq 0x34c0
cmpq -0x460(%rbp), %rax
ja 0x28ed
movq -0x4c8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x4e8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x490(%rbp)
movq $0x0, -0x480(%rbp)
leaq -0x490(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x3520
movq -0x4e8(%rbp), %rdi
movq -0x4e0(%rbp), %rsi
callq 0x34f0
jmp 0x28c2
leaq -0x490(%rbp), %rdi
callq 0x3540
jmp 0x285a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x3540
jmp 0x2a38
movq -0x4c8(%rbp), %rdi
addq $0x8, %rdi
movq -0x460(%rbp), %rsi
callq 0x35a0
movq %rax, %rdi
movl -0x468(%rbp), %eax
movl %eax, -0x494(%rbp)
leaq -0x494(%rbp), %rsi
callq 0x35c0
jmp 0x2921
testb $0x1, -0x29(%rbp)
je 0x29fd
testb $0x1, -0x11(%rbp)
je 0x29fd
jmp 0x2937
movq -0x4c8(%rbp), %rdi
addq $0x8, %rdi
callq 0x34c0
cmpq -0x468(%rbp), %rax
ja 0x29c7
movq -0x4c8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x4f8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x4b0(%rbp)
movq $0x0, -0x4a0(%rbp)
leaq -0x4b0(%rbp), %rdi
movq %rdi, -0x4f0(%rbp)
callq 0x3520
movq -0x4f8(%rbp), %rdi
movq -0x4f0(%rbp), %rsi
callq 0x34f0
jmp 0x299f
leaq -0x4b0(%rbp), %rdi
callq 0x3540
jmp 0x2937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x4b0(%rbp), %rdi
callq 0x3540
jmp 0x2a38
movq -0x4c8(%rbp), %rdi
addq $0x8, %rdi
movq -0x468(%rbp), %rsi
callq 0x35a0
movq %rax, %rdi
movl -0x460(%rbp), %eax
movl %eax, -0x4b4(%rbp)
leaq -0x4b4(%rbp), %rsi
callq 0x35c0
jmp 0x29fb
jmp 0x29fd
jmp 0x25fd
jmp 0x25fd
movq -0x20(%rbp), %rdi
callq 0x2140
jmp 0x2a12
movb $0x1, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
jne 0x2a28
movq -0x4c8(%rbp), %rdi
callq 0x35f0
movq -0x4c0(%rbp), %rax
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
movq -0x4c8(%rbp), %rdi
callq 0x35f0
movq -0x38(%rbp), %rdi
callq 0x22d0
nopl (%rax)