// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x15(%rbp)
cmpl $0x0, -0x8(%rbp)
jle 0xa51a
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0xa52a
leaq 0x72fb(%rip), %rax      # 0x1181c
movq %rax, -0x88(%rbp)
jmp 0xa52a
movq -0x88(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9ff0
movq 0xba6b(%rip), %rax      # 0x15fd0
movq (%rax), %rdx
leaq -0x58(%rbp), %rdi
movl $0x7, %esi
xorl %ecx, %ecx
callq 0xa150
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x729b(%rip), %rdx      # 0x11821
callq 0x2240
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
jl 0xa67e
movl -0x6c(%rbp), %eax
addl $-0x4c, %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x2a, %eax
ja 0xa675
movq -0x90(%rbp), %rax
leaq 0x71b3(%rip), %rcx      # 0x11770
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rdi
callq 0x2580
movq 0xba0a(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
callq 0x106a0
movq %rax, -0x28(%rbp)
jmp 0xa679
movq -0x20(%rbp), %rdi
callq 0xa970
movl $0x0, -0x14(%rbp)
jmp 0xa918
movq -0x20(%rbp), %rdi
movq 0xb9d9(%rip), %rax      # 0x15fe0
movq (%rax), %rdx
leaq -0x58(%rbp), %rsi
callq 0xa9b0
cmpl $0x0, %eax
je 0xa61d
jmp 0xa918
jmp 0xa679
movq -0x20(%rbp), %rdi
movq 0xb9b6(%rip), %rax      # 0x15fe0
movq (%rax), %rdx
leaq -0x58(%rbp), %rsi
callq 0xabe0
cmpl $0x0, %eax
je 0xa640
jmp 0xa918
jmp 0xa679
movq -0x30(%rbp), %rdi
callq 0x2580
movq 0xb98e(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
callq 0x106a0
movq %rax, -0x30(%rbp)
jmp 0xa679
movq -0x20(%rbp), %rdi
callq 0xad10
movl $0x0, -0x14(%rbp)
jmp 0xa918
movb $0x1, -0x15(%rbp)
jmp 0xa578
testb $0x1, -0x15(%rbp)
je 0xa69c
movq -0x20(%rbp), %rdi
movq 0xb959(%rip), %rax      # 0x15fe8
movq (%rax), %rsi
callq 0xad40
jmp 0xa918
cmpq $0x0, -0x28(%rbp)
jne 0xa6ba
leaq 0x7182(%rip), %rdi      # 0x1182c
leaq 0x7180(%rip), %rsi      # 0x11831
callq 0x10930
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xa6d4
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x10800
cmpl $0x0, %eax
je 0xa720
movq 0xb90d(%rip), %rax      # 0x15fe8
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x2320
movl (%rax), %edi
callq 0x2260
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rdx
movq %rax, %rcx
leaq 0x7127(%rip), %rsi      # 0x1183b
movb $0x0, %al
callq 0x24c0
jmp 0xa918
cmpq $0x0, -0x30(%rbp)
jne 0xa73e
leaq 0x713d(%rip), %rdi      # 0x1186b
leaq 0x7141(%rip), %rsi      # 0x11876
callq 0x10930
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xa755
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x10800
cmpl $0x0, %eax
je 0xa7a1
movq 0xb88c(%rip), %rax      # 0x15fe8
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
callq 0x2320
movl (%rax), %edi
callq 0x2260
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
movq %rax, %rcx
leaq 0x70ec(%rip), %rsi      # 0x11881
movb $0x0, %al
callq 0x24c0
jmp 0xa918
leaq 0x710a(%rip), %rdi      # 0x118b2
leaq 0x7107(%rip), %rsi      # 0x118b6
callq 0x10930
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0xa86c
movq -0x60(%rbp), %rdi
leaq 0x70f2(%rip), %rsi      # 0x118bf
callq 0x2160
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0xa86c
leaq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0xa040
movq 0xb7db(%rip), %rcx      # 0x15fd0
cmpq (%rcx), %rax
jne 0xa80e
movq -0x68(%rbp), %rdx
leaq -0x58(%rbp), %rdi
movl $0x1, %esi
xorl %ecx, %ecx
callq 0xa150
leaq -0x58(%rbp), %rdi
movl $0x2, %esi
callq 0xa040
movq 0xb7ad(%rip), %rcx      # 0x15fd0
cmpq (%rcx), %rax
jne 0xa83c
movq -0x68(%rbp), %rdx
leaq -0x58(%rbp), %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0xa150
leaq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0xa040
movq 0xb77f(%rip), %rcx      # 0x15fd0
cmpq (%rcx), %rax
jne 0xa86a
movq -0x68(%rbp), %rdx
leaq -0x58(%rbp), %rdi
movl $0x4, %esi
xorl %ecx, %ecx
callq 0xa150
jmp 0xa86c
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x4bd0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0xa916
leaq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0xa040
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0xa8f8
movq -0x78(%rbp), %rdi
callq 0x2560
movq -0x78(%rbp), %rdi
callq 0x2280
movq 0xb72c(%rip), %rax      # 0x15fe8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x6ff8(%rip), %rsi      # 0x118c2
movb $0x0, %al
callq 0x24c0
movq -0x78(%rbp), %rdi
callq 0x2570
movl %eax, -0x7c(%rbp)
cmpl $-0x1, %eax
je 0xa8f6
movl -0x7c(%rbp), %edi
movq 0xb6fc(%rip), %rax      # 0x15fe8
movq (%rax), %rsi
callq 0x22a0
jmp 0xa8d1
jmp 0xa914
movq 0xb6e9(%rip), %rax      # 0x15fe8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x6fcd(%rip), %rsi      # 0x118da
movb $0x0, %al
callq 0x24c0
jmp 0xa918
jmp 0xa918
movq -0x28(%rbp), %rdi
callq 0x2580
movq -0x30(%rbp), %rdi
callq 0x2580
leaq -0x58(%rbp), %rdi
callq 0xa3c0
movq -0x60(%rbp), %rdi
callq 0x2580
cmpq $0x0, -0x68(%rbp)
je 0xa94c
movq -0x68(%rbp), %rdi
callq 0x23f0
movl -0x14(%rbp), %ecx
movl $0x1, %edi
xorl %eax, %eax
cmpl $0x0, %ecx
cmovgel %eax, %edi
callq 0x2110
nopw %cs:(%rax,%rax)