// File: /workspace/github_cpp_makefile_star2_O3/biotomas[P]ipasir/app/genipabones/genipabones.cpp
// Function: loadFormula(void*, char const*, std::vector<int, std::allocator<int>>&, int&)
bool loadFormula(void* solver, const char* filename, vector<int>& boundary, int& maxVar) {
	FILE* f = fopen(filename, "r");
	if (f == NULL) {
		return false;
	}
	maxVar = 0;
	int c = 0;
	bool neg = false;
	while (c != EOF) {
		c = fgetc(f);

		// comment or problem definition line
		if (c == 'c' || c == 'p') {
			c = fgetc(f);
			if (c == 'v' && fgetc(f) == 'i' && fgetc(f) == 'p' && fgetc(f) == ' ') {
				// boundary variables
				printf("c back-bone candidates specified in input file.\n");
				int num = 0;
				while(c != '\n') {
					c = fgetc(f);
					while (isdigit(c)) {
						num = num*10 + (c-'0');
						c = fgetc(f);
					}
					boundary.push_back(num);
					num = 0;
				}
			}
			// skip this line
			while(c != '\n') {
				c = fgetc(f);
			}
			continue;
		}
		// whitespace
		if (isspace(c)) {
			continue;
		}
		// negative
		if (c == '-') {
			neg = true;
			continue;
		}

		// number
		if (isdigit(c)) {
			int num = c - '0';
			c = fgetc(f);
			while (isdigit(c)) {
				num = num*10 + (c-'0');
				c = fgetc(f);
			}
			if (neg) {
				num *= -1;
			}
			neg = false;

			if (abs(num) > maxVar) {
				maxVar = abs(num);
			}
			// add to the solver
			ipasir_add(solver, num);
		}
	}
	fclose(f);
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %r15
leaq 0x1149c(%rip), %rsi     # 0x12c09
movq %rax, %rdi
callq 0x1150
movq %rax, %r12
testq %rax, %rax
je 0x1945
movl $0x0, (%rbx)
movl $0x0, 0xc(%rsp)
leaq 0x8(%rsp), %rbp
movq %r12, %rdi
callq 0x11f0
cmpl $0x70, %eax
je 0x17ad
movl %eax, %r13d
cmpl $0x63, %eax
jne 0x188e
movq %r12, %rdi
callq 0x11f0
movl %eax, %r13d
cmpl $0xa, %eax
je 0x189a
cmpl $0x76, %r13d
jne 0x1879
movq %r12, %rdi
callq 0x11f0
cmpl $0x69, %eax
jne 0x1879
movq %r12, %rdi
callq 0x11f0
cmpl $0x70, %eax
jne 0x1879
movq %r12, %rdi
callq 0x11f0
cmpl $0x20, %eax
jne 0x1879
leaq 0xe971(%rip), %rdi      # 0x10172
callq 0x11d0
movl $0x0, 0x8(%rsp)
movq %r12, %rdi
callq 0x11f0
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x1844
movl 0x8(%rsp), %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rax,%rcx,2), %eax
movl %eax, 0x8(%rsp)
movq %r12, %rdi
callq 0x11f0
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0x1822
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x185e
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x1869
movq %r14, %rdi
movq %rbp, %rdx
callq 0x1c34
movl $0x0, 0x8(%rsp)
cmpl $0xa, %r13d
jne 0x180e
jmp 0x1886
movq %r12, %rdi
callq 0x11f0
cmpl $0xa, %eax
jne 0x1879
movl $0xa, %r13d
jmp 0x189a
movl %r13d, %edi
callq 0x1040
testl %eax, %eax
je 0x18a9
cmpl $-0x1, %r13d
jne 0x1794
jmp 0x193d
cmpl $0x2d, %r13d
jne 0x18bd
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x2d, %r13d
jmp 0x189a
movq %r15, 0x10(%rsp)
movl %r13d, %r15d
addl $-0x30, %r15d
cmpl $0x9, %r15d
ja 0x1933
movq %r12, %rdi
callq 0x11f0
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x18ff
leal (%r15,%r15,4), %ecx
leal (%rax,%rcx,2), %r15d
movq %r12, %rdi
callq 0x11f0
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0x18e3
movl %r15d, %esi
negl %esi
movl %r15d, %eax
cmovnsl %esi, %eax
testb $0x1, 0xc(%rsp)
cmovel %r15d, %esi
cmpl (%rbx), %eax
jle 0x1919
movl %eax, (%rbx)
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x1de9
movl $0x0, 0xc(%rsp)
jmp 0x189a
movq 0x10(%rsp), %r15
jmp 0x189a
movq %r12, %rdi
callq 0x10f0
testq %r12, %r12
setne %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq