// File: /workspace/github_cpp_makefile_star2_O2/biotomas[P]ipasir/app/genipaessentials/genipaessentials.cpp
// Function: main
int main(int argc, char **argv) {
	printf("Using the incremental SAT solver %s.\n", ipasir_signature());

	if (argc != 2) {
		puts("USAGE: ./genipaessentials <dimacs.cnf>");
		return 0;
	}

	puts("Given a satisfiable formula F and a variable x, we say that x is");
	puts("essential for the satisfiability of F if a truth value (True or False)");
	puts("must be assigned to x in each satisfying assignment of F. This application");
	puts("finds all the variables essential for the satisfiability of a given formula.");

	void *solver = ipasir_init();
	ipasir_set_learn(solver, NULL, 3, learnCb);
	int variables = 0;
	bool loaded = loadFormulaDualRailed(solver, argv[1], &variables);

	if (!loaded) {
		printf("The input formula \"%s\" could not be loaded.\n", argv[1]);
		return 0;
	}

	int satRes = ipasir_solve(solver);

	if (satRes == 20) {
		puts("The input formula is unsatisfiable.");
		return 0;
	}

	std::vector<int> essentialVariables;
	for (int var = 1; var <= variables; var++) {
		printf("Testing if variable %d (out of %d) is essential for satisfiability.\n", var, variables);
		ipasir_assume(solver, -getDualRailName(var));
		ipasir_assume(solver, -getDualRailName(-var));
		satRes = ipasir_solve(solver);
		if (satRes == 10) {
			printf("Variable %d IS NOT essential for satisfiability.\n", var);
		} else {
			printf("Variable %d IS essential for satisfiability.\n", var);
			essentialVariables.push_back(var);
		}
	}
	int essentials = (int)essentialVariables.size();
	printf("SUMMARY: %d of %d (%0.2f%%) of variables is essential for satisfiability.\n",
			essentials, variables, 100.0*essentials/variables);
	puts("The list of variables eseential for satisfiability:");
	for (size_t i = 0; i < essentialVariables.size(); i++) {
		printf("%d ", essentialVariables[i]);
	}
	printf("\n");
	printf("The solver shared %d unit, %d binary and %d ternary clauses.\n", lunits, lbins, lterns);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebx
callq 0x18e0
leaq 0xcb12(%rip), %rdi      # 0xe010
movq %rax, %rsi
xorl %eax, %eax
callq 0x1030
cmpl $0x2, %ebx
jne 0x1587
leaq 0xcb49(%rip), %rdi      # 0xe05d
callq 0x11f0
leaq 0xcb7e(%rip), %rdi      # 0xe09e
callq 0x11f0
leaq 0xcbb9(%rip), %rdi      # 0xe0e5
callq 0x11f0
leaq 0xcbf8(%rip), %rdi      # 0xe130
callq 0x11f0
callq 0x18e8
movq %rax, %rbx
leaq -0xa1(%rip), %rcx       # 0x14ab
pushq $0x3
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1989
leaq 0xc(%rsp), %rdx
andl $0x0, (%rdx)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x1350
testb %al, %al
je 0x1598
movq %rbx, %rdi
callq 0x1961
cmpl $0x14, %eax
jne 0x15af
leaq 0xcc25(%rip), %rdi      # 0xe1aa
jmp 0x158e
leaq 0xcaa8(%rip), %rdi      # 0xe036
callq 0x11f0
jmp 0x1719
movq 0x8(%r14), %rsi
leaq 0xcbda(%rip), %rdi      # 0xe17d
xorl %eax, %eax
callq 0x1030
jmp 0x1719
leaq 0x10(%rsp), %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
pushq $0x1
popq %rsi
movl 0xc(%rsp), %ebp
leaq 0xcc00(%rip), %r15      # 0xe1ce
leaq 0xcc70(%rip), %r13      # 0xe245
leaq 0x8(%rsp), %r12
movl %esi, 0x8(%rsp)
cmpl %ebp, %esi
jg 0x1676
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1030
movl 0x8(%rsp), %eax
xorl %esi, %esi
testl %eax, %eax
setle %sil
leal (%rax,%rax), %ecx
negl %esi
xorl %ecx, %esi
testl %eax, %eax
cmovel %eax, %esi
negl %esi
movq %rbx, %rdi
callq 0x195c
movl 0x8(%rsp), %eax
leal (%rax,%rax), %ecx
negl %ecx
movl %eax, %esi
notl %esi
sarl $0x1f, %esi
xorl %ecx, %esi
testl %eax, %eax
cmovel %eax, %esi
negl %esi
movq %rbx, %rdi
callq 0x195c
movq %rbx, %rdi
callq 0x1961
movl 0x8(%rsp), %esi
cmpl $0xa, %eax
jne 0x1656
leaq 0xcbc6(%rip), %rdi      # 0xe213
xorl %eax, %eax
callq 0x1030
jmp 0x166b
movq %r13, %rdi
xorl %eax, %eax
callq 0x1030
movq %r14, %rdi
movq %r12, %rsi
callq 0x1740
movl 0x8(%rsp), %esi
incl %esi
jmp 0x15da
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
shrq $0x2, %rsi
cvtsi2sd %esi, %xmm0
mulsd 0xc978(%rip), %xmm0     # 0xe008
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
leaq 0xcbd4(%rip), %rdi      # 0xe273
movl %ebp, %edx
movb $0x1, %al
callq 0x1030
leaq 0xcc0f(%rip), %rdi      # 0xe2be
callq 0x11f0
leaq 0xcc37(%rip), %rbx      # 0xe2f2
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r14
jae 0x16e7
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1030
incq %r14
jmp 0x16be
pushq $0xa
popq %rdi
callq 0x11d0
movl 0x13a47(%rip), %esi     # 0x1513c
movl 0x13a45(%rip), %edx     # 0x15140
movl 0x13a43(%rip), %ecx     # 0x15144
leaq 0xcbee(%rip), %rdi      # 0xe2f6
xorl %eax, %eax
callq 0x1030
leaq 0x10(%rsp), %rdi
callq 0x176a
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x176a
movq %rbx, %rdi
callq 0x1230
nop