// File: /workspace/github_cpp_makefile_star2_O3/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 0xa460(%rip), %rdi      # 0x16ae0
leaq 0x50(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x63c0
testq %rax, %rax
js 0xc6a5
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0xc6b1
addq %rsp, %rax
addq $0x50, %rax
jmp 0xc6ae
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 0xf464
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x6200
movq %rsp, %rdi
callq 0x61f0
leaq 0xfc37(%rip), %rdi      # 0x1c320
movq %rax, %rsi
callq 0x64d0
movq %rsp, %rdi
callq 0xeeb0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0xeeb0
leaq 0xa3e2(%rip), %rdi      # 0x16aef
callq 0x63e0
movq %rax, (%rbx)
movq %rsp, %rbx
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf4ec
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x6200
leaq 0xfc0a(%rip), %rdi      # 0x1c348
leaq 0x50(%rsp), %rbx
movq %rbx, %rsi
callq 0x6400
movq 0x20(%rbx), %rax
movq $0x0, 0x20(%rbx)
movq 0xfc0a(%rip), %rsi      # 0x1c368
movq %rax, 0xfc03(%rip)      # 0x1c368
testq %rsi, %rsi
je 0xc776
leaq 0xfbf7(%rip), %rdi      # 0x1c368
callq 0x60e0
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x10128
movq %rbx, %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xa35a(%rip), %rsi      # 0x16af4
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf574
leaq 0xfbbd(%rip), %rdi      # 0x1c370
movq %rbx, %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
leaq 0xa32d(%rip), %rsi      # 0x16af9
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf634
leaq 0xfb65(%rip), %rsi      # 0x1c348
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf5fb
leaq 0xfb79(%rip), %rdi      # 0x1c370
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xa2df(%rip), %rsi      # 0x16af9
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf634
leaq 0xfaef(%rip), %rsi      # 0x1c320
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf5fb
leaq 0xfb2b(%rip), %rdi      # 0x1c370
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xa2a3(%rip), %rsi      # 0x16b0b
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf6bc
leaq 0xfaa1(%rip), %rsi      # 0x1c320
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf5fb
leaq 0xfaf5(%rip), %rdi      # 0x1c388
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xa253(%rip), %rsi      # 0x16b09
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf744
leaq 0xfab9(%rip), %rdi      # 0x1c388
movq %rbx, %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
leaq 0xfaa0(%rip), %rdi      # 0x1c388
leaq 0xfa31(%rip), %rbx      # 0x1c320
movq %rbx, %rsi
callq 0xf21a
leaq 0xa216(%rip), %rsi      # 0x16b14
movq %rsp, %r14
movq %r14, %rdi
movl $0x2, %edx
callq 0xf7cc
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf5fb
leaq 0xfa7b(%rip), %rdi      # 0x1c3a0
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xa1ca(%rip), %rsi      # 0x16b12
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf854
leaq 0xfa3f(%rip), %rdi      # 0x1c3a0
movq %rbx, %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
leaq 0xfa26(%rip), %rdi      # 0x1c3a0
leaq 0xf99f(%rip), %rsi      # 0x1c320
callq 0xf21a
leaq 0xa18f(%rip), %rsi      # 0x16b1c
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x2, %edx
callq 0xf854
leaq 0xf9a4(%rip), %rsi      # 0x1c348
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xf5fb
leaq 0xfa00(%rip), %rdi      # 0x1c3b8
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xf9dd(%rip), %rdi      # 0x1c3b8
leaq 0xf966(%rip), %rbx      # 0x1c348
movq %rbx, %rsi
callq 0xf21a
leaq 0xa135(%rip), %rsi      # 0x16b26
movq %rsp, %r14
movq %r14, %rdi
movl $0x2, %edx
callq 0xf744
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf5fb
leaq 0xf9b8(%rip), %rdi      # 0x1c3d0
leaq 0x50(%rsp), %rsi
callq 0x1146a
leaq 0x50(%rsp), %rdi
callq 0xeeb0
movq %rsp, %rdi
callq 0xeeb0
leaq 0xf995(%rip), %rdi      # 0x1c3d0
leaq 0xf906(%rip), %rsi      # 0x1c348
callq 0xf21a
xorl %eax, %eax
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r14
retq
jmp 0xca6c
jmp 0xca87
jmp 0xca6c
jmp 0xca87
jmp 0xca7d
jmp 0xca6c
jmp 0xca87
jmp 0xca7d
jmp 0xca6c
jmp 0xca87
jmp 0xca6c
jmp 0xca87
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xeeb0
jmp 0xca8a
jmp 0xca87
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0xca8d
movq %rax, %rbx
movq %rsp, %rdi
callq 0xeeb0
movq %rbx, %rdi
callq 0x6550
movq %rax, %rbx
jmp 0xcaaa
movq %rax, %rbx
movq %rsp, %rdi
callq 0xeeb0
leaq 0x28(%rsp), %rdi
jmp 0xca8d