// File: /workspace/github_cpp_makefile_star2_O1/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 -0x9d0(%rip), %rsi      # 0x299b
movl $0xf, %edi
callq 0x21d0
leaq 0xedbb(%rip), %rdi      # 0x12137
callq 0x2260
leaq 0xeddc(%rip), %rdi      # 0x12164
callq 0x2260
callq 0x3c2c
leaq 0xedf2(%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 0x33da
movq 0x10(%rbx), %rdi
callq 0x2270
movl %eax, %r15d
movq 0x18(%rbx), %rdi
callq 0x2270
movl %eax, %ebx
jmp 0x33de
movl 0x8(%rsp), %ebx
leaq 0xedbf(%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 0x3055
movl 0x4(%rsp), %r12d
movl (%rsp), %ebp
testl %r12d, %r12d
jle 0x354a
leaq 0xedb6(%rip), %rdi      # 0x121d6
movl %r12d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x28bb
callq 0x3c34
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x3ca5
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0x3ca5
movl %r12d, 0x15d45(%rip)    # 0x19198
movl %r12d, 0x15d42(%rip)    # 0x1919c
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x30e0
testl %r15d, %r15d
je 0x3480
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x31d5
incl %r15d
cmpl 0x15d12(%rip), %r15d    # 0x1919c
jl 0x345f
movl 0x15d0a(%rip), %edx     # 0x1919c
cmpl %ebp, %edx
jge 0x353b
leaq 0x8(%rsp), %r15
leaq 0xedae(%rip), %r12      # 0x12254
leaq 0xedea(%rip), %r13      # 0x12297
movq %r14, %rdi
movq %r15, %rsi
callq 0x30e0
movl 0x15cde(%rip), %edx     # 0x1919c
movq %r14, %rdi
movq %r15, %rsi
callq 0x31d5
movl 0x8(%rsp), %esi
imull 0x15cc8(%rip), %esi     # 0x1919c
addl %ebx, %esi
movq %r14, %rdi
callq 0x3caa
movl 0x15cb8(%rip), %esi     # 0x1919c
incl %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x28bb
movq %r14, %rdi
callq 0x3caf
cmpl $0xa, %eax
jne 0x351b
leaq 0xed81(%rip), %rdi      # 0x12285
xorl %eax, %eax
callq 0x28bb
movl 0x15c8b(%rip), %eax     # 0x1919c
incl %eax
movl %eax, 0x15c7f(%rip)     # 0x19198
jmp 0x3525
movq %r13, %rdi
xorl %eax, %eax
callq 0x28bb
movl 0x15c71(%rip), %edx     # 0x1919c
incl %edx
movl %edx, 0x15c69(%rip)     # 0x1919c
cmpl %ebp, %edx
jl 0x34ad
movl 0x15c57(%rip), %esi     # 0x19198
leaq 0xed69(%rip), %rdi      # 0x122b1
jmp 0x3553
leaq 0xecbb(%rip), %rdi      # 0x1220c
movl %ebp, %esi
xorl %eax, %eax
callq 0x28bb
leaq 0x10(%rsp), %rdi
callq 0x35fc
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x357d
jmp 0x357d
jmp 0x357d
jmp 0x357d
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x35fc
movq %rbx, %rdi
callq 0x22d0