// File: /workspace/github_cpp_makefile_star2_O2/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 0x9a3f(%rip), %rdi      # 0x14a10
leaq 0x50(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x63c0
testq %rax, %rax
js 0xaff6
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0xb002
addq %rsp, %rax
addq $0x50, %rax
jmp 0xafff
leaq 0x51(%rsp), %rax
movb $0x2e, -0x1(%rax)
movb $0x0, (%rax)
leaq 0x50(%rsp), %rsi
movb $0x0, 0xfff(%rsi)
leaq 0x28(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd778
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x6220
movq %rsp, %rdi
callq 0x6210
leaq 0x102f8(%rip), %rdi     # 0x1b330
movq %rax, %rsi
callq 0x6500
movq %rsp, %rdi
callq 0xd08a
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0xd08a
leaq 0x99c3(%rip), %rdi      # 0x14a1f
callq 0x63e0
movq %rax, (%rbx)
movq %rsp, %rbx
leaq 0x28(%rsp), %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd7e4
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x6220
leaq 0x102cd(%rip), %rdi     # 0x1b358
leaq 0x50(%rsp), %rbx
movq %rbx, %rsi
callq 0xd052
movq %rbx, %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x9975(%rip), %rsi      # 0x14a24
leaq 0x50(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd850
leaq 0x102ba(%rip), %rdi     # 0x1b380
movq %rbx, %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
leaq 0x994a(%rip), %rsi      # 0x14a29
movq %rsp, %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd8f4
leaq 0x10264(%rip), %rsi     # 0x1b358
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xd8bb
leaq 0x10278(%rip), %rdi     # 0x1b380
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x98fe(%rip), %rsi      # 0x14a29
movq %rsp, %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd8f4
leaq 0x101f0(%rip), %rsi     # 0x1b330
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xd8bb
leaq 0x1022c(%rip), %rdi     # 0x1b380
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x98c4(%rip), %rsi      # 0x14a3b
movq %rsp, %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd960
leaq 0x101a4(%rip), %rsi     # 0x1b330
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xd8bb
leaq 0x101f8(%rip), %rdi     # 0x1b398
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x9876(%rip), %rsi      # 0x14a39
leaq 0x50(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xd9cc
leaq 0x101be(%rip), %rdi     # 0x1b398
movq %rbx, %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
leaq 0x101a5(%rip), %rdi     # 0x1b398
leaq 0x10136(%rip), %rbx     # 0x1b330
movq %rbx, %rsi
callq 0xd572
leaq 0x983b(%rip), %rsi      # 0x14a44
movq %rsp, %r14
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0xda38
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xd8bb
leaq 0x10182(%rip), %rdi     # 0x1b3b0
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x97f1(%rip), %rsi      # 0x14a42
leaq 0x50(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xdaa4
leaq 0x10148(%rip), %rdi     # 0x1b3b0
movq %rbx, %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
leaq 0x1012f(%rip), %rdi     # 0x1b3b0
leaq 0x100a8(%rip), %rsi     # 0x1b330
callq 0xd572
leaq 0x97b8(%rip), %rsi      # 0x14a4c
movq %rsp, %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xdaa4
leaq 0x100af(%rip), %rsi     # 0x1b358
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
callq 0xd8bb
leaq 0x1010b(%rip), %rdi     # 0x1b3c8
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x100e8(%rip), %rdi     # 0x1b3c8
leaq 0x10071(%rip), %rbx     # 0x1b358
movq %rbx, %rsi
callq 0xd572
leaq 0x9760(%rip), %rsi      # 0x14a56
movq %rsp, %r14
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0xd9cc
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xd8bb
leaq 0x100c5(%rip), %rdi     # 0x1b3e0
leaq 0x50(%rsp), %rsi
callq 0xf640
leaq 0x50(%rsp), %rdi
callq 0xd08a
movq %rsp, %rdi
callq 0xd08a
leaq 0x100a2(%rip), %rdi     # 0x1b3e0
leaq 0x10013(%rip), %rsi     # 0x1b358
callq 0xd572
xorl %eax, %eax
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r14
retq
jmp 0xb36f
jmp 0xb38a
jmp 0xb36f
jmp 0xb38a
jmp 0xb380
jmp 0xb36f
jmp 0xb38a
jmp 0xb380
jmp 0xb36f
jmp 0xb38a
jmp 0xb36f
jmp 0xb38a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xd08a
jmp 0xb38d
jmp 0xb38a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0xb390
movq %rax, %rbx
movq %rsp, %rdi
callq 0xd08a
movq %rbx, %rdi
callq 0x6580
movq %rax, %rbx
jmp 0xb3ad
movq %rax, %rbx
movq %rsp, %rdi
callq 0xd08a
leaq 0x28(%rsp), %rdi
jmp 0xb390