// File: /workspace/github_cpp_makefile_star2_O2/biotomas[P]ipasir/app/genipareach/genipareach.cpp
// Function: main
int main(int argc, char **argv) {
	puts("c this is a trivial DIMSPEC formula solver.");

	if (argc != 2) {
		puts("c USAGE: ./reachability <dimspec.srt>");
		return 0;
	}

	Formula init,univ,trans, goal;
	loadReachabilityProblem(argv[1], &init, &univ, &goal, &trans);
	printf("c variables in initial %d universal %d goal %d transition %d\n", init.variables, univ.variables, goal.variables, trans.variables);
	printf("c clauses in initial %lu universal %lu goal %lu transition %lu\n", init.clauses.size(), univ.clauses.size(), goal.clauses.size(), trans.clauses.size());
	printf("c Using the incremental SAT solver %s.\n", ipasir_signature());

	int baseVariables = init.variables;
	if (univ.variables != baseVariables || goal.variables != baseVariables || trans.variables != 2*baseVariables) {
		printf("Error: Variable number inconsistency in the input formula.\n");
		return 1;
	}
	vector<int> goalLiterals;
	for (size_t cid = 0; cid < goal.clauses.size(); cid++) {
		if (goal.clauses[cid].size() > 1) {
			printf("Error: only unit goal clauses supported, encode your problem accordingly.\n");
			return 1;
		} else if (goal.clauses[cid].size() > 0) {
			goalLiterals.push_back(goal.clauses[cid][0]);
		}
	}

	void* solver = ipasir_init();
	// Add the initial conditions
	addClauses(solver, init.clauses, 0);

	for (int step = 0;;step++) {
		printf("c running step nr. %d\n", step);
		addClauses(solver, univ.clauses, step*baseVariables);
		if (step > 0) {
			addClauses(solver, trans.clauses, (step-1)*baseVariables);
		}
		assumeLits(solver, goalLiterals, step*baseVariables);
		int res = ipasir_solve(solver);
		if (res == 10) {
			printf("c solved at step nr. %d\n", step);
			break;
		}
	}
	ipasir_release(solver);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xda5e(%rip), %rdi      # 0xf004
callq 0x11f0
cmpl $0x2, %ebp
jne 0x174a
xorps %xmm0, %xmm0
leaq 0xe0(%rsp), %rsi
movaps %xmm0, 0x20(%rsi)
andq $0x0, 0x30(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq 0xa0(%rsp), %rdx
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
andq $0x0, 0x30(%rdx)
movaps %xmm0, (%rdx)
leaq 0x60(%rsp), %r8
movaps %xmm0, 0x20(%r8)
movaps %xmm0, 0x10(%r8)
movaps %xmm0, (%r8)
andq $0x0, 0x30(%r8)
leaq 0x20(%rsp), %rcx
movaps %xmm0, 0x20(%rcx)
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, (%rcx)
andq $0x0, 0x30(%rcx)
movq 0x8(%rbx), %rdi
callq 0x139b
movl 0xe0(%rsp), %esi
movl 0xa0(%rsp), %edx
movl 0x20(%rsp), %ecx
movl 0x60(%rsp), %r8d
leaq 0xda1b(%rip), %rdi      # 0xf056
xorl %eax, %eax
callq 0x1030
movq 0xf0(%rsp), %rax
subq 0xe8(%rsp), %rax
pushq $0x18
popq %r15
cqto
idivq %r15
movq %rax, %rsi
movq 0xb0(%rsp), %rax
subq 0xa8(%rsp), %rax
cqto
idivq %r15
movq %rax, %rcx
movq 0x30(%rsp), %rax
subq 0x28(%rsp), %rax
cqto
idivq %r15
movq %rax, %r8
movq 0x70(%rsp), %rax
subq 0x68(%rsp), %rax
cqto
idivq %r15
leaq 0xd9f6(%rip), %rdi      # 0xf094
movq %rcx, %rdx
movq %r8, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1030
callq 0x1de0
leaq 0xda1a(%rip), %rdi      # 0xf0d4
movq %rax, %rsi
xorl %eax, %eax
callq 0x1030
movl 0xe0(%rsp), %ebx
cmpl %ebx, 0xa0(%rsp)
jne 0x175d
cmpl %ebx, 0x20(%rsp)
jne 0x175d
leal (%rbx,%rbx), %eax
cmpl %eax, 0x60(%rsp)
jne 0x175d
leaq 0xe8(%rsp), %r12
movq %rsp, %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
pushq $0x8
popq %r13
xorl %ebp, %ebp
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
cqto
idivq %r15
cmpq %rax, %rbp
jae 0x1771
movq -0x8(%rcx,%r13), %rsi
movq (%rcx,%r13), %rax
movq %rax, %rcx
subq %rsi, %rcx
cmpq $0x5, %rcx
jae 0x180a
cmpq %rsi, %rax
je 0x1741
movq %r14, %rdi
callq 0x18f8
incq %rbp
addq $0x18, %r13
jmp 0x1704
leaq 0xd8df(%rip), %rdi      # 0xf030
callq 0x11f0
xorl %ebx, %ebx
jmp 0x184f
leaq 0xda2c(%rip), %rdi      # 0xf190
callq 0x11f0
pushq $0x1
popq %rbx
jmp 0x1821
callq 0x1de8
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x149f
movl %ebx, %r12d
negl %r12d
movq %rsp, %r13
xorl %r14d, %r14d
xorl %ebp, %ebp
leaq 0xd961(%rip), %rdi      # 0xf0fc
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
movq %r15, %rdi
leaq 0xa8(%rsp), %rsi
movl %r14d, %edx
callq 0x149f
testl %ebp, %ebp
je 0x17cc
leal (%r12,%r14), %edx
movq %r15, %rdi
leaq 0x68(%rsp), %rsi
callq 0x149f
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x153c
movq %r15, %rdi
callq 0x1e61
cmpl $0xa, %eax
je 0x17ee
incl %ebp
addl %ebx, %r14d
jmp 0x1794
leaq 0xd91e(%rip), %rdi      # 0xf113
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
movq %r15, %rdi
callq 0x1e45
jmp 0x1819
leaq 0xd935(%rip), %rdi      # 0xf146
callq 0x11f0
pushq $0x1
popq %rbx
movq %rsp, %rdi
callq 0x1abe
leaq 0x20(%rsp), %rdi
callq 0x1916
leaq 0x60(%rsp), %rdi
callq 0x1916
leaq 0xa0(%rsp), %rdi
callq 0x1916
leaq 0xe0(%rsp), %rdi
callq 0x1916
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x186e
movq %rax, %rbx
jmp 0x1879
jmp 0x186e
jmp 0x186e
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1abe
leaq 0x20(%rsp), %rdi
callq 0x1916
leaq 0x60(%rsp), %rdi
callq 0x1916
leaq 0xa0(%rsp), %rdi
callq 0x1916
leaq 0xe0(%rsp), %rdi
callq 0x1916
movq %rbx, %rdi
callq 0x1240
nop