// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x1a8e9(%rip), %rdi     # 0x1c059
callq 0x1200
cmpl $0x2, -0x8(%rbp)
je 0x1793
leaq 0x1a903(%rip), %rdi     # 0x1c085
callq 0x1200
movl $0x0, -0x4(%rbp)
jmp 0x1c19
leaq -0x48(%rbp), %rdi
callq 0x1d30
leaq -0x80(%rbp), %rdi
callq 0x1d30
jmp 0x17a7
leaq -0xc8(%rbp), %rdi
callq 0x1d30
jmp 0x17b5
leaq -0x100(%rbp), %rdi
callq 0x1d30
jmp 0x17c3
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0xc8(%rbp), %r8
callq 0x1410
jmp 0x17e8
movl -0x48(%rbp), %esi
movl -0x80(%rbp), %edx
movl -0x100(%rbp), %ecx
movl -0xc8(%rbp), %r8d
leaq 0x1a8a9(%rip), %rdi     # 0x1c0ab
xorl %eax, %eax
callq 0x1030
jmp 0x180b
leaq -0x40(%rbp), %rdi
callq 0x1ca0
movq %rax, -0x150(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x1ca0
movq %rax, -0x148(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x1ca0
movq %rax, -0x140(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x1ca0
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rcx
movq %rax, %r8
leaq 0x1a880(%rip), %rdi     # 0x1c0e9
xorl %eax, %eax
callq 0x1030
jmp 0x1872
callq 0x3bd0
movq %rax, -0x158(%rbp)
jmp 0x1880
movq -0x158(%rbp), %rsi
leaq 0x1a89b(%rip), %rdi     # 0x1c129
xorl %eax, %eax
callq 0x1030
jmp 0x1897
movl -0x48(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x104(%rbp), %eax
jne 0x18cf
movl -0x100(%rbp), %eax
cmpl -0x104(%rbp), %eax
jne 0x18cf
movl -0xc8(%rbp), %eax
movl -0x104(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
je 0x1951
leaq 0x1a87b(%rip), %rdi     # 0x1c151
xorl %eax, %eax
callq 0x1030
jmp 0x18df
movl $0x1, -0x4(%rbp)
movl $0x1, -0x108(%rbp)
jmp 0x1bc1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1c0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1c05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1bf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1bed
leaq -0x120(%rbp), %rdi
callq 0x1d70
movq $0x0, -0x128(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x100(%rbp), %rdi
addq $0x8, %rdi
callq 0x1ca0
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jae 0x1a79
leaq -0x100(%rbp), %rdi
addq $0x8, %rdi
movq -0x128(%rbp), %rsi
callq 0x1d90
movq %rax, %rdi
callq 0x1cf0
cmpq $0x1, %rax
jbe 0x1a07
leaq 0x1a7c8(%rip), %rdi     # 0x1c18d
xorl %eax, %eax
callq 0x1030
jmp 0x19ce
movl $0x1, -0x4(%rbp)
movl $0x1, -0x108(%rbp)
jmp 0x1bb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x1e40
jmp 0x1bed
leaq -0x100(%rbp), %rdi
addq $0x8, %rdi
movq -0x128(%rbp), %rsi
callq 0x1d90
movq %rax, %rdi
callq 0x1cf0
cmpq $0x0, %rax
jbe 0x1a5e
leaq -0xf8(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x1d90
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1e20
movq %rax, %rsi
leaq -0x120(%rbp), %rdi
callq 0x1db0
jmp 0x1a5c
jmp 0x1a5e
jmp 0x1a60
jmp 0x1a62
movq -0x128(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
jmp 0x1968
callq 0x3be0
movq %rax, -0x168(%rbp)
jmp 0x1a87
movq -0x168(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0x15b0
jmp 0x1aa9
movl $0x0, -0x134(%rbp)
movl -0x134(%rbp), %esi
leaq 0x1a718(%rip), %rdi     # 0x1c1d8
xorl %eax, %eax
callq 0x1030
jmp 0x1ac9
movq -0x130(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl -0x134(%rbp), %edx
movl -0x104(%rbp), %eax
imull %eax, %edx
callq 0x15b0
jmp 0x1aea
cmpl $0x0, -0x134(%rbp)
jle 0x1b1b
movq -0x130(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl -0x134(%rbp), %edx
decl %edx
movl -0x104(%rbp), %eax
imull %eax, %edx
callq 0x15b0
jmp 0x1b19
jmp 0x1b1b
movq -0x130(%rbp), %rdi
movl -0x134(%rbp), %edx
movl -0x104(%rbp), %eax
imull %eax, %edx
leaq -0x120(%rbp), %rsi
callq 0x16c0
jmp 0x1b3f
movq -0x130(%rbp), %rdi
callq 0x3ce0
movl %eax, -0x16c(%rbp)
jmp 0x1b53
movl -0x16c(%rbp), %eax
movl %eax, -0x138(%rbp)
cmpl $0xa, -0x138(%rbp)
jne 0x1b80
movl -0x134(%rbp), %esi
leaq 0x1a67a(%rip), %rdi     # 0x1c1ef
xorl %eax, %eax
callq 0x1030
jmp 0x1b7e
jmp 0x1b96
jmp 0x1b82
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x1ab3
movq -0x130(%rbp), %rdi
callq 0x3c50
jmp 0x1ba4
movl $0x0, -0x4(%rbp)
movl $0x1, -0x108(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x1e40
leaq -0x100(%rbp), %rdi
callq 0x1ea0
leaq -0xc8(%rbp), %rdi
callq 0x1ea0
leaq -0x80(%rbp), %rdi
callq 0x1ea0
leaq -0x48(%rbp), %rdi
callq 0x1ea0
jmp 0x1c19
leaq -0x100(%rbp), %rdi
callq 0x1ea0
leaq -0xc8(%rbp), %rdi
callq 0x1ea0
leaq -0x80(%rbp), %rdi
callq 0x1ea0
leaq -0x48(%rbp), %rdi
callq 0x1ea0
jmp 0x1c25
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x1250
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)