// File: /workspace/github_cpp_makefile_star2_O3/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 0xe81b(%rip), %rdi      # 0x101a2
callq 0x11d0
leaq 0xe877(%rip), %rdi      # 0x1020a
callq 0x11d0
leaq 0xe8f7(%rip), %rdi      # 0x10296
callq 0x11d0
callq 0x1d70
leaq 0xe654(%rip), %rdi      # 0x10004
movq %rax, %rsi
xorl %eax, %eax
callq 0x1030
cmpl $0x1, %r12d
jg 0x19d1
leaq 0xe665(%rip), %rdi      # 0x1002c
callq 0x11d0
jmp 0x1bf8
callq 0x1d78
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 0x1a21
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
je 0x1a38
sarq $0x2, %rsi
leaq 0xe6ae(%rip), %rdi      # 0x100c6
xorl %eax, %eax
callq 0x1030
jmp 0x1a9a
movq 0x8(%r15), %rsi
leaq 0xe639(%rip), %rdi      # 0x10065
xorl %eax, %eax
callq 0x1030
jmp 0x1be1
movl 0x34(%rsp), %ebp
movl $0x1, 0xc(%rsp)
testl %ebp, %ebp
jle 0x1a8a
movl $0x1, %eax
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r13
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1a70
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x1a7b
movq %r14, %rdi
movq %r13, %rdx
callq 0x1c34
movl 0xc(%rsp), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%rsp)
cmpl %ebp, %ecx
jl 0x1a57
leaq 0xe601(%rip), %rdi      # 0x10092
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
xorl %ebp, %ebp
movl $0x0, %r14d
cmpl $0x2, %r12d
je 0x1af0
movq 0x10(%r15), %rdi
cmpb $0x74, 0x1(%rdi)
jne 0x1af0
addq $0x3, %rdi
callq 0x11e0
movl %eax, %r14d
leaq 0xe62d(%rip), %rdi      # 0x100f2
movl %eax, %esi
xorl %eax, %eax
callq 0x1030
leaq -0x17b(%rip), %rdx      # 0x195a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1e18
leaq -0x185(%rip), %rsi      # 0x1961
movl $0xe, %edi
callq 0x1160
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
je 0x1bd1
sarq $0x2, %rcx
xorl %r13d, %r13d
xorl %ebp, %ebp
movl (%rax,%r13,4), %r15d
incq %r13
leaq 0xe5fe(%rip), %rdi      # 0x10118
movl %r15d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1030
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1dee
movl $0x0, 0x15600(%rip)     # 0x1713c
movl %r14d, %edi
callq 0x1230
movq %rbx, %rdi
callq 0x1df3
movl %r15d, %r12d
negl %r12d
cmpl $0x14, %eax
jne 0x1b6c
incl %ebp
leaq 0xf3d7(%rip), %rdi      # 0x10f37
movl %r12d, %esi
xorl %eax, %eax
callq 0x1030
jmp 0x1bb7
xorl %edi, %edi
callq 0x1230
movq %rbx, %rdi
movl %r12d, %esi
callq 0x1dee
movl $0x0, 0x155b4(%rip)     # 0x1713c
movl %r14d, %edi
callq 0x1230
movq %rbx, %rdi
callq 0x1df3
cmpl $0x14, %eax
jne 0x1bb0
incl %ebp
leaq 0xf391(%rip), %rdi      # 0x10f37
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 0x1b0c
leaq 0xe56a(%rip), %rdi      # 0x10142
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1bf8
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 0x1c11
jmp 0x1c11
jmp 0x1c11
jmp 0x1c11
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c2b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1220
nop