// File: /workspace/github_cpp_makefile_star2_O2/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 -0x7c7(%rip), %rsi      # 0x251e
pushq $0xf
popq %rdi
callq 0x21d0
leaq 0xd443(%rip), %rdi      # 0x10137
callq 0x2260
leaq 0xd464(%rip), %rdi      # 0x10164
callq 0x2260
callq 0x36c8
leaq 0xd47a(%rip), %rdi      # 0x1018b
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %r15
movl %r15d, %edx
callq 0x2541
cmpl $0x4, %ebp
jne 0x2d4e
movq 0x10(%rbx), %rdi
callq 0x2270
movl %eax, %r15d
movq 0x18(%rbx), %rdi
callq 0x2270
movl %eax, %ebx
jmp 0x2d52
movl 0x8(%rsp), %ebx
leaq 0xd44b(%rip), %rdi      # 0x101a4
movl %r15d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x246b
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
movl %r15d, %esi
movl %ebx, %edx
callq 0x2a88
movl 0x4(%rsp), %r13d
movl (%rsp), %ebp
testl %r13d, %r13d
jle 0x2eb7
leaq 0xd442(%rip), %rdi      # 0x101d6
movl %r13d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x246b
callq 0x36d0
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %edx
callq 0x2af0
movl %r13d, 0x143de(%rip)    # 0x17198
movl %r13d, 0x143db(%rip)    # 0x1719c
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
cmpl %r13d, %r15d
jge 0x2dfb
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x2b11
testl %r15d, %r15d
je 0x2def
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x2bac
incl %r15d
movl 0x143a3(%rip), %r13d    # 0x1719c
jmp 0x2dc9
leaq 0x8(%rsp), %r15
leaq 0xd44d(%rip), %r12      # 0x10254
cmpl %ebp, %r13d
jge 0x2ea8
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x2b11
movl 0x14378(%rip), %edx     # 0x1719c
movq %r14, %rdi
movq %r15, %rsi
callq 0x2bac
movl 0x8(%rsp), %esi
imull 0x14362(%rip), %esi     # 0x1719c
addl %ebx, %esi
movq %r14, %rdi
callq 0x3744
movl 0x14352(%rip), %esi     # 0x1719c
incl %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x246b
movq %r14, %rdi
callq 0x3749
cmpl $0xa, %eax
jne 0x2e84
leaq 0xd41b(%rip), %rdi      # 0x10285
xorl %eax, %eax
callq 0x246b
movl 0x14324(%rip), %r13d    # 0x1719c
incl %r13d
movl %r13d, 0x14316(%rip)    # 0x17198
jmp 0x2e9c
leaq 0xd40c(%rip), %rdi      # 0x10297
xorl %eax, %eax
callq 0x246b
movl 0x14303(%rip), %r13d    # 0x1719c
incl %r13d
movl %r13d, 0x142f9(%rip)    # 0x1719c
jmp 0x2e07
movl 0x142ea(%rip), %esi     # 0x17198
leaq 0xd3fc(%rip), %rdi      # 0x102b1
jmp 0x2ec0
leaq 0xd34e(%rip), %rdi      # 0x1020c
movl %ebp, %esi
xorl %eax, %eax
callq 0x246b
leaq 0x10(%rsp), %rdi
callq 0x2f54
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2eea
jmp 0x2eea
jmp 0x2eea
jmp 0x2eea
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2f54
movq %rbx, %rdi
callq 0x22d0
nop