// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %r15
leaq 0xf86a(%rip), %rsi      # 0x10be7
movq %rax, %rdi
callq 0x1170
movq %rax, %r12
testq %rax, %rax
je 0x1520
movq %r15, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
andl $0x0, (%rbx)
xorl %r13d, %r13d
pushq $0xa
popq %rbx
leaq 0xc(%rsp), %rbp
movq $0x0, 0x10(%rsp)
pushq $0x76
popq %r15
movq %r12, %rdi
cmpl $-0x1, %r13d
je 0x151b
callq 0x1210
cmpl $0x70, %eax
je 0x13d9
movl %eax, %r13d
cmpl $0x63, %eax
jne 0x146c
movq %r12, %rdi
callq 0x1210
cmpl $0x76, %eax
jne 0x148a
movq %r12, %rdi
callq 0x1210
movl %eax, %ecx
movl %r15d, %eax
cmpl $0x69, %ecx
jne 0x148a
movq %r12, %rdi
callq 0x1210
movl %eax, %ecx
movl %r15d, %eax
cmpl $0x70, %ecx
jne 0x148a
movq %r12, %rdi
callq 0x1210
movl %eax, %ecx
movl %r15d, %eax
cmpl $0x20, %ecx
jne 0x148a
leaq 0xcd47(%rip), %rdi      # 0xe172
callq 0x11f0
movl %r15d, %r13d
andl $0x0, 0xc(%rsp)
cmpl $0xa, %r13d
jne 0x144b
jmp 0x147e
imull $0xa, 0xc(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0xc(%rsp)
movq %r12, %rdi
callq 0x1210
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
jbe 0x1440
movq %r14, %rdi
movq %rbp, %rsi
callq 0x17b0
jmp 0x1433
movl %r13d, %edi
callq 0x1040
testl %eax, %eax
jne 0x13b6
jmp 0x1497
movl %ebx, %eax
jmp 0x148a
movq %r12, %rdi
callq 0x1210
cmpl $0xa, %eax
jne 0x1482
movl %ebx, %r13d
jmp 0x13b6
cmpl $0x2d, %r13d
sete %cl
je 0x14d2
movl %r13d, %r15d
addl $-0x30, %r15d
cmpl $0x9, %r15d
ja 0x13b2
movb %cl, 0xb(%rsp)
movq %r12, %rdi
callq 0x1210
movl %eax, %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x14e4
imull $0xa, %r15d, %r15d
addl %eax, %r15d
jmp 0x14b5
pushq $0x2d
popq %rax
movl %eax, %r13d
movl %ecx, %eax
movq %rax, 0x10(%rsp)
jmp 0x13b2
movl %r15d, %esi
negl %esi
movl %r15d, %eax
cmovnsl %esi, %eax
testb $0x1, 0x10(%rsp)
cmovel %r15d, %esi
movq 0x20(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x1503
movl %eax, (%rcx)
movq 0x18(%rsp), %rdi
callq 0x19c7
movb 0xb(%rsp), %al
movq %rax, 0x10(%rsp)
jmp 0x13b2
callq 0x1110
testq %r12, %r12
setne %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq