// File: /workspace/github_cpp_makefile_star2_O1/biotomas[P]ipasir/app/genipabones/genipabones.cpp
// Function: main
int main(int argc, char **argv) {
	printf("c This program finds back-bones of a CNF SAT formula. A back-bone is assignment fixed in all solutions.\n");
	printf("c You can specify backbone candidates by adding a line starting with 'cvip' followed by variables names separated by space to the cnf file.\n");
	printf("c You can specify a time limit (in seconds) for checking one backbone using the -t parameter.\n");
	printf("c Using the incremental SAT solver %s.\n", ipasir_signature());


	if (argc < 2) {
		puts("USAGE: ./bbones <dimacs.cnf> [-t=<time-limit-per-check>]");
		return 0;
	}

	void *solver = ipasir_init();
	vector<int> boundary;
	int maxVar;
	bool loaded = loadFormula(solver, argv[1], boundary, maxVar);

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

	if (boundary.size() == 0) {
		boundary.clear();
		for (int var = 1; var <= maxVar; var++) {
			boundary.push_back(var);
		}
		printf("c Will check all the variables (%d) for backbones.\n", maxVar);
	} else {
		printf("c Will check %lu candidates for backbones.\n", boundary.size());
	}

	int timelimit = 0;
	if ((argc > 2 && argv[2][1] == 't')) {
		timelimit = atoi(argv[2]+3);
		printf("c Time limit per check is %d seconds\n", timelimit);
		ipasir_set_terminate(solver, NULL, terminateCallback);
		signal(SIGALRM, watchdog);
	}

	int bbonesFound = 0;

	for (size_t i = 0; i < boundary.size(); i++) {
		int candidate = boundary[i];
		printf("c Checking canidate %d, (nr. %lu of %lu)\n", candidate, i+1, boundary.size());
		// check positive case
		ipasir_assume(solver, candidate);
		terminateFlag = 0;
		alarm(timelimit);
		int res = ipasir_solve(solver);
		if (res == 20) {
			bbonesFound++;
			printf("%d 0\n", -candidate);
			continue;
		}
		alarm(0);

		// check negative case
		ipasir_assume(solver, -candidate);
		terminateFlag = 0;
		alarm(timelimit);
		res = ipasir_solve(solver);
		if (res == 20) {
			bbonesFound++;
			printf("%d 0\n", candidate);
		}
		alarm(0);
	}

	printf("c Found %d backbones\n", bbonesFound);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movl %edi, %r12d
leaq 0xe81e(%rip), %rdi      # 0x101a2
callq 0x11d0
leaq 0xe87a(%rip), %rdi      # 0x1020a
callq 0x11d0
leaq 0xe8fa(%rip), %rdi      # 0x10296
callq 0x11d0
callq 0x1d6c
leaq 0xe657(%rip), %rdi      # 0x10004
movq %rax, %rsi
xorl %eax, %eax
callq 0x1030
cmpl $0x1, %r12d
jg 0x19ce
leaq 0xe668(%rip), %rdi      # 0x1002c
callq 0x11d0
jmp 0x1bf5
callq 0x1d74
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq 0x8(%r15), %rsi
leaq 0x34(%rsp), %rcx
movq %rax, %rdi
callq 0x174c
testb %al, %al
je 0x1a1e
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
je 0x1a35
sarq $0x2, %rsi
leaq 0xe6b1(%rip), %rdi      # 0x100c6
xorl %eax, %eax
callq 0x1030
jmp 0x1a97
movq 0x8(%r15), %rsi
leaq 0xe63c(%rip), %rdi      # 0x10065
xorl %eax, %eax
callq 0x1030
jmp 0x1bde
movl 0x34(%rsp), %ebp
movl $0x1, 0xc(%rsp)
testl %ebp, %ebp
jle 0x1a87
movl $0x1, %eax
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r13
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1a6d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x1a78
movq %r14, %rdi
movq %r13, %rdx
callq 0x1c30
movl 0xc(%rsp), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%rsp)
cmpl %ebp, %ecx
jl 0x1a54
leaq 0xe604(%rip), %rdi      # 0x10092
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
xorl %ebp, %ebp
movl $0x0, %r14d
cmpl $0x2, %r12d
je 0x1aed
movq 0x10(%r15), %rdi
cmpb $0x74, 0x1(%rdi)
jne 0x1aed
addq $0x3, %rdi
callq 0x11e0
movl %eax, %r14d
leaq 0xe630(%rip), %rdi      # 0x100f2
movl %eax, %esi
xorl %eax, %eax
callq 0x1030
leaq -0x17b(%rip), %rdx      # 0x1957
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1e14
leaq -0x185(%rip), %rsi      # 0x195e
movl $0xe, %edi
callq 0x1160
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
je 0x1bce
sarq $0x2, %rcx
xorl %r13d, %r13d
xorl %ebp, %ebp
movl (%rax,%r13,4), %r15d
incq %r13
leaq 0xe601(%rip), %rdi      # 0x10118
movl %r15d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1dea
movl $0x0, 0x15603(%rip)     # 0x1713c
movl %r14d, %edi
callq 0x1230
movq %rbx, %rdi
callq 0x1def
movl %r15d, %r12d
negl %r12d
cmpl $0x14, %eax
jne 0x1b69
incl %ebp
leaq 0xf3ca(%rip), %rdi      # 0x10f27
movl %r12d, %esi
xorl %eax, %eax
callq 0x1030
jmp 0x1bb4
xorl %edi, %edi
callq 0x1230
movq %rbx, %rdi
movl %r12d, %esi
callq 0x1dea
movl $0x0, 0x155b7(%rip)     # 0x1713c
movl %r14d, %edi
callq 0x1230
movq %rbx, %rdi
callq 0x1def
cmpl $0x14, %eax
jne 0x1bad
incl %ebp
leaq 0xf384(%rip), %rdi      # 0x10f27
movl %r15d, %esi
xorl %eax, %eax
callq 0x1030
xorl %edi, %edi
callq 0x1230
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r13
jb 0x1b09
leaq 0xe56d(%rip), %rdi      # 0x10142
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1bf5
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1110
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c0e
jmp 0x1c0e
jmp 0x1c0e
jmp 0x1c0e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c28
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1220