// File: rofl0r[P]ascc/main.cpp
// Function: main
int main(int argc, char** argv) {
	char exepath[1024];
	int c;
	int only_preprocess = 0;
	int disas_flag = 0;
	char oname_buf[2048], *oname = oname_buf;
	char *headers = 0;
	char *cppcmd = 0;
	const char *req_api = "350";
	char *systemhdr_dir = NULL;
	int abi = 350;

	set_compiler_default_options();

	while((c = getopt(argc, argv, "gWESD:A:a:f:i:H:o:P:")) != EOF) switch(c) {
		case 'a': abi = atoi(optarg); break;
		case 'A': req_api = optarg; break;
		case 'i': systemhdr_dir = optarg; break;
		case 'f': process_compiler_option(optarg); break;
		case 'o': oname = optarg; break;
		case 'H': headers = optarg; break;
		case 'P': cppcmd = optarg; break;
		case 'D': parse_macro(optarg); break;
		case 'E': only_preprocess = 1; break;
		case 'W': ccPrintAllErrors = 1; break;
		case 'S': disas_flag = 1; break;
		case 'g':
			add_macro("DEBUG", "1");
			ccSetOption(SCOPT_LINENUMBERS, 1);
			ccSetOption(SCOPT_CHECKBOUNDS, 1);
			break;
		default: return usage(argv[0]);
	}
	if(!argv[optind]) return usage(argv[0]);
	if(optind +1 != argc) {
		fprintf(stderr, "error: only one filename can be passed.\n"
				"arguments after first filename:\n");
		for(c=optind+1;c<argc;c++)
			fprintf(stderr, "%s\n", argv[c]);
		return usage(argv[0]);
	}
	char *filename = argv[optind];

	add_macro("__ASCC__", "3");
	add_macro("__ASCC_MINOR__", "5");

	// Editor/AGS.Editor/AGSEditor.cs
	add_macro("AGS_SUPPORTS_IFVER", "1");

	// FIXME: these should all be toggled by options
	//add_macro("STRICT", "1");
	add_macro("LRPRECEDENCE", "1");
	//add_macro("STRICT_STRINGS", "1");
	//add_macro("STRICT_AUDIO", "1");
	add_macro("NEW_DIALOGOPTS_API", "1");

        // Don't allow them to override imports in the room script
	// FIXME needs better check for whether it's a roomfile
        ccSetOption(SCOPT_NOIMPORTOVERRIDE, !!strstr(filename, "room") );

	if(abi < 271) {
		cc_set_max_command(SCMD_SHIFTRIGHT);
		ccSetOption(SCOPT_CHECKBOUNDS, 0);
		//ccSetOption(SCOPT_EXPLICITRET, 0);
	} else {
		add_macro("AGS_NEW_STRINGS", "1");
	}

	unsigned i;
	{
		int enable_api = 0;
		char abuf[16];
		snprintf(abuf, sizeof abuf, "%s000", req_api);
		add_macro("SCRIPT_API", abuf);
		for(i=0;apiv[i];++i) {
			char buf[64];
			// enable only requested and lower APIs
			if(!enable_api) {
				if(!strcmp(req_api, apiv[i]))
					enable_api = 1;
			} else
			// do not activate 3.x APIs for 2.x and vice versa
				if(req_api[0] != apiv[i][0])
					enable_api = 0;

			if(enable_api) {
				sprintf(buf, "SCRIPT_API_v%s", apiv[i]);
				add_macro(buf, "1");
				sprintf(buf, "SCRIPT_COMPAT_v%s", apiv[i]);
				add_macro(buf, "1");
			}
		}
	}

	FILE *f;
	char filename_wo_ext[2048];
	char *p = filename, *e = strrchr(filename, '.');
	char *q = filename_wo_ext;
	if(!e) return usage(argv[0]);
	while(p < e) *(q++) = *(p++);
	*q = 0;
	q = getbasename(filename_wo_ext);

	if(!opt_freestanding) {
		snprintf(oname_buf, sizeof oname_buf, "%s/agsdefns.sh", systemhdr_dir?systemhdr_dir:"systemhdrs");
		f = fopen(oname_buf, "r");
		if(!f && !systemhdr_dir && search_executable_dir(argv[0], exepath, sizeof exepath)) {
			snprintf(oname_buf, sizeof oname_buf, "%s/%s/agsdefns.sh", exepath, "systemhdrs");
			f = fopen(oname_buf, "r");
		}
		if(!f) fprintf(stderr, "warning: default header agsdefns.sh not found, you may want to set -i to the dir containing it!\n");
		else preproc_add(f, "_BuiltInScriptHeader.ash", !!cppcmd);
	}
	if(headers && !load_headers(headers, !!cppcmd)) return 1;

	if(oname == oname_buf) {
		if(only_preprocess)
			sprintf(oname, "%s.i", filename_wo_ext);
		else if(disas_flag)
			sprintf(oname, "%s.s", filename_wo_ext);
		else
			sprintf(oname, "%s.o", filename_wo_ext);
	}

	f = fopen(filename, "r");
	if(!f) {
		fprintf(stderr, "error opening %s\n", filename);
		return 1;
	}
	char *mem = slurp_file(f);
	if(only_preprocess) {
		char *outp;
		if(cppcmd) {
			outp = run_cpp(cppcmd, mem);
			if(!outp) return 1;
		} else {
			// FIXME, buf may be to small for elab. macro expansions
			outp = (char*)malloc(strlen(mem)*2+5000);
			cc_preprocess(mem, outp);
		}
		f = fopen(oname, "w");
		if(!f) {
			fprintf(stderr, "error opening %s\n", oname);
			return 1;
		}
		fwrite(outp, 1, strlen(outp), f);
		fclose(f);
		return ccError != 0;
	} else if(cppcmd) {
		char *outp = run_cpp(cppcmd, mem);
		if(!outp) return 1;
		free(mem);
		mem = outp;
	}
	ccScript* obj = ccCompileText(mem, q);
	if(!obj || (ccError != 0)) {
		std::cerr << ccErrorString;
		std::cerr << std::endl;
		return 1;
		//std::cout << ccErrorLine;
	} else {
		char *fn;
		if(disas_flag) fn = tempfile();
		else fn = strdup(oname);
		FileWriteStream fout;
		if(!fout.Open(fn)) {
			fprintf(stderr, "error opening %s\n", fn);
			return 1;
		}
		obj->Write(&fout);
		fout.Close();
		if(disas_flag) {
			char cmd[2048 + 64], *out_tmp = tempfile();
			sprintf(cmd, "agsdisas %s %s", fn, out_tmp);
			int status = system(cmd);
			if(status == -1 || !WIFEXITED(status)) {
				fprintf(stderr, "agsdisas failed! : ");
				perror("");
				return 1;
			}
			if(rename(out_tmp, oname) == -1) {
				perror("rename");
				return 1;
			}
			unlink(fn);
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d80, %rsp           # imm = 0x1D80
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x418(%rbp)
movl $0x0, -0x41c(%rbp)
leaq -0xc20(%rbp), %rax
movq %rax, -0xc28(%rbp)
movq $0x0, -0xc30(%rbp)
movq $0x0, -0xc38(%rbp)
leaq 0x2c5f2(%rip), %rax     # 0x310ca
movq %rax, -0xc40(%rbp)
movq $0x0, -0xc48(%rbp)
movl $0x15e, -0xc4c(%rbp)    # imm = 0x15E
callq 0x55d0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2c5c7(%rip), %rdx     # 0x310ce
callq 0x40f0
movl %eax, -0x414(%rbp)
cmpl $-0x1, %eax
je 0x4c6a
movl -0x414(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0x1d68(%rbp)
subl $0x2e, %eax
ja 0x4c51
movq -0x1d68(%rbp), %rax
leaq 0x2c4c0(%rip), %rcx     # 0x31004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x3d454(%rip), %rax     # 0x41fa8
movq (%rax), %rdi
callq 0x45b0
movl %eax, -0xc4c(%rbp)
jmp 0x4c65
movq 0x3d43a(%rip), %rax     # 0x41fa8
movq (%rax), %rax
movq %rax, -0xc40(%rbp)
jmp 0x4c65
movq 0x3d424(%rip), %rax     # 0x41fa8
movq (%rax), %rax
movq %rax, -0xc48(%rbp)
jmp 0x4c65
movq 0x3d40e(%rip), %rax     # 0x41fa8
movq (%rax), %rdi
callq 0x5630
jmp 0x4c65
movq 0x3d3fa(%rip), %rax     # 0x41fa8
movq (%rax), %rax
movq %rax, -0xc28(%rbp)
jmp 0x4c65
movq 0x3d3e4(%rip), %rax     # 0x41fa8
movq (%rax), %rax
movq %rax, -0xc30(%rbp)
jmp 0x4c65
movq 0x3d3ce(%rip), %rax     # 0x41fa8
movq (%rax), %rax
movq %rax, -0xc38(%rbp)
jmp 0x4c65
movq 0x3d3bb(%rip), %rax     # 0x41fa8
movq (%rax), %rdi
callq 0x5710
jmp 0x4c65
movl $0x1, -0x418(%rbp)
jmp 0x4c65
leaq 0x3dc42(%rip), %rax     # 0x4284c
movl $0x1, (%rax)
jmp 0x4c65
movl $0x1, -0x41c(%rbp)
jmp 0x4c65
leaq 0x2c4be(%rip), %rdi     # 0x310e3
leaq 0x2e434(%rip), %rsi     # 0x33060
callq 0x5780
movl $0x4, %edi
movl $0x1, %esi
callq 0x26560
movl $0x100, %edi            # imm = 0x100
movl $0x1, %esi
callq 0x26560
jmp 0x4c65
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5800
movl %eax, -0x4(%rbp)
jmp 0x55bf
jmp 0x4af9
movq -0x10(%rbp), %rax
movq 0x3d353(%rip), %rcx     # 0x41fc8
movslq (%rcx), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x4c93
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5800
movl %eax, -0x4(%rbp)
jmp 0x55bf
movq 0x3d32e(%rip), %rax     # 0x41fc8
movl (%rax), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
je 0x4d29
movq 0x3d311(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
leaq 0x2c430(%rip), %rsi     # 0x310e9
movb $0x0, %al
callq 0x4550
movq 0x3d301(%rip), %rax     # 0x41fc8
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x414(%rbp)
movl -0x414(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x4d15
movq 0x3d2dc(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x414(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x2c7e1(%rip), %rsi     # 0x314de
movb $0x0, %al
callq 0x4550
movl -0x414(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x414(%rbp)
jmp 0x4cd2
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5800
movl %eax, -0x4(%rbp)
jmp 0x55bf
movq -0x10(%rbp), %rax
movq 0x3d294(%rip), %rcx     # 0x41fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc58(%rbp)
leaq 0x2c3e9(%rip), %rdi     # 0x31132
leaq 0x2c3eb(%rip), %rsi     # 0x3113b
callq 0x5780
leaq 0x2c3e1(%rip), %rdi     # 0x3113d
leaq 0x2caf2(%rip), %rsi     # 0x31855
callq 0x5780
leaq 0x2c3dd(%rip), %rdi     # 0x3114c
leaq 0x2e2ea(%rip), %rsi     # 0x33060
callq 0x5780
leaq 0x2c3dd(%rip), %rdi     # 0x3115f
leaq 0x2e2d7(%rip), %rsi     # 0x33060
callq 0x5780
leaq 0x2c3d7(%rip), %rdi     # 0x3116c
leaq 0x2e2c4(%rip), %rsi     # 0x33060
callq 0x5780
movq -0xc58(%rbp), %rdi
leaq 0x2c3d0(%rip), %rsi     # 0x3117f
callq 0x40e0
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
movl $0x20, %edi
callq 0x26560
cmpl $0x10f, -0xc4c(%rbp)    # imm = 0x10F
jge 0x4df2
movl $0x2c, %edi
callq 0x6250
movl $0x100, %edi            # imm = 0x100
xorl %esi, %esi
callq 0x26560
jmp 0x4e05
leaq 0x2c38b(%rip), %rdi     # 0x31184
leaq 0x2e260(%rip), %rsi     # 0x33060
callq 0x5780
movl $0x0, -0xc60(%rbp)
leaq -0xc70(%rbp), %rdi
movq -0xc40(%rbp), %rcx
movl $0x10, %esi
leaq 0x2c36b(%rip), %rdx     # 0x31194
movb $0x0, %al
callq 0x45f0
leaq -0xc70(%rbp), %rsi
leaq 0x2c35c(%rip), %rdi     # 0x3119a
callq 0x5780
movl $0x0, -0xc5c(%rbp)
movl -0xc5c(%rbp), %eax
movl %eax, %ecx
leaq 0x3d544(%rip), %rax     # 0x423a0
cmpq $0x0, (%rax,%rcx,8)
je 0x4f65
cmpl $0x0, -0xc60(%rbp)
jne 0x4ea0
movq -0xc40(%rbp), %rdi
movl -0xc5c(%rbp), %eax
movl %eax, %ecx
leaq 0x3d51a(%rip), %rax     # 0x423a0
movq (%rax,%rcx,8), %rsi
callq 0x4510
cmpl $0x0, %eax
jne 0x4e9e
movl $0x1, -0xc60(%rbp)
jmp 0x4ed0
movq -0xc40(%rbp), %rax
movsbl (%rax), %eax
movl -0xc5c(%rbp), %ecx
movl %ecx, %edx
leaq 0x3d4e7(%rip), %rcx     # 0x423a0
movq (%rcx,%rdx,8), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x4ece
movl $0x0, -0xc60(%rbp)
jmp 0x4ed0
cmpl $0x0, -0xc60(%rbp)
je 0x4f4f
leaq -0xcb0(%rbp), %rdi
movl -0xc5c(%rbp), %eax
movl %eax, %ecx
leaq 0x3d4b1(%rip), %rax     # 0x423a0
movq (%rax,%rcx,8), %rdx
leaq 0x2c2ab(%rip), %rsi     # 0x311a5
movb $0x0, %al
callq 0x40d0
leaq -0xcb0(%rbp), %rdi
leaq 0x2e151(%rip), %rsi     # 0x33060
callq 0x5780
leaq -0xcb0(%rbp), %rdi
movl -0xc5c(%rbp), %eax
movl %eax, %ecx
leaq 0x3d476(%rip), %rax     # 0x423a0
movq (%rax,%rcx,8), %rdx
leaq 0x2c27f(%rip), %rsi     # 0x311b4
movb $0x0, %al
callq 0x40d0
leaq -0xcb0(%rbp), %rdi
leaq 0x2e116(%rip), %rsi     # 0x33060
callq 0x5780
jmp 0x4f51
movl -0xc5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc5c(%rbp)
jmp 0x4e4d
movq -0xc58(%rbp), %rax
movq %rax, -0x14c8(%rbp)
movq -0xc58(%rbp), %rdi
movl $0x2e, %esi
callq 0x4430
movq %rax, -0x14d0(%rbp)
leaq -0x14c0(%rbp), %rax
movq %rax, -0x14d8(%rbp)
cmpq $0x0, -0x14d0(%rbp)
jne 0x4fb7
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5800
movl %eax, -0x4(%rbp)
jmp 0x55bf
jmp 0x4fb9
movq -0x14c8(%rbp), %rax
cmpq -0x14d0(%rbp), %rax
jae 0x4ff9
movq -0x14c8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x14c8(%rbp)
movb (%rax), %cl
movq -0x14d8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x14d8(%rbp)
movb %cl, (%rax)
jmp 0x4fb9
movq -0x14d8(%rbp), %rax
movb $0x0, (%rax)
leaq -0x14c0(%rbp), %rdi
callq 0x5990
movq %rax, -0x14d8(%rbp)
cmpl $0x0, 0x3d4ef(%rip)     # 0x4250c
jne 0x5156
leaq -0xc20(%rbp), %rax
movq %rax, -0x1d70(%rbp)
cmpq $0x0, -0xc48(%rbp)
je 0x504b
movq -0xc48(%rbp), %rax
movq %rax, -0x1d78(%rbp)
jmp 0x505b
leaq 0x2c174(%rip), %rax     # 0x311c6
movq %rax, -0x1d78(%rbp)
jmp 0x505b
movq -0x1d70(%rbp), %rdi
movq -0x1d78(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
leaq 0x2c15f(%rip), %rdx     # 0x311d4
movb $0x0, %al
callq 0x45f0
leaq -0xc20(%rbp), %rdi
leaq 0x2f40e(%rip), %rsi     # 0x34498
callq 0x4450
movq %rax, -0xcb8(%rbp)
cmpq $0x0, -0xcb8(%rbp)
jne 0x5109
cmpq $0x0, -0xc48(%rbp)
jne 0x5109
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x410(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x59f0
cmpl $0x0, %eax
je 0x5109
leaq -0xc20(%rbp), %rdi
leaq -0x410(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
leaq 0x2c0f0(%rip), %rdx     # 0x311d1
leaq 0x2c0de(%rip), %r8      # 0x311c6
movb $0x0, %al
callq 0x45f0
leaq -0xc20(%rbp), %rdi
leaq 0x2f39b(%rip), %rsi     # 0x34498
callq 0x4450
movq %rax, -0xcb8(%rbp)
cmpq $0x0, -0xcb8(%rbp)
jne 0x512d
movq 0x3cea6(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
leaq 0x2c0bf(%rip), %rsi     # 0x311e3
movb $0x0, %al
callq 0x4550
jmp 0x5154
movq -0xcb8(%rbp), %rdi
cmpq $0x0, -0xc38(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edx
leaq 0x2c0f5(%rip), %rsi     # 0x31244
callq 0x5a60
jmp 0x5156
cmpq $0x0, -0xc30(%rbp)
je 0x5191
movq -0xc30(%rbp), %rdi
cmpq $0x0, -0xc38(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x5ac0
cmpl $0x0, %eax
jne 0x5191
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0xc28(%rbp), %rax
leaq -0xc20(%rbp), %rcx
cmpq %rcx, %rax
jne 0x5212
cmpl $0x0, -0x418(%rbp)
je 0x51cb
movq -0xc28(%rbp), %rdi
leaq -0x14c0(%rbp), %rdx
leaq 0x2c09b(%rip), %rsi     # 0x3125d
movb $0x0, %al
callq 0x40d0
jmp 0x5210
cmpl $0x0, -0x41c(%rbp)
je 0x51f2
movq -0xc28(%rbp), %rdi
leaq -0x14c0(%rbp), %rdx
leaq 0x2c079(%rip), %rsi     # 0x31262
movb $0x0, %al
callq 0x40d0
jmp 0x520e
movq -0xc28(%rbp), %rdi
leaq -0x14c0(%rbp), %rdx
leaq 0x2c060(%rip), %rsi     # 0x31267
movb $0x0, %al
callq 0x40d0
jmp 0x5210
jmp 0x5212
movq -0xc58(%rbp), %rdi
leaq 0x2f278(%rip), %rsi     # 0x34498
callq 0x4450
movq %rax, -0xcb8(%rbp)
cmpq $0x0, -0xcb8(%rbp)
jne 0x5261
movq 0x3cd83(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
movq -0xc58(%rbp), %rdx
leaq 0x2c01e(%rip), %rsi     # 0x3126c
movb $0x0, %al
callq 0x4550
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0xcb8(%rbp), %rdi
callq 0x49f0
movq %rax, -0x14e0(%rbp)
cmpl $0x0, -0x418(%rbp)
je 0x539f
cmpq $0x0, -0xc38(%rbp)
je 0x52bd
movq -0xc38(%rbp), %rdi
movq -0x14e0(%rbp), %rsi
callq 0x5ba0
movq %rax, -0x14e8(%rbp)
cmpq $0x0, -0x14e8(%rbp)
jne 0x52bb
movl $0x1, -0x4(%rbp)
jmp 0x55bf
jmp 0x52f5
movq -0x14e0(%rbp), %rdi
callq 0x41d0
movq %rax, %rdi
shlq %rdi
addq $0x1388, %rdi           # imm = 0x1388
callq 0x44f0
movq %rax, -0x14e8(%rbp)
movq -0x14e0(%rbp), %rdi
movq -0x14e8(%rbp), %rsi
callq 0x2d5d0
movq -0xc28(%rbp), %rdi
leaq 0x2e6df(%rip), %rsi     # 0x339e2
callq 0x4450
movq %rax, -0xcb8(%rbp)
cmpq $0x0, -0xcb8(%rbp)
jne 0x5344
movq 0x3cca0(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
movq -0xc28(%rbp), %rdx
leaq 0x2bf3b(%rip), %rsi     # 0x3126c
movb $0x0, %al
callq 0x4550
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0x14e8(%rbp), %rax
movq %rax, -0x1d80(%rbp)
movq -0x14e8(%rbp), %rdi
callq 0x41d0
movq -0x1d80(%rbp), %rdi
movq %rax, %rdx
movq -0xcb8(%rbp), %rcx
movl $0x1, %esi
callq 0x46e0
movq -0xcb8(%rbp), %rdi
callq 0x4370
leaq 0x3d4c4(%rip), %rax     # 0x42850
cmpl $0x0, (%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
jmp 0x55bf
cmpq $0x0, -0xc38(%rbp)
je 0x53f3
movq -0xc38(%rbp), %rdi
movq -0x14e0(%rbp), %rsi
callq 0x5ba0
movq %rax, -0x14f0(%rbp)
cmpq $0x0, -0x14f0(%rbp)
jne 0x53d9
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0x14e0(%rbp), %rdi
callq 0x4460
movq -0x14f0(%rbp), %rax
movq %rax, -0x14e0(%rbp)
jmp 0x53f5
movq -0x14e0(%rbp), %rdi
movq -0x14d8(%rbp), %rsi
callq 0x2bc40
movq %rax, -0x14f8(%rbp)
cmpq $0x0, -0x14f8(%rbp)
je 0x5425
leaq 0x3d430(%rip), %rax     # 0x42850
cmpl $0x0, (%rax)
je 0x545f
leaq 0x3d42c(%rip), %rdi     # 0x42858
callq 0x6180
movq %rax, %rsi
movq 0x3cbad(%rip), %rdi     # 0x41fe8
callq 0x4360
movq 0x3cba1(%rip), %rdi     # 0x41fe8
movq 0x3cb52(%rip), %rsi     # 0x41fa0
callq 0x43b0
movl $0x1, -0x4(%rbp)
jmp 0x55bf
cmpl $0x0, -0x41c(%rbp)
je 0x5476
callq 0x49a0
movq %rax, -0x1500(%rbp)
jmp 0x5489
movq -0xc28(%rbp), %rdi
callq 0x46b0
movq %rax, -0x1500(%rbp)
movq -0x1500(%rbp), %rsi
leaq -0x1508(%rbp), %rdi
callq 0x61a0
cmpl $0x0, %eax
jne 0x54cc
movq 0x3cb18(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
movq -0x1500(%rbp), %rdx
leaq 0x2bdb3(%rip), %rsi     # 0x3126c
movb $0x0, %al
callq 0x4550
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0x14f8(%rbp), %rdi
leaq -0x1508(%rbp), %rsi
callq 0x27450
leaq -0x1508(%rbp), %rdi
callq 0x61f0
cmpl $0x0, -0x41c(%rbp)
je 0x55b6
callq 0x49a0
movq %rax, -0x1d58(%rbp)
leaq -0x1d50(%rbp), %rdi
movq -0x1500(%rbp), %rdx
movq -0x1d58(%rbp), %rcx
leaq 0x2bd5e(%rip), %rsi     # 0x3127e
movb $0x0, %al
callq 0x40d0
leaq -0x1d50(%rbp), %rdi
callq 0x4330
movl %eax, -0x1d5c(%rbp)
cmpl $-0x1, -0x1d5c(%rbp)
je 0x5550
movl -0x1d5c(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
je 0x557d
movq 0x3ca69(%rip), %rax     # 0x41fc0
movq (%rax), %rdi
leaq 0x2bd2c(%rip), %rsi     # 0x3128d
movb $0x0, %al
callq 0x4550
leaq 0x2ebfd(%rip), %rdi     # 0x3416c
callq 0x4310
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0x1d58(%rbp), %rdi
movq -0xc28(%rbp), %rsi
callq 0x4260
cmpl $-0x1, %eax
jne 0x55aa
leaq 0x2bd05(%rip), %rdi     # 0x312a1
callq 0x4310
movl $0x1, -0x4(%rbp)
jmp 0x55bf
movq -0x1500(%rbp), %rdi
callq 0x4200
jmp 0x55b8
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1d80, %rsp           # imm = 0x1D80
popq %rbp
retq
nopl (%rax,%rax)