// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: InitPaths()
int InitPaths()
{
	{ // find executable file location
#ifdef WINDOWS
		TCHAR rtnbuf[MAX_PATH];
		DWORD rtnlen = GetModuleFileName(NULL, rtnbuf, MAX_PATH);
		if (rtnlen < 0)
		{
			rtnbuf[0] = '.';
			rtnbuf[1] = 0;
		}
		else if (rtnlen < MAX_PATH)
		{
			rtnbuf[rtnlen] = 0;
		}
		rtnbuf[MAX_PATH - 1] = 0;
#else // *nix
		char rtnbuf[4096];
		ssize_t rtnlen = readlink("/proc/self/exe", rtnbuf, 4096);
		if (rtnlen < 0)
		{
			rtnbuf[0] = '.';
			rtnbuf[1] = 0;
		}
		else if (rtnlen < 4096)
		{
			rtnbuf[rtnlen] = 0;
		}
		rtnbuf[4095] = 0;
#endif
		config.system.exepath = std::filesystem::canonical(rtnbuf).remove_filename();
	}
	{ // find user home directory
#ifdef WINDOWS
		char homedrive[MAX_PATH], homedir[MAX_PATH];
		size_t homedrivelen;
		size_t homedirlen;
		getenv_s(&homedrivelen, homedrive, MAX_PATH, "HOMEDRIVE");
		if (homedrivelen < 0)
		{
			homedrive[0] = 'C';
			homedrive[1] = ':';
			homedrive[2] = 0;
		}
		else if (homedrivelen < MAX_PATH)
		{
			homedrive[homedrivelen] = 0;
		}
		homedrive[MAX_PATH - 1] = 0;
		getenv_s(&homedirlen, homedir, MAX_PATH, "HOMEPATH");
		if (homedirlen < 0)
		{
			homedir[0] = '\\';
			homedir[1] = 0;
		}
		else if (homedirlen < MAX_PATH)
		{
			homedir[homedirlen] = 0;
		}
		homedir[MAX_PATH - 1] = 0;
		config.system.homepath = std::filesystem::canonical(
			std::filesystem::path(homedrive)
			/ std::filesystem::path(homedir));
#else // *nix
		config.system.homepath = std::filesystem::canonical(std::getenv("HOME"));
#endif
	}
	{ // possible places to find configuration file
#ifdef WINDOWS
		config.system.configloc.push_back("Windows Registry");
#else // *nix
		config.system.configloc.push_back("/etc/.retro6k-config");
#endif
		config.system.configloc.push_back(
			config.system.homepath
			/ std::filesystem::path(".retro6k-config"));
		config.system.configloc.push_back(
			config.system.exepath / std::filesystem::path(".retro6k-config"));
	}
	// fallback paths in case of failure to load config
	config.path.rompath.push_back(config.system.exepath / std::filesystem::path("../rom"));
	config.path.rompath.push_back(std::filesystem::path("./../rom"));
	config.path.rompath.push_back(config.system.exepath);
	config.path.cartpath.push_back(config.system.exepath / std::filesystem::path("../cart"));
	config.path.cartpath.push_back(std::filesystem::path("./../cart"));
	config.path.cartpath.push_back(config.system.exepath);
	config.path.savepath.push_back(config.system.homepath / std::filesystem::path("Documents"));
	config.path.savepath.push_back(config.system.homepath);
	config.path.screencappath.push_back(config.system.homepath / std::filesystem::path("Pictures"));
	config.path.screencappath.push_back(config.system.homepath);
	return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x1058, %rsp           # imm = 0x1058
leaq 0xa9b5(%rip), %rdi      # 0x169f0
leaq 0x50(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x63c0
testq %rax, %rax
js 0xc060
cmpq $0xfff, %rax            # imm = 0xFFF
jg 0xc06c
addq %rsp, %rax
addq $0x50, %rax
jmp 0xc069
leaq 0x51(%rsp), %rax
movb $0x2e, -0x1(%rax)
movb $0x0, (%rax)
leaq 0x50(%rsp), %rsi
movb $0x0, 0xfff(%rsi)
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xee7c
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x6200
movq %rsp, %rdi
callq 0x61f0
leaq 0x1027c(%rip), %rdi     # 0x1c320
movq %rax, %rsi
callq 0x64d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0xe8d0
leaq 0xa937(%rip), %rdi      # 0x169ff
callq 0x63e0
movq %rax, (%rbx)
movq %rsp, %rbx
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x2, %edx
callq 0xef04
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x6200
leaq 0x1024f(%rip), %rdi     # 0x1c348
leaq 0x50(%rsp), %rbx
movq %rbx, %rsi
callq 0x6400
movq 0x20(%rbx), %rax
movq $0x0, 0x20(%rbx)
movq 0x1024f(%rip), %rsi     # 0x1c368
movq %rax, 0x10248(%rip)     # 0x1c368
testq %rsi, %rsi
je 0xc131
leaq 0x1023c(%rip), %rdi     # 0x1c368
callq 0x60e0
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0xfbcc
movq %rbx, %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xa8af(%rip), %rsi      # 0x16a04
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xef8c
leaq 0x10202(%rip), %rdi     # 0x1c370
movq %rbx, %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
leaq 0xa882(%rip), %rsi      # 0x16a09
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf04c
leaq 0x101aa(%rip), %rsi     # 0x1c348
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf013
leaq 0x101be(%rip), %rdi     # 0x1c370
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xa834(%rip), %rsi      # 0x16a09
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf04c
leaq 0x10134(%rip), %rsi     # 0x1c320
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf013
leaq 0x10170(%rip), %rdi     # 0x1c370
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xa7f8(%rip), %rsi      # 0x16a1b
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf0d4
leaq 0x100e6(%rip), %rsi     # 0x1c320
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf013
leaq 0x1013a(%rip), %rdi     # 0x1c388
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xa7a8(%rip), %rsi      # 0x16a19
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf15c
leaq 0x100fe(%rip), %rdi     # 0x1c388
movq %rbx, %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
leaq 0x100e5(%rip), %rdi     # 0x1c388
leaq 0x10076(%rip), %rbx     # 0x1c320
movq %rbx, %rsi
callq 0xec3a
leaq 0xa76b(%rip), %rsi      # 0x16a24
movq %rsp, %r14
movq %r14, %rdi
movl $0x2, %edx
callq 0xf1e4
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf013
leaq 0x100c0(%rip), %rdi     # 0x1c3a0
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xa71f(%rip), %rsi      # 0x16a22
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf26c
leaq 0x10084(%rip), %rdi     # 0x1c3a0
movq %rbx, %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
leaq 0x1006b(%rip), %rdi     # 0x1c3a0
leaq 0xffe4(%rip), %rsi      # 0x1c320
callq 0xec3a
leaq 0xa6e4(%rip), %rsi      # 0x16a2c
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf26c
leaq 0xffe9(%rip), %rsi      # 0x1c348
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf013
leaq 0x10045(%rip), %rdi     # 0x1c3b8
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0x10022(%rip), %rdi     # 0x1c3b8
leaq 0xffab(%rip), %rbx      # 0x1c348
movq %rbx, %rsi
callq 0xec3a
leaq 0xa68a(%rip), %rsi      # 0x16a36
movq %rsp, %r14
movq %r14, %rdi
movl $0x2, %edx
callq 0xf15c
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf013
leaq 0xfffd(%rip), %rdi      # 0x1c3d0
leaq 0x50(%rsp), %rsi
callq 0x10ed0
leaq 0x50(%rsp), %rdi
callq 0xe8d0
movq %rsp, %rdi
callq 0xe8d0
leaq 0xffda(%rip), %rdi      # 0x1c3d0
leaq 0xff4b(%rip), %rsi      # 0x1c348
callq 0xec3a
xorl %eax, %eax
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r14
retq
jmp 0xc427
jmp 0xc442
jmp 0xc427
jmp 0xc442
jmp 0xc438
jmp 0xc427
jmp 0xc442
jmp 0xc438
jmp 0xc427
jmp 0xc442
jmp 0xc427
jmp 0xc442
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xe8d0
jmp 0xc445
jmp 0xc442
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0xc448
movq %rax, %rbx
movq %rsp, %rdi
callq 0xe8d0
movq %rbx, %rdi
callq 0x6550
movq %rax, %rbx
jmp 0xc465
movq %rax, %rbx
movq %rsp, %rdi
callq 0xe8d0
leaq 0x28(%rsp), %rdi
jmp 0xc448