// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %r15
movl %edi, %r13d
testl %edi, %edi
jle 0x7009
movq (%r15), %rax
jmp 0x7010
leaq 0x56cd(%rip), %rax      # 0xc6dd
movq %rax, (%rsp)
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x6d48
movq 0x9fa8(%rip), %rax      # 0x10fd0
movq (%rax), %rdx
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0x7, %esi
xorl %ecx, %ecx
callq 0x6d8d
leaq 0x569e(%rip), %rdx      # 0xc6e2
movl %r13d, %edi
movq %r15, %rsi
callq 0x2240
testl %eax, %eax
js 0x728f
movq 0x9f82(%rip), %rbx      # 0x10fe0
leaq 0x567d(%rip), %rbp      # 0xc6e2
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r15, 0x50(%rsp)
movl %r13d, 0x24(%rsp)
cmpl $0x6b, %eax
jg 0x70a9
cmpl $0x4c, %eax
je 0x70cf
cmpl $0x64, %eax
jne 0x715a
movq %r14, %rdi
callq 0x2570
movq (%rbx), %rdi
callq 0xada8
movq %rax, %r14
jmp 0x7249
cmpl $0x6c, %eax
je 0x70ed
cmpl $0x73, %eax
jne 0x7164
movq %r12, %rdi
callq 0x2570
movq (%rbx), %rdi
callq 0xada8
movq %rax, %r12
jmp 0x7249
movq (%rbx), %rdx
movq (%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7611
testl %eax, %eax
je 0x7249
jmp 0x75d8
movq %r14, 0x8(%rsp)
movq %rbx, %rbp
movq (%rbx), %rbx
movq %rbx, %rdi
movl $0x3d, %esi
callq 0x22c0
testq %rax, %rax
je 0x73f4
movq %rax, %r14
movq %r12, 0x18(%rsp)
movb 0x1(%rax), %r13b
testb %r13b, %r13b
je 0x7179
leaq 0x1(%r14), %r15
movq %r15, %rdi
leaq 0x5146(%rip), %rsi      # 0xc273
callq 0x2160
testq %rax, %rax
je 0x73b1
movq %r15, %rdi
leaq 0x5b34(%rip), %rsi      # 0xcc79
movq %rax, %rdx
callq 0x23f0
movq %rax, %r12
testq %rax, %rax
jne 0x7183
jmp 0x73b1
cmpl $0x68, %eax
jne 0x716d
jmp 0x75c2
cmpl $0x76, %eax
je 0x75ab
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x7249
movq 0x9e68(%rip), %rax      # 0x10fe8
movq (%rax), %r12
subq %rbx, %r14
leaq 0x1(%r14), %r15
leaq 0x5b40(%rip), %rdi      # 0xccd1
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2350
testl %eax, %eax
je 0x71ed
leaq 0x5b2f(%rip), %rdi      # 0xccd6
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2350
testl %eax, %eax
je 0x71f5
leaq 0x5b1f(%rip), %rdi      # 0xccdc
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2350
testl %eax, %eax
je 0x71fd
leaq 0x5b12(%rip), %rdi      # 0xcce5
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2350
movl $0x4, %r15d
testl %eax, %eax
je 0x7203
jmp 0x7581
movl $0x7, %r15d
jmp 0x7203
movl $0x1, %r15d
jmp 0x7203
movl $0x2, %r15d
xorl %ebx, %ebx
testb %r13b, %r13b
setne %bl
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
callq 0x772c
movq %r14, %rdi
movl %r15d, %esi
movq %r12, %rdx
movl %ebx, %ecx
callq 0x6d8d
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %r14
movq 0x50(%rsp), %r15
movl 0x24(%rsp), %r13d
movq %rbp, %rbx
leaq 0x5499(%rip), %rbp      # 0xc6e2
movl %r13d, %edi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2240
testl %eax, %eax
jns 0x707e
testb $0x1, 0x10(%rsp)
je 0x728a
movq 0x9d7b(%rip), %rax      # 0x10fe8
movq (%rax), %rdi
leaq 0x5acf(%rip), %rsi      # 0xcd46
xorl %r13d, %r13d
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x24b0
jmp 0x731d
testq %r14, %r14
jne 0x72af
leaq 0x5457(%rip), %rdi      # 0xc6ed
leaq 0x5455(%rip), %rsi      # 0xc6f2
callq 0xaf06
testq %rax, %rax
jne 0x72ac
xorl %r14d, %r14d
jmp 0x72ec
movq %rax, %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0xae58
testl %eax, %eax
jne 0x72ec
testq %r12, %r12
jne 0x735b
leaq 0x545c(%rip), %rdi      # 0xc72c
leaq 0x5460(%rip), %rsi      # 0xc737
callq 0xaf06
movq %rax, %r12
testq %rax, %rax
jne 0x735b
xorl %r12d, %r12d
jmp 0x738f
movq 0x9cf5(%rip), %rax      # 0x10fe8
movq (%rax), %rbx
callq 0x2320
movl (%rax), %edi
callq 0x2260
leaq 0x53f3(%rip), %rsi      # 0xc6fc
xorl %r13d, %r13d
movq %rbx, %rdi
movq (%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x24b0
movl $0x1, %ebx
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x2570
movq %r12, %rdi
callq 0x2570
leaq 0x28(%rsp), %rdi
callq 0x6f5d
movq %r13, %rdi
callq 0x2570
testq %r15, %r15
je 0x7354
movq %r15, %rdi
callq 0x23e0
movl %ebx, %edi
callq 0x2110
movq %r12, %rdi
xorl %esi, %esi
callq 0xae58
testl %eax, %eax
jne 0x738f
leaq 0x5403(%rip), %rdi      # 0xc773
leaq 0x5400(%rip), %rsi      # 0xc777
callq 0xaf06
xorl %ebx, %ebx
testq %rax, %rax
jne 0x7428
movq %rax, %r13
jmp 0x7443
movq 0x9c52(%rip), %rax      # 0x10fe8
movq (%rax), %rbx
callq 0x2320
movl (%rax), %edi
callq 0x2260
leaq 0x5396(%rip), %rsi      # 0xc742
jmp 0x7309
movq 0x9c30(%rip), %rax      # 0x10fe8
movq (%rax), %rbx
callq 0x2320
movl (%rax), %edi
callq 0x2260
leaq 0x58ae(%rip), %rsi      # 0xcc7c
xorl %r13d, %r13d
movq %rbx, %rdi
movq (%rsp), %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x24b0
movl $0x1, %ebx
xorl %r15d, %r15d
movq 0x18(%rsp), %r12
jmp 0x741e
movq 0x9bed(%rip), %rax      # 0x10fe8
movq (%rax), %rdi
leaq 0x589a(%rip), %rsi      # 0xcc9f
xorl %r13d, %r13d
movq (%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x24b0
movl $0x1, %ebx
xorl %r15d, %r15d
movq 0x8(%rsp), %r14
jmp 0x7325
leaq 0x5351(%rip), %rsi      # 0xc780
movq %rax, %r13
movq %rax, %rdi
callq 0x2160
testq %rax, %rax
jne 0x74e8
xorl %r15d, %r15d
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x3aa0
testl %eax, %eax
jns 0x7325
leaq 0x28(%rsp), %rdi
movl $0x4, %esi
callq 0x6d5f
testq %rax, %rax
jne 0x7490
movq 0x9b6f(%rip), %rax      # 0x10fe8
movq (%rax), %rdi
leaq 0x5318(%rip), %rsi      # 0xc79b
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x24b0
jmp 0x74de
movq %rax, %rbx
movq %r14, %rbp
movq %rax, %rdi
callq 0x2550
movq %rbx, %rdi
callq 0x2280
movq 0x9b3b(%rip), %r14      # 0x10fe8
movq (%r14), %rdi
leaq 0x52cc(%rip), %rsi      # 0xc783
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x24b0
movq %rbx, %rdi
callq 0x2560
cmpl $-0x1, %eax
je 0x74db
movq (%r14), %rsi
movl %eax, %edi
callq 0x22a0
jmp 0x74c2
movq %rbp, %r14
movl $0x1, %ebx
jmp 0x7325
movq %rax, %r15
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x6d5f
movq 0x9acf(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x751a
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6d8d
leaq 0x28(%rsp), %rdi
movl $0x2, %esi
callq 0x6d5f
movq 0x9aa0(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x7549
leaq 0x28(%rsp), %rdi
movl $0x2, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6d8d
leaq 0x28(%rsp), %rdi
movl $0x4, %esi
callq 0x6d5f
movq 0x9a71(%rip), %rcx      # 0x10fd0
cmpq (%rcx), %rax
jne 0x7446
leaq 0x28(%rsp), %rdi
movl $0x4, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6d8d
jmp 0x7446
movq 0x9a60(%rip), %rax      # 0x10fe8
movq (%rax), %rdi
leaq 0x575a(%rip), %rsi      # 0xccec
xorl %r13d, %r13d
movq (%rsp), %rdx
movl %r14d, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x24b0
jmp 0x73e5
leaq 0x5781(%rip), %rdi      # 0xcd33
xorl %r13d, %r13d
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2040
jmp 0x75ce
movq (%rsp), %rdi
callq 0x75e8
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %ebx, %ebx
jmp 0x7325
movl $0x1, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x7325