// File: /workspace/github_cpp_makefile_star2_O3/biotomas[P]ipasir/app/genipalsp/genipalsp.cpp
// Function: main
int main(int argc, char **argv) {
	signal(SIGTERM, signalHandler);
	puts("Usage: ./lsp <graph-file> [<start>] [<goal>]");
	puts("       default start=1, goal=#vertices");
	printf("Using the SAT solver %s\n", ipasir_signature());
	Graph g = loadGraph(argv[1], true);
	int start = 1;
	int goal = g.verticesCount;
	if (argc == 4) {
		start = atoi(argv[2]);
		goal = atoi(argv[3]);
	}
	log("INFO: searching for a longest path from %d to %d\n", start, goal);

	int lb, ub;
	getLowerUpperBound(g, start, goal, lb, ub);
	if (lb > 0) {
		log("INFO: DFS found path of length %d, upper bound is %d\n", lb, ub);
	} else {
		log("INFO: no path between start and goal, %d reachable vertices from start\n", ub);
		return 0;
	}

	void* solver = ipasir_init();
	addInitalCondition(solver, g, start);
	best = lb;
	pathLength = lb;
	for (int i = 0; i < pathLength; i++) {
		addUniversalConditions(solver, g, i);
		if (i > 0) {
			addTransitionalConditions(solver, g, i);
		}
	}

	while (pathLength < ub) {
		addUniversalConditions(solver, g, pathLength);
		addTransitionalConditions(solver, g, pathLength);
		assumeGoalCondition(solver, g, goal, pathLength);
		log("INFO: trying to find a path of length %d by SAT\n", pathLength+1);
		int res = ipasir_solve(solver);
		if (res == 10) {
			log(" :-) path found!\n");
			best = pathLength+1;
		} else {
			log(" :-( path does not exist\n");
		}
		pathLength++;
	}
	log("RES: Longest path has %d vertices.\n", best);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq -0x9f5(%rip), %rsi      # 0x299b
movl $0xf, %edi
callq 0x21d0
leaq 0xed96(%rip), %rdi      # 0x12137
callq 0x2260
leaq 0xedb7(%rip), %rdi      # 0x12164
callq 0x2260
callq 0x3c3c
leaq 0xedcd(%rip), %rdi      # 0x1218b
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %rdi
movl $0x1, %r15d
movl $0x1, %edx
callq 0x29be
cmpl $0x4, %ebp
jne 0x33ff
movq 0x10(%rbx), %rdi
callq 0x2270
movl %eax, %r15d
movq 0x18(%rbx), %rdi
callq 0x2270
movl %eax, %ebx
jmp 0x3403
movl 0x8(%rsp), %ebx
leaq 0xed9a(%rip), %rdi      # 0x121a4
movl %r15d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x28bb
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
movl %r15d, %esi
movl %ebx, %edx
callq 0x3052
movl 0x4(%rsp), %r12d
movl (%rsp), %ebp
testl %r12d, %r12d
jle 0x356b
leaq 0xed91(%rip), %rdi      # 0x121d6
movl %r12d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x28bb
callq 0x3c44
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x3cb5
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0x3cb5
movl %r12d, 0x15d20(%rip)    # 0x19198
movl %r12d, 0x15d1d(%rip)    # 0x1919c
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x30db
testl %r15d, %r15d
je 0x34a5
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x31fa
incl %r15d
movl 0x15cee(%rip), %edx     # 0x1919c
cmpl %edx, %r15d
jl 0x3484
cmpl %ebp, %edx
jge 0x355c
leaq 0x8(%rsp), %r15
leaq 0xed8d(%rip), %r12      # 0x12254
leaq 0xedc9(%rip), %r13      # 0x12297
movq %r14, %rdi
movq %r15, %rsi
callq 0x30db
movl 0x15cbd(%rip), %edx     # 0x1919c
movq %r14, %rdi
movq %r15, %rsi
callq 0x31fa
movl 0x8(%rsp), %esi
imull 0x15ca7(%rip), %esi     # 0x1919c
addl %ebx, %esi
movq %r14, %rdi
callq 0x3cba
movl 0x15c97(%rip), %esi     # 0x1919c
incl %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x28bb
movq %r14, %rdi
callq 0x3cbf
cmpl $0xa, %eax
jne 0x353c
leaq 0xed60(%rip), %rdi      # 0x12285
xorl %eax, %eax
callq 0x28bb
movl 0x15c6a(%rip), %edx     # 0x1919c
incl %edx
movl %edx, 0x15c5e(%rip)     # 0x19198
jmp 0x354e
movq %r13, %rdi
xorl %eax, %eax
callq 0x28bb
movl 0x15c50(%rip), %edx     # 0x1919c
incl %edx
movl %edx, 0x15c48(%rip)     # 0x1919c
cmpl %ebp, %edx
jl 0x34ce
movl 0x15c36(%rip), %esi     # 0x19198
leaq 0xed48(%rip), %rdi      # 0x122b1
jmp 0x3574
leaq 0xec9a(%rip), %rdi      # 0x1220c
movl %ebp, %esi
xorl %eax, %eax
callq 0x28bb
leaq 0x10(%rsp), %rdi
callq 0x3620
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x359e
jmp 0x359e
jmp 0x359e
jmp 0x359e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3620
movq %rbx, %rdi
callq 0x22d0
nop