// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xf, %edi
leaq -0xcc2(%rip), %rsi      # 0x2540
callq 0x21d0
leaq 0x1af19(%rip), %rdi     # 0x1e127
callq 0x2260
leaq 0x1af3a(%rip), %rdi     # 0x1e154
callq 0x2260
callq 0x64a0
movq %rax, %rsi
leaq 0x1af4d(%rip), %rdi     # 0x1e17b
movb $0x0, %al
callq 0x2030
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x30(%rbp), %rdi
movl $0x1, %edx
callq 0x2580
movl $0x1, -0x34(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x4, -0x8(%rbp)
jne 0x327e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2270
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2270
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
leaq 0x1af09(%rip), %rdi     # 0x1e194
xorl %eax, %eax
callq 0x2480
jmp 0x3294
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rcx
leaq -0x4c(%rbp), %r8
callq 0x2e80
jmp 0x32ad
cmpl $0x0, -0x48(%rbp)
jle 0x32e5
movl -0x48(%rbp), %esi
movl -0x4c(%rbp), %edx
leaq 0x1af06(%rip), %rdi     # 0x1e1c6
xorl %eax, %eax
callq 0x2480
jmp 0x32c9
jmp 0x330b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x35f0
jmp 0x348f
movl -0x4c(%rbp), %esi
leaq 0x1af0d(%rip), %rdi     # 0x1e1fc
xorl %eax, %eax
callq 0x2480
jmp 0x32f8
movl $0x0, -0x4(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x347d
callq 0x64b0
movq %rax, -0x68(%rbp)
jmp 0x3316
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq -0x30(%rbp), %rsi
callq 0x2f00
jmp 0x3330
movl -0x48(%rbp), %eax
movl %eax, 0x23e67(%rip)     # 0x271a0
movl -0x48(%rbp), %eax
movl %eax, 0x23e62(%rip)     # 0x271a4
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl 0x23e52(%rip), %eax     # 0x271a4
jge 0x338d
movq -0x58(%rbp), %rdi
movl -0x5c(%rbp), %edx
leaq -0x30(%rbp), %rsi
callq 0x2f90
jmp 0x3366
cmpl $0x0, -0x5c(%rbp)
jle 0x3380
movq -0x58(%rbp), %rdi
movl -0x5c(%rbp), %edx
leaq -0x30(%rbp), %rsi
callq 0x3060
jmp 0x337e
jmp 0x3380
jmp 0x3382
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x3349
jmp 0x338f
movl 0x23e0f(%rip), %eax     # 0x271a4
cmpl -0x4c(%rbp), %eax
jge 0x3459
movq -0x58(%rbp), %rdi
movl 0x23dfc(%rip), %edx     # 0x271a4
leaq -0x30(%rbp), %rsi
callq 0x2f90
jmp 0x33b3
movq -0x58(%rbp), %rdi
movl 0x23de7(%rip), %edx     # 0x271a4
leaq -0x30(%rbp), %rsi
callq 0x3060
jmp 0x33c8
movq -0x58(%rbp), %rdi
movl -0x38(%rbp), %edx
movl 0x23dcf(%rip), %ecx     # 0x271a4
leaq -0x30(%rbp), %rsi
callq 0x2f50
jmp 0x33e0
movl 0x23dbe(%rip), %esi     # 0x271a4
incl %esi
leaq 0x1ae55(%rip), %rdi     # 0x1e244
xorl %eax, %eax
callq 0x2480
jmp 0x33f8
movq -0x58(%rbp), %rdi
callq 0x65b0
movl %eax, -0x6c(%rbp)
jmp 0x3406
movl -0x6c(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0xa, -0x60(%rbp)
jne 0x3433
leaq 0x1ae5c(%rip), %rdi     # 0x1e275
xorl %eax, %eax
callq 0x2480
jmp 0x3422
movl 0x23d7c(%rip), %eax     # 0x271a4
addl $0x1, %eax
movl %eax, 0x23d6f(%rip)     # 0x271a0
jmp 0x3445
leaq 0x1ae4d(%rip), %rdi     # 0x1e287
xorl %eax, %eax
callq 0x2480
jmp 0x3443
jmp 0x3445
movl 0x23d59(%rip), %eax     # 0x271a4
addl $0x1, %eax
movl %eax, 0x23d50(%rip)     # 0x271a4
jmp 0x338f
movl 0x23d41(%rip), %esi     # 0x271a0
leaq 0x1ae3b(%rip), %rdi     # 0x1e2a1
xorl %eax, %eax
callq 0x2480
jmp 0x346f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x35f0
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x22d0
nopl (%rax,%rax)