// File: biotomas[P]ipasir/app/genipareach/genipareach.cpp
// Function: loadReachabilityProblem(char const*, Formula*, Formula*, Formula*, Formula*)
bool loadReachabilityProblem(const char* filename, Formula* initial, Formula* universal, Formula* goal, Formula* transition) {
	FILE* f = fopen(filename, "r");
	if (f == NULL) {
		return false;
	}
	int c = 0;
	bool neg = false;
	Formula* current = goal;
	while (c != EOF) {
		c = fgetc(f);

		// comment line
		if (c == 'c') {
			readLine(f);
			continue;
		}
		// problem lines
		if (c == 'i' || c == 'u' || c == 'g' || c == 't') {
			switch (c) {
			case 'i':
				current = initial;
				break;
			case 'u':
				current = universal;
				break;
			case 'g':
				current = goal;
				break;
			case 't':
				current = transition;
				break;
			default:
				printf("Invalid character: \"%c\"\n", c);
				return false;
			}
			current->variables = readNextNumber(f, 0);
			readLine(f);
			continue;
		}
		// whitespace
		if (isspace(c)) {
			continue;
		}
		// negative
		if (c == '-') {
			neg = true;
			continue;
		}

		// number
		if (isdigit(c)) {
			int num = readNextNumber(f, c);
			if (neg) {
				num *= -1;
			}
			neg = false;
			current->addLit(num);
		}
	}
	fclose(f);

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1d8cd(%rip), %rsi     # 0x1ed04
callq 0x1180
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1450
movb $0x0, -0x1(%rbp)
jmp 0x159a
movl $0x0, -0x3c(%rbp)
movb $0x0, -0x3d(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $-0x1, -0x3c(%rbp)
je 0x158d
movq -0x38(%rbp), %rdi
callq 0x1210
movl %eax, -0x3c(%rbp)
cmpl $0x63, -0x3c(%rbp)
jne 0x148a
movq -0x38(%rbp), %rdi
callq 0x13d0
jmp 0x1463
cmpl $0x69, -0x3c(%rbp)
je 0x14a6
cmpl $0x75, -0x3c(%rbp)
je 0x14a6
cmpl $0x67, -0x3c(%rbp)
je 0x14a6
cmpl $0x74, -0x3c(%rbp)
jne 0x152e
movl -0x3c(%rbp), %eax
addl $-0x67, %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0xe, %eax
ja 0x14f3
movq -0x58(%rbp), %rax
leaq 0x1ab42(%rip), %rcx     # 0x1c004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x150d
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x150d
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x150d
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x150d
movl -0x3c(%rbp), %esi
leaq 0x1ab43(%rip), %rdi     # 0x1c040
movb $0x0, %al
callq 0x1030
movb $0x0, -0x1(%rbp)
jmp 0x159a
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1360
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x13d0
jmp 0x1463
movl -0x3c(%rbp), %edi
callq 0x1040
cmpl $0x0, %eax
je 0x1540
jmp 0x1463
cmpl $0x2d, -0x3c(%rbp)
jne 0x154f
movb $0x1, -0x3d(%rbp)
jmp 0x1463
movl -0x3c(%rbp), %edi
callq 0x1100
cmpl $0x0, %eax
je 0x1588
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x1360
movl %eax, -0x4c(%rbp)
testb $0x1, -0x3d(%rbp)
je 0x1578
imull $-0x1, -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movb $0x0, -0x3d(%rbp)
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x1c40
jmp 0x1463
movq -0x38(%rbp), %rdi
callq 0x1120
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)