// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x2370
movq %rax, %rsi
leaq 0x18a38(%rip), %rdi     # 0x1a010
movb $0x0, %al
callq 0x1030
cmpl $0x2, -0x8(%rbp)
je 0x15fd
leaq 0x18a4a(%rip), %rdi     # 0x1a036
callq 0x11f0
movl $0x0, -0x4(%rbp)
jmp 0x188f
leaq 0x18a59(%rip), %rdi     # 0x1a05d
callq 0x11f0
leaq 0x18a8e(%rip), %rdi     # 0x1a09e
callq 0x11f0
leaq 0x18ac9(%rip), %rdi     # 0x1a0e5
callq 0x11f0
leaq 0x18b08(%rip), %rdi     # 0x1a130
callq 0x11f0
callq 0x2380
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3, %edx
leaq -0x10a(%rip), %rcx      # 0x1540
callq 0x2560
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x1380
andb $0x1, %al
movb %al, -0x1d(%rbp)
testb $0x1, -0x1d(%rbp)
jne 0x1698
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x18af8(%rip), %rdi     # 0x1a17d
movb $0x0, %al
callq 0x1030
movl $0x0, -0x4(%rbp)
jmp 0x188f
movq -0x18(%rbp), %rdi
callq 0x2480
movl %eax, -0x24(%rbp)
cmpl $0x14, -0x24(%rbp)
jne 0x16c2
leaq 0x18af9(%rip), %rdi     # 0x1a1aa
callq 0x11f0
movl $0x0, -0x4(%rbp)
jmp 0x188f
leaq -0x40(%rbp), %rdi
callq 0x18b0
movl $0x1, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x17b1
movl -0x44(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq 0x18ae3(%rip), %rdi     # 0x1a1ce
xorl %eax, %eax
callq 0x1030
jmp 0x16f4
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %edi
callq 0x1340
movq -0x68(%rbp), %rdi
movl %eax, %esi
negl %esi
callq 0x2450
jmp 0x1713
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x44(%rbp), %edi
negl %edi
callq 0x1340
movq -0x70(%rbp), %rdi
movl %eax, %esi
negl %esi
callq 0x2450
jmp 0x1734
movq -0x18(%rbp), %rdi
callq 0x2480
movl %eax, -0x74(%rbp)
jmp 0x1742
movl -0x74(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0xa, -0x24(%rbp)
jne 0x177d
movl -0x44(%rbp), %esi
leaq 0x18abb(%rip), %rdi     # 0x1a213
xorl %eax, %eax
callq 0x1030
jmp 0x1761
jmp 0x17a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1980
jmp 0x189b
movl -0x44(%rbp), %esi
leaq 0x18abe(%rip), %rdi     # 0x1a245
xorl %eax, %eax
callq 0x1030
jmp 0x1790
leaq -0x40(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x18d0
jmp 0x179f
jmp 0x17a1
jmp 0x17a3
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x16d2
leaq -0x40(%rbp), %rdi
callq 0x1940
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %esi
movl -0x1c(%rbp), %edx
cvtsi2sd %esi, %xmm0
movsd 0x18839(%rip), %xmm1    # 0x1a008
mulsd %xmm1, %xmm0
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
leaq 0x18a91(%rip), %rdi     # 0x1a273
movb $0x1, %al
callq 0x1030
jmp 0x17eb
leaq 0x18acc(%rip), %rdi     # 0x1a2be
callq 0x11f0
jmp 0x17f9
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1940
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x184d
movq -0x60(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1960
movl (%rax), %esi
leaq 0x18abe(%rip), %rdi     # 0x1a2f2
xorl %eax, %eax
callq 0x1030
jmp 0x183d
jmp 0x183f
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1801
leaq 0x196bb(%rip), %rdi     # 0x1af0f
xorl %eax, %eax
callq 0x1030
jmp 0x185d
movl 0x208e1(%rip), %esi     # 0x22144
movl 0x208df(%rip), %edx     # 0x22148
movl 0x208dd(%rip), %ecx     # 0x2214c
leaq 0x18a80(%rip), %rdi     # 0x1a2f6
xorl %eax, %eax
callq 0x1030
jmp 0x187f
movl $0x0, -0x4(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1980
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x1230
nopw %cs:(%rax,%rax)
nop