// File: /workspace/github_cpp_makefile_star2_O2/Laakeri[P]maxpre/src/inputreader.cpp
// Function: maxPreprocessor::InputReader::readClauses(std::istream&, bool)
int InputReader::readClauses(istream& input, bool maxSat) {
	clauses.clear();
	weights.clear();
	cardinalityConstraints.clear();
	readError = "";
	currentLine = 0;
	string line;
	while (getline(input, line)) {
		currentLine++;
		if (line.size() > 0 && line[0] == 'p') break;
	}
	if (line.size() == 0 || line[0] != 'p') {
		readError = "Cannot find the p-line of the input";
		return 1;
	}
	stringstream parameterLine;
	parameterLine<<line;
	parameterLine>>line;
	if (line != "p") {
		readError = "Invalid p-line of the input (line "+to_string(currentLine)+")";
		return 1;
	}
	parameterLine>>line>>nbvar>>nbclauses;
	clauses.reserve(nbclauses);
	weights.reserve(nbclauses);
	if (parameterLine.fail()) {
		readError = "Invalid p-line of the input (line "+to_string(currentLine)+")";
		return 1;
	}
	if (line == "wcnf" && maxSat) {
		inputFormat = INPUT_FORMAT_WPMS;
		if (!(parameterLine>>top)) {
			cerr<<"Weighted Max-SAT input format"<<endl;
			top = (1ull << 63ull) - 1;
		}
		else {
			cerr<<"Weighted Partial Max-SAT input format"<<endl;
		}
		cerr<<"Top "<<top<<endl;
	}
	else if (line == "cnf" && maxSat) {
		inputFormat = INPUT_FORMAT_MS;
		cerr<<"Max-SAT input format"<<endl;
		top = (1ull << 63ull) - 1;
	}
	else if (line == "cnf" && !maxSat) {
		inputFormat = INPUT_FORMAT_SAT;
		cerr<<"SAT input format"<<endl;
		top = (1ull << 63ull) - 1;
	}
	else {
		readError = "Invalid p-line of the input (problem type "+line+" and the dimacs format do not match) (line "+to_string(currentLine)+")";
		return 1;
	}
	while (1) {
		currentLine++;
		int status = readLine(input);
		if (status == 1) break;
		else if (status == 2) return 1;
		assert(status == 0);
	}
	int freeVar = 1;
	for (auto& clause : clauses) {
		for (int lit : clause) {
			freeVar = max(freeVar, abs(lit) + 1);
		}
	}
	for (auto& cc : cardinalityConstraints) {
		for (int lit : cc.inputLiterals) freeVar = max(freeVar, abs(lit) + 1);
		for (int lit : cc.outputLiterals) freeVar = max(freeVar, abs(lit) + 1);
		for (int lit : cc.addLiterals) freeVar = max(freeVar, abs(lit) + 1);
	}
	for (auto& cc : cardinalityConstraints) {
		vector<vector<int> > cls = cc.getClauses(freeVar);
		for (auto& clause : cls) {
			clauses.push_back(clause);
			weights.push_back(top);
			for (int lit : clause) {
				freeVar = max(freeVar, abs(lit) + 1);
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movl %edx, (%rsp)
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x40(%rdi), %r14
movq %r14, %rdi
callq 0x1fa16
movq 0x58(%rbx), %rax
cmpq %rax, 0x60(%rbx)
je 0x1f396
movq %rax, 0x60(%rbx)
leaq 0x58(%rbx), %r15
leaq 0x70(%rbx), %rdi
callq 0x1fa1e
leaq 0x10(%rbx), %r13
leaq 0x11cf5(%rip), %rsi     # 0x310a3
movq %r13, %rdi
callq 0x34d0
andl $0x0, 0x8(%rbx)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
movq 0x10(%rsp), %rax
jne 0x1f402
incl 0x8(%rbx)
testq %rax, %rax
je 0x1f3d0
movq 0x8(%rsp), %rax
cmpb $0x70, (%rax)
jne 0x1f3d0
jmp 0x1f40b
testq %rax, %rax
je 0x1f49d
movq 0x8(%rsp), %rax
cmpb $0x70, (%rax)
jne 0x1f49d
leaq 0xd0(%rsp), %rdi
callq 0x3210
leaq 0xe0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3290
leaq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3360
leaq 0xf76d(%rip), %rsi      # 0x2ebbe
leaq 0x8(%rsp), %rdi
callq 0x1fa26
testb %al, %al
je 0x1f4b4
movl 0x8(%rbx), %esi
leaq 0x28(%rsp), %rdi
callq 0x1f9bd
leaq 0x10ee3(%rip), %rsi     # 0x30356
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x1f999
leaq 0x110fd(%rip), %rdx     # 0x30586
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x6944
jmp 0x1f54b
leaq 0x10e8e(%rip), %rsi     # 0x30332
movq %r13, %rdi
callq 0x34d0
pushq $0x1
popq %rbx
jmp 0x1f587
leaq 0xd0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3360
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31a0
leaq 0x4(%rbx), %rbp
movq %rax, %rdi
movq %rbp, %rsi
callq 0x31a0
movslq (%rbp), %rsi
movq %r14, %rdi
callq 0x1fa30
movslq (%rbp), %rsi
movq %r15, %rdi
callq 0x1fad2
movq 0xd0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xf0(%rsp,%rax)
je 0x1f5a5
movl 0x8(%rbx), %esi
leaq 0x28(%rsp), %rdi
callq 0x1f9bd
leaq 0x10e30(%rip), %rsi     # 0x30356
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x1f999
leaq 0x1104a(%rip), %rdx     # 0x30586
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x6944
leaq 0x68(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3350
movq %rbx, %rdi
callq 0x3130
leaq 0x48(%rsp), %rdi
callq 0x3130
leaq 0x28(%rsp), %rdi
callq 0x3130
pushq $0x1
popq %rbx
leaq 0xd0(%rsp), %rdi
callq 0x3230
leaq 0x8(%rsp), %rdi
callq 0x3130
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xefb8(%rip), %rsi      # 0x2e564
leaq 0x8(%rsp), %rdi
callq 0x6844
andb (%rsp), %al
movabsq $0x7fffffffffffffff, %rbp # imm = 0x7FFFFFFFFFFFFFFF
cmpb $0x1, %al
jne 0x1f618
movl $0x1, 0x38(%rbx)
leaq 0x30(%rbx), %r13
leaq 0xd0(%rsp), %rdi
movq %r13, %rsi
callq 0x3170
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x1f712
movq 0x249f5(%rip), %rdi     # 0x43ff0
leaq 0x10d77(%rip), %rsi     # 0x30379
callq 0x32a0
movq %rax, %rdi
callq 0x3140
movq %rbp, (%r13)
jmp 0x1f72d
leaq 0xef46(%rip), %rsi      # 0x2e565
leaq 0x8(%rsp), %rdi
callq 0x6844
movl (%rsp), %ecx
testb %cl, %al
je 0x1f63f
leaq 0x10d4b(%rip), %rsi     # 0x30382
pushq $0x2
popq %rax
jmp 0x1f76a
leaq 0xef1f(%rip), %rsi      # 0x2e565
leaq 0x8(%rsp), %rdi
movl %ecx, %ebp
callq 0x6844
xorb $0x1, %al
orb %bpl, %al
je 0x1f756
leaq 0x10d5e(%rip), %rsi     # 0x303c2
leaq 0xb0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x1fbcf
leaq 0x10d70(%rip), %rdx     # 0x303ed
leaq 0x28(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x6944
movl 0x8(%rbx), %esi
leaq 0x90(%rsp), %rdi
callq 0x1f9bd
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x1fb68
leaq 0x10ec9(%rip), %rdx     # 0x30586
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x6944
leaq 0x68(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3350
movq %rbx, %rdi
callq 0x3130
leaq 0x48(%rsp), %rdi
callq 0x3130
leaq 0x90(%rsp), %rdi
callq 0x3130
leaq 0x28(%rsp), %rdi
callq 0x3130
leaq 0xb0(%rsp), %rdi
jmp 0x1f572
movq 0x248d7(%rip), %rdi     # 0x43ff0
leaq 0x10c77(%rip), %rsi     # 0x30397
callq 0x32a0
movq %rax, %rdi
callq 0x3140
movq 0x248bc(%rip), %rdi     # 0x43ff0
leaq 0x10c82(%rip), %rsi     # 0x303bd
callq 0x32a0
movq (%r13), %rsi
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
jmp 0x1f785
leaq 0x10c29(%rip), %rsi     # 0x30386
pushq $0x3
popq %rax
movabsq $0x7fffffffffffffff, %rbp # imm = 0x7FFFFFFFFFFFFFFF
movl %eax, 0x38(%rbx)
movq 0x2487c(%rip), %rdi     # 0x43ff0
callq 0x32a0
movq %rax, %rdi
callq 0x3140
movq %rbp, 0x30(%rbx)
incl 0x8(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1f0e0
testl %eax, %eax
je 0x1f785
cmpl $0x1, %eax
jne 0x1f577
movq 0x40(%rbx), %rax
movq 0x48(%rbx), %rcx
pushq $0x1
popq %rbp
cmpq %rcx, %rax
je 0x1f7de
movq (%rax), %rdx
movq 0x8(%rax), %rsi
cmpq %rsi, %rdx
je 0x1f7d8
movl (%rdx), %edi
movl %edi, %r8d
negl %r8d
cmovsl %edi, %r8d
incl %r8d
cmpl %r8d, %ebp
cmovlel %r8d, %ebp
addq $0x4, %rdx
jmp 0x1f7b7
addq $0x18, %rax
jmp 0x1f7ab
movq 0x70(%rbx), %rsi
movq 0x78(%rbx), %rax
movq %rax, (%rsp)
movq %rsi, %rax
cmpq (%rsp), %rax
je 0x1f86b
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
cmpq %rdx, %rcx
je 0x1f819
movl (%rcx), %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
incl %edi
cmpl %edi, %ebp
cmovlel %edi, %ebp
addq $0x4, %rcx
jmp 0x1f7fb
movq 0x20(%rax), %rcx
movq 0x28(%rax), %rdx
cmpq %rdx, %rcx
je 0x1f83f
movl (%rcx), %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
incl %edi
cmpl %edi, %ebp
cmovlel %edi, %ebp
addq $0x4, %rcx
jmp 0x1f821
movq 0x40(%rax), %rcx
movq 0x48(%rax), %rdx
cmpq %rdx, %rcx
je 0x1f865
movl (%rcx), %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
incl %edi
cmpl %edi, %ebp
cmovlel %edi, %ebp
addq $0x4, %rcx
jmp 0x1f847
addq $0x60, %rax
jmp 0x1f7ed
addq $0x30, %rbx
cmpq (%rsp), %rsi
je 0x1f8ef
leaq 0x68(%rsp), %rdi
movq %rsi, 0x88(%rsp)
movl %ebp, %edx
callq 0x2bc6c
movq 0x68(%rsp), %r13
movq 0x70(%rsp), %r12
cmpq %r12, %r13
je 0x1f8d7
movq %r14, %rdi
movq %r13, %rsi
callq 0x18f96
movq %r15, %rdi
movq %rbx, %rsi
callq 0x193d8
movq (%r13), %rax
movq 0x8(%r13), %rcx
cmpq %rcx, %rax
je 0x1f8d1
movl (%rax), %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
incl %esi
cmpl %esi, %ebp
cmovlel %esi, %ebp
addq $0x4, %rax
jmp 0x1f8b6
addq $0x18, %r13
jmp 0x1f893
leaq 0x68(%rsp), %rdi
callq 0x6aa2
movq 0x88(%rsp), %rsi
addq $0x60, %rsi
jmp 0x1f86f
xorl %ebx, %ebx
jmp 0x1f57a
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3130
jmp 0x1f908
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x3130
jmp 0x1f91a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3130
jmp 0x1f929
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x1f952
jmp 0x1f963
jmp 0x1f93b
jmp 0x1f94a
jmp 0x1f963
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3130
jmp 0x1f94d
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3130
jmp 0x1f97a
jmp 0x1f963
jmp 0x1f968
jmp 0x1f968
jmp 0x1f963
jmp 0x1f963
movq %rax, %rbx
jmp 0x1f97a
movq %rax, %rbx
jmp 0x1f987
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6aa2
leaq 0xd0(%rsp), %rdi
callq 0x3230
leaq 0x8(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3490