// File: /workspace/github_c_makefile_star2_O2/TurkeyMcMac[P]ts3d/src/main.c
// Function: main
int main(int argc, char *argv[])
{
	// 0 for EXIT_SUCCESS, -1 for EXIT_FAILURE:
	int ret = -1;
	// Indicates option parsing error:
	bool error = false;
	// Program name from invokation:
	const char *progname = argc > 0 ? argv[0] : "ts3d";
	// Data directory path, NULL for default:
	char *data_dir = NULL;
	// State file path, NULL for default:
	char *state_file = NULL;
	// Logger to be used by do_ts3d_game:
	struct logger log;
	// Default log destination file path, NULL until initialized:
	char *log_name_def = NULL;
	// Default log destination file, NULL until initialized:
	FILE *log_def = NULL;
	int opt;
	logger_init(&log);
	logger_set_output(&log, LOGGER_ALL, UNTOUCHED_MARKER, false);
	while ((opt = getopt(argc, argv, "d:hl:L:s:v")) >= 0) {
		switch (opt) {
		case 'd':
			free(data_dir);
			data_dir = str_dup(optarg);
			break;
		case 'h':
			print_help(progname);
			ret = 0;
			goto end;
		case 'l':
			if (add_log_dest(progname, &log, optarg)) goto end;
			break;
		case 'L':
			if (remove_log_dest(progname, &log, optarg)) goto end;
			break;
		case 's':
			free(state_file);
			state_file = str_dup(optarg);
			break;
		case 'v':
			print_version(progname);
			ret = 0;
			goto end;
		default:
			error = true;
			break;
		}
	}
	if (error) {
		print_usage(progname, stderr);
		goto end;
	}
	if (!data_dir) data_dir = default_file("data", "TS3D_DATA");
	if (!data_dir || ensure_file(data_dir, true)) {
		fprintf(stderr,
			"%s: No suitable \"data\" directory available: %s\n",
			progname, strerror(errno));
		goto end;
	}
	if (!state_file) state_file = default_file("state.json", "TS3D_STATE");
	if (!state_file || ensure_file(state_file, false)) {
		fprintf(stderr,
			"%s: No suitable \"state.json\" file available: %s\n",
			progname, strerror(errno));
		goto end;
	}
	if ((log_name_def = default_file("log", "TS3D_LOG"))
	 && (log_def = fopen(log_name_def, "w+"))) {
		// Replace UNTOUCHED_MARKER with log_def.
		if (logger_get_output(&log, LOGGER_INFO) == UNTOUCHED_MARKER)
			logger_set_output(&log, LOGGER_INFO, log_def, false);
		if (logger_get_output(&log, LOGGER_WARNING) == UNTOUCHED_MARKER)
			logger_set_output(&log, LOGGER_WARNING, log_def, false);
		if (logger_get_output(&log, LOGGER_ERROR) == UNTOUCHED_MARKER)
			logger_set_output(&log, LOGGER_ERROR, log_def, false);
	}
	ret = do_ts3d_game(data_dir, state_file, &log);
	if (ret < 0) {
		FILE *err_log = logger_get_output(&log, LOGGER_ERROR);
		if (err_log) {
			fflush(err_log);
			rewind(err_log);
			fprintf(stderr, "%s: An error occurred.\n", progname);
			// Copy the error log to stderr:
			int c;
			while ((c = getc(err_log)) != EOF) {
				putc(c, stderr);
			}
		} else {
			fprintf(stderr,
				"%s: An error occurred and was not logged.\n",
				progname);
		}
		goto end;
	}
end:
	free(data_dir);
	free(state_file);
	logger_free(&log);
	free(log_name_def);
	if (log_def) fclose(log_def);
	exit(ret >= 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbp
movl %edi, %ebx
testl %edi, %edi
jle 0x6abd
movq (%rbp), %rax
jmp 0x6ac4
leaq 0x4be9(%rip), %rax      # 0xb6ad
movq %rax, 0x8(%rsp)
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x680c
movq 0xa4f3(%rip), %rax      # 0x10fd0
movq (%rax), %rdx
pushq $0x7
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x6873
leaq 0x4bbe(%rip), %r15      # 0xb6b2
movq 0xa4e5(%rip), %r13      # 0x10fe0
pushq $0x1
popq %rax
movq %rax, 0x18(%rsp)
movq 0xa4de(%rip), %r12      # 0x10fe8
movq $0x0, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movq %rbp, 0x60(%rsp)
movl %ebx, 0x2c(%rsp)
movl %ebx, %edi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2240
testl %eax, %eax
js 0x6ceb
cmpl $0x4c, %eax
je 0x6bb2
cmpl $0x6c, %eax
jne 0x6c89
movq (%r13), %r15
movq %r15, %rdi
pushq $0x3d
popq %rsi
callq 0x22d0
testq %rax, %rax
je 0x6dc9
movq %rax, %r14
movb 0x1(%rax), %al
movb %al, 0x7(%rsp)
testb %al, %al
je 0x6bd0
leaq 0x1(%r14), %rbx
movq %rbx, %rdi
leaq 0x46be(%rip), %rsi      # 0xb243
callq 0x2160
testq %rax, %rax
je 0x6d98
movq %rbx, %rdi
leaq 0x50ac(%rip), %rsi      # 0xbc49
movq %rax, %rdx
callq 0x2400
movq %rax, %r13
testq %rax, %rax
jne 0x6bd4
jmp 0x6d98
movq (%r13), %rdx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x7066
testl %eax, %eax
je 0x6b2e
jmp 0x7046
movq (%r12), %r13
subq %r15, %r14
leaq 0x1(%r14), %rbx
leaq 0x50bf(%rip), %rdi      # 0xbca1
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2360
pushq $0x7
popq %rbp
testl %eax, %eax
je 0x6c45
leaq 0x50ab(%rip), %rdi      # 0xbca6
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2360
pushq $0x1
popq %rcx
movl %ecx, %ebp
testl %eax, %eax
je 0x6c45
leaq 0x5096(%rip), %rdi      # 0xbcac
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2360
pushq $0x2
popq %rbp
testl %eax, %eax
je 0x6c45
leaq 0x5086(%rip), %rdi      # 0xbcb5
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2360
pushq $0x4
popq %rbp
testl %eax, %eax
jne 0x6e98
xorl %ebx, %ebx
cmpb $0x0, 0x7(%rsp)
setne %bl
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x7185
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movl %ebx, %ecx
callq 0x6873
movq 0x60(%rsp), %rbp
movl 0x2c(%rsp), %ebx
leaq 0x4a35(%rip), %r15      # 0xb6b2
movq 0xa35c(%rip), %r13      # 0x10fe0
jmp 0x6b2e
cmpl $0x64, %eax
je 0x6cb1
cmpl $0x73, %eax
je 0x6cce
cmpl $0x68, %eax
je 0x6ffb
cmpl $0x76, %eax
je 0x7020
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x6b2e
movq 0x10(%rsp), %rdi
callq 0x2580
movq (%r13), %rdi
callq 0xa554
movq %rax, 0x10(%rsp)
jmp 0x6b2e
movq 0x20(%rsp), %rdi
callq 0x2580
movq (%r13), %rdi
callq 0xa554
movq %rax, 0x20(%rsp)
jmp 0x6b2e
testb $0x1, 0x30(%rsp)
jne 0x7050
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
jne 0x6d26
leaq 0x49b6(%rip), %rdi      # 0xb6bd
leaq 0x49b4(%rip), %rsi      # 0xb6c2
callq 0xa6b1
movq %rax, %rdi
testq %rax, %rax
jne 0x6d26
movq $0x0, 0x10(%rsp)
jmp 0x6d71
pushq $0x1
popq %rbp
movq %rdi, 0x10(%rsp)
movl %ebp, %esi
callq 0xa604
testl %eax, %eax
jne 0x6d71
movq 0x20(%rsp), %rax
testq %rax, %rax
jne 0x6e25
leaq 0x49ae(%rip), %rdi      # 0xb6fc
leaq 0x49b2(%rip), %rsi      # 0xb707
callq 0xa6b1
testq %rax, %rax
jne 0x6e25
movq $0x0, 0x20(%rsp)
jmp 0x6e5e
movq (%r12), %rbx
callq 0x2330
movl (%rax), %edi
callq 0x2260
leaq 0x4944(%rip), %rsi      # 0xb6cc
xorl %r12d, %r12d
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
jmp 0x6ddf
movq (%r12), %r14
callq 0x2330
movl (%rax), %edi
callq 0x2260
leaq 0x4e9d(%rip), %rsi      # 0xbc4c
xorl %r12d, %r12d
movq %r14, %rdi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x24c0
jmp 0x6de6
movq (%r12), %rdi
leaq 0x4e9b(%rip), %rsi      # 0xbc6f
xorl %r12d, %r12d
movq 0x8(%rsp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x24c0
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
callq 0x2580
movq 0x20(%rsp), %rdi
callq 0x2580
leaq 0x38(%rsp), %rdi
callq 0x6a11
movq %r12, %rdi
callq 0x2580
testq %rbx, %rbx
je 0x6e1b
movq %rbx, %rdi
callq 0x23f0
movq 0x18(%rsp), %rdi
callq 0x2110
movq %rax, 0x20(%rsp)
movq %rax, %rdi
xorl %esi, %esi
callq 0xa604
testl %eax, %eax
jne 0x6e5e
leaq 0x4904(%rip), %rdi      # 0xb743
leaq 0x4901(%rip), %rsi      # 0xb747
callq 0xa6b1
movq $0x0, 0x18(%rsp)
testq %rax, %rax
jne 0x6ebd
movq %rax, %r15
jmp 0x6ed8
movq (%r12), %rbx
callq 0x2330
movl (%rax), %edi
callq 0x2260
leaq 0x489d(%rip), %rsi      # 0xb712
xorl %r12d, %r12d
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x24c0
xorl %ebx, %ebx
movl %ebp, %eax
movq %rax, 0x18(%rsp)
jmp 0x6de8
movq (%r12), %rdi
leaq 0x4e19(%rip), %rsi      # 0xbcbc
xorl %r12d, %r12d
movq 0x8(%rsp), %rdx
movl %r14d, %ecx
movq %r15, %r8
xorl %eax, %eax
callq 0x24c0
jmp 0x6de6
leaq 0x488c(%rip), %rsi      # 0xb750
movq %rax, %r15
movq %rax, %rdi
callq 0x2160
testq %rax, %rax
jne 0x6f6e
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
movq 0x20(%rsp), %rsi
callq 0x38b8
testl %eax, %eax
jns 0x6f22
leaq 0x38(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0x6820
testq %rax, %rax
jne 0x6f2a
movq (%r12), %rdi
leaq 0x485c(%rip), %rsi      # 0xb76b
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x24c0
movl %ebp, %eax
movq %rax, 0x18(%rsp)
movq %r15, %r12
jmp 0x6de8
movq %rax, %r14
movq %rax, %rdi
callq 0x2560
movq %r14, %rdi
callq 0x2280
movq (%r12), %rdi
leaq 0x480b(%rip), %rsi      # 0xb753
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x24c0
movq %r14, %rdi
callq 0x2570
cmpl $-0x1, %eax
je 0x6f1b
movq (%r12), %rsi
movl %eax, %edi
callq 0x22b0
jmp 0x6f54
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x6820
movq 0xa04b(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x6f9c
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x6873
leaq 0x38(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x6820
movq 0xa020(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x6fc7
leaq 0x38(%rsp), %rdi
pushq $0x2
popq %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x6873
leaq 0x38(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0x6820
movq 0x9ff5(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x6eda
leaq 0x38(%rsp), %rdi
pushq $0x4
popq %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x6873
jmp 0x6eda
movq 0x9ff6(%rip), %rax      # 0x10ff8
movq (%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x716e
leaq 0x4780(%rip), %rdi      # 0xb796
callq 0x2100
xorl %r12d, %r12d
jmp 0x7036
leaq 0x4cdc(%rip), %rdi      # 0xbd03
xorl %r12d, %r12d
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x2040
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
jmp 0x6de8
xorl %ebx, %ebx
xorl %r12d, %r12d
jmp 0x6de8
movq (%r12), %rsi
movq 0x8(%rsp), %rdi
callq 0x716e
xorl %r12d, %r12d
jmp 0x6de6