// File: mdpkh[P]retro6k/src/main.cpp
// Function: bool LoadConfigFromFile<char const*>(char const*)
bool LoadConfigFromFile(T infilename)
{
	std::ifstream infile(infilename, std::ios::binary);
	if (!infile.is_open())
	{
		infile.close();
		return false;
	}
	std::string line;
	configfilesection section = configfilesection::CF_UNKNOWN;
	while (std::getline(infile, line))
	{
		if (!line.size() || line[0] == '#')
			continue;
		while (line.size() > 0 && 
			(line[line.size() - 1] == '\r' || line[line.size() - 1] == '\n'))
			line.resize(line.size() - 1);
		if (line[0] == '[')
		{
			if (cilstreq(line.c_str(), "[paths]"))
			{
				section = configfilesection::CF_PATHS;
				continue;
			}
			if (cilstreq(line.c_str(), "[screen]"))
			{
				section = configfilesection::CF_SCREEN;
				continue;
			}
			section = configfilesection::CF_UNKNOWN;
			continue;
		}
		int splitpos = -1;
		for (int i = 0; i < line.size(); ++i)
		{
			if (line[i] == '=')
			{
				splitpos = i;
				break;
			}
		}
		if (splitpos < 0)
			continue;
		std::string_view key(line.c_str(), splitpos);
		++splitpos;
		std::string_view value(line.c_str() + splitpos, line.size() - splitpos);
		switch (section)
		{
		case configfilesection::CF_PATHS:
			if (key == "cart")
			{
				config.sessionpath.cartpath.push_back(std::filesystem::path(value));
				break;
			}
			if (key == "rom")
			{
				config.sessionpath.rompath.push_back(std::filesystem::path(value));
				break;
			}
			if (key == "save")
			{
				config.sessionpath.savepath.push_back(std::filesystem::path(value));
				break;
			}
			if (key == "screencap")
			{
				config.sessionpath.screencappath.push_back(std::filesystem::path(value));
				break;
			}
			break;
		case configfilesection::CF_SCREEN:
			if (key == "aspectratio")
			{
				if (value == "free")
				{
					config.screen.specaspectratio = aspectratiocat::AR_FREE;
					break;
				}
				if (value == "classic")
				{
					config.screen.specaspectratio = aspectratiocat::AR_CLASSIC;
					break;
				}
				if (value == "wide")
				{
					config.screen.specaspectratio = aspectratiocat::AR_WIDE;
					break;
				}
				break;
			}
			if (key == "pixwidth")
			{
				if (value == "auto")
				{
					config.screen.specpixwidth = -1;
					break;
				}
				config.screen.specpixwidth = atoi(value.data());
				config.screen.pixwidth = config.screen.specpixwidth;
				break;
			}
			if (key == "pixheight")
			{
				if (value == "auto")
				{
					config.screen.specpixheight = -1;
					break;
				}
				config.screen.specpixheight = atoi(value.data());
				config.screen.pixheight = config.screen.specpixheight;
				break;
			}
			break;
		}
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movq %rdi, -0x4a8(%rbp)
movl $0x4, %edx
callq 0x7760
movq -0x4a8(%rbp), %rdi
callq 0x7680
movb %al, -0x499(%rbp)
jmp 0x14cff
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x14d43
jmp 0x14d0b
leaq -0x218(%rbp), %rdi
callq 0x70a0
jmp 0x14d19
movb $0x0, -0x1(%rbp)
movl $0x1, -0x228(%rbp)
jmp 0x15730
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x1574a
leaq -0x248(%rbp), %rdi
callq 0x75e0
movl $0x0, -0x24c(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x7090
movq %rax, -0x4b0(%rbp)
jmp 0x14d75
movq -0x4b0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x7540
movb %al, -0x4b1(%rbp)
jmp 0x14d93
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0x14da2
jmp 0x15706
leaq -0x248(%rbp), %rdi
callq 0x7320
cmpq $0x0, %rax
je 0x14ddc
xorl %eax, %eax
movl %eax, %esi
leaq -0x248(%rbp), %rdi
callq 0x77b0
movq %rax, -0x4c0(%rbp)
jmp 0x14dcd
movq -0x4c0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x14df8
jmp 0x14d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x15722
jmp 0x14dfa
leaq -0x248(%rbp), %rdi
callq 0x7320
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x4c1(%rbp)
jbe 0x14eb0
leaq -0x248(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x7320
movq -0x4d8(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x77b0
movq %rax, -0x4d0(%rbp)
jmp 0x14e49
movq -0x4d0(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xd, %ecx
movb %al, -0x4d9(%rbp)
je 0x14ea4
leaq -0x248(%rbp), %rdi
movq %rdi, -0x4f0(%rbp)
callq 0x7320
movq -0x4f0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x77b0
movq %rax, -0x4e8(%rbp)
jmp 0x14e8e
movq -0x4e8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x4d9(%rbp)
movb -0x4d9(%rbp), %al
movb %al, -0x4c1(%rbp)
movb -0x4c1(%rbp), %al
testb $0x1, %al
jne 0x14ebc
jmp 0x14ee8
leaq -0x248(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0x7320
movq -0x4f8(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x75d0
jmp 0x14ee3
jmp 0x14dfa
xorl %eax, %eax
movl %eax, %esi
leaq -0x248(%rbp), %rdi
callq 0x77b0
movq %rax, -0x500(%rbp)
jmp 0x14f01
movq -0x500(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0x14f7f
leaq -0x248(%rbp), %rdi
callq 0x71b0
movq %rax, %rdi
leaq 0xeb97(%rip), %rsi      # 0x23abd
callq 0x13be0
testb $0x1, %al
jne 0x14f31
jmp 0x14f40
movl $0x1, -0x24c(%rbp)
jmp 0x14d59
leaq -0x248(%rbp), %rdi
callq 0x71b0
movq %rax, %rdi
leaq 0xeb6f(%rip), %rsi      # 0x23ac5
callq 0x13be0
testb $0x1, %al
jne 0x14f61
jmp 0x14f70
movl $0x2, -0x24c(%rbp)
jmp 0x14d59
movl $0x0, -0x24c(%rbp)
jmp 0x14d59
movl $0xffffffff, -0x250(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x254(%rbp)
movslq -0x254(%rbp), %rax
movq %rax, -0x508(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x7320
movq %rax, %rcx
movq -0x508(%rbp), %rax
cmpq %rcx, %rax
jae 0x15008
movslq -0x254(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0x77b0
movq %rax, -0x510(%rbp)
jmp 0x14fd8
movq -0x510(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x14ff5
movl -0x254(%rbp), %eax
movl %eax, -0x250(%rbp)
jmp 0x15008
jmp 0x14ff7
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x14f93
cmpl $0x0, -0x250(%rbp)
jge 0x15016
jmp 0x14d59
leaq -0x248(%rbp), %rdi
movq %rdi, -0x528(%rbp)
callq 0x71b0
movq %rax, %rsi
movslq -0x250(%rbp), %rdx
leaq -0x268(%rbp), %rdi
callq 0x1c530
movq -0x528(%rbp), %rdi
movl -0x250(%rbp), %eax
incl %eax
movl %eax, -0x250(%rbp)
callq 0x71b0
movq -0x528(%rbp), %rdi
movslq -0x250(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x520(%rbp)
callq 0x7320
movq -0x520(%rbp), %rsi
movq %rax, %rdx
movslq -0x250(%rbp), %rax
subq %rax, %rdx
leaq -0x278(%rbp), %rdi
callq 0x1c530
movl -0x24c(%rbp), %eax
movl %eax, -0x514(%rbp)
subl $0x1, %eax
je 0x150bd
jmp 0x150a9
movl -0x514(%rbp), %eax
subl $0x2, %eax
je 0x153a6
jmp 0x15701
movq -0x268(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x298(%rbp), %rdi
leaq 0xe850(%rip), %rsi      # 0x23937
callq 0x18f40
movq -0x288(%rbp), %rdi
movq -0x280(%rbp), %rsi
movq -0x298(%rbp), %rdx
movq -0x290(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x15113
jmp 0x15176
leaq -0x2c0(%rbp), %rdi
leaq -0x278(%rbp), %rsi
movl $0x2, %edx
callq 0x1c5e0
jmp 0x1512d
leaq 0x183cc(%rip), %rdi     # 0x2d500
leaq -0x2c0(%rbp), %rsi
callq 0x145b0
jmp 0x15142
leaq -0x2c0(%rbp), %rdi
callq 0x12ed0
jmp 0x15701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x12ed0
jmp 0x15722
movq -0x268(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x2c8(%rbp)
leaq -0x2e0(%rbp), %rdi
leaq 0xe7d1(%rip), %rsi      # 0x23971
callq 0x18f40
movq -0x2d0(%rbp), %rdi
movq -0x2c8(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
movq -0x2d8(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x151cc
jmp 0x1522f
leaq -0x308(%rbp), %rdi
leaq -0x278(%rbp), %rsi
movl $0x2, %edx
callq 0x1c5e0
jmp 0x151e6
leaq 0x182fb(%rip), %rdi     # 0x2d4e8
leaq -0x308(%rbp), %rsi
callq 0x145b0
jmp 0x151fb
leaq -0x308(%rbp), %rdi
callq 0x12ed0
jmp 0x15701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x12ed0
jmp 0x15722
movq -0x268(%rbp), %rax
movq %rax, -0x318(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x328(%rbp), %rdi
leaq 0xe597(%rip), %rsi      # 0x237f0
callq 0x18f40
movq -0x318(%rbp), %rdi
movq -0x310(%rbp), %rsi
movq -0x328(%rbp), %rdx
movq -0x320(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x15285
jmp 0x152e8
leaq -0x350(%rbp), %rdi
leaq -0x278(%rbp), %rsi
movl $0x2, %edx
callq 0x1c5e0
jmp 0x1529f
leaq 0x18272(%rip), %rdi     # 0x2d518
leaq -0x350(%rbp), %rsi
callq 0x145b0
jmp 0x152b4
leaq -0x350(%rbp), %rdi
callq 0x12ed0
jmp 0x15701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x12ed0
jmp 0x15722
movq -0x268(%rbp), %rax
movq %rax, -0x360(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x358(%rbp)
leaq -0x370(%rbp), %rdi
leaq 0xe7bc(%rip), %rsi      # 0x23ace
callq 0x18f40
movq -0x360(%rbp), %rdi
movq -0x358(%rbp), %rsi
movq -0x370(%rbp), %rdx
movq -0x368(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x1533e
jmp 0x153a1
leaq -0x398(%rbp), %rdi
leaq -0x278(%rbp), %rsi
movl $0x2, %edx
callq 0x1c5e0
jmp 0x15358
leaq 0x181d1(%rip), %rdi     # 0x2d530
leaq -0x398(%rbp), %rsi
callq 0x145b0
jmp 0x1536d
leaq -0x398(%rbp), %rdi
callq 0x12ed0
jmp 0x15701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x12ed0
jmp 0x15722
jmp 0x15701
movq -0x268(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x3a0(%rbp)
leaq -0x3b8(%rbp), %rdi
leaq 0xe708(%rip), %rsi      # 0x23ad8
callq 0x18f40
movq -0x3a8(%rbp), %rdi
movq -0x3a0(%rbp), %rsi
movq -0x3b8(%rbp), %rdx
movq -0x3b0(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x153ff
jmp 0x15533
movq -0x278(%rbp), %rax
movq %rax, -0x3c8(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x3d8(%rbp), %rdi
leaq 0xe6bb(%rip), %rsi      # 0x23ae4
callq 0x18f40
movq -0x3c8(%rbp), %rdi
movq -0x3c0(%rbp), %rsi
movq -0x3d8(%rbp), %rdx
movq -0x3d0(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x15455
jmp 0x15464
movl $0x0, 0x180f9(%rip)     # 0x2d558
jmp 0x15701
movq -0x278(%rbp), %rax
movq %rax, -0x3e8(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x3e0(%rbp)
leaq -0x3f8(%rbp), %rdi
leaq 0xe65b(%rip), %rsi      # 0x23ae9
callq 0x18f40
movq -0x3e8(%rbp), %rdi
movq -0x3e0(%rbp), %rsi
movq -0x3f8(%rbp), %rdx
movq -0x3f0(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x154ba
jmp 0x154c9
movl $0x1, 0x18094(%rip)     # 0x2d558
jmp 0x15701
movq -0x278(%rbp), %rax
movq %rax, -0x408(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x400(%rbp)
leaq -0x418(%rbp), %rdi
leaq 0xe5fe(%rip), %rsi      # 0x23af1
callq 0x18f40
movq -0x408(%rbp), %rdi
movq -0x400(%rbp), %rsi
movq -0x418(%rbp), %rdx
movq -0x410(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x1551f
jmp 0x1552e
movl $0x2, 0x1802f(%rip)     # 0x2d558
jmp 0x15701
jmp 0x15701
movq -0x268(%rbp), %rax
movq %rax, -0x428(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x420(%rbp)
leaq -0x438(%rbp), %rdi
leaq 0xe599(%rip), %rsi      # 0x23af6
callq 0x18f40
movq -0x428(%rbp), %rdi
movq -0x420(%rbp), %rsi
movq -0x438(%rbp), %rdx
movq -0x430(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x1558c
jmp 0x1561c
movq -0x278(%rbp), %rax
movq %rax, -0x448(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0x458(%rbp), %rdi
leaq 0xe549(%rip), %rsi      # 0x23aff
callq 0x18f40
movq -0x448(%rbp), %rdi
movq -0x440(%rbp), %rsi
movq -0x458(%rbp), %rdx
movq -0x450(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x155e2
jmp 0x155f1
movl $0xffffffff, 0x17f5c(%rip) # imm = 0xFFFFFFFF
jmp 0x15701
leaq -0x278(%rbp), %rdi
callq 0x1c6c0
movq %rax, %rdi
callq 0x7670
movl %eax, 0x17f3d(%rip)     # 0x2d548
movl 0x17f37(%rip), %eax     # 0x2d548
movl %eax, 0x17f39(%rip)     # 0x2d550
jmp 0x15701
movq -0x268(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x460(%rbp)
leaq -0x478(%rbp), %rdi
leaq 0xe4be(%rip), %rsi      # 0x23b04
callq 0x18f40
movq -0x468(%rbp), %rdi
movq -0x460(%rbp), %rsi
movq -0x478(%rbp), %rdx
movq -0x470(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x15675
jmp 0x156ff
movq -0x278(%rbp), %rax
movq %rax, -0x488(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x480(%rbp)
leaq -0x498(%rbp), %rdi
leaq 0xe460(%rip), %rsi      # 0x23aff
callq 0x18f40
movq -0x488(%rbp), %rdi
movq -0x480(%rbp), %rsi
movq -0x498(%rbp), %rdx
movq -0x490(%rbp), %rcx
callq 0x1c560
testb $0x1, %al
jne 0x156cb
jmp 0x156d7
movl $0xffffffff, 0x17e77(%rip) # imm = 0xFFFFFFFF
jmp 0x15701
leaq -0x278(%rbp), %rdi
callq 0x1c6c0
movq %rax, %rdi
callq 0x7670
movl %eax, 0x17e5b(%rip)     # 0x2d54c
movl 0x17e55(%rip), %eax     # 0x2d54c
movl %eax, 0x17e57(%rip)     # 0x2d554
jmp 0x15701
jmp 0x15701
jmp 0x14d59
movb $0x1, -0x1(%rbp)
movl $0x1, -0x228(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x72c0
jmp 0x15730
leaq -0x248(%rbp), %rdi
callq 0x72c0
jmp 0x1574a
leaq -0x218(%rbp), %rdi
callq 0x70f0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x70f0
movq -0x220(%rbp), %rdi
callq 0x7710
nopw %cs:(%rax,%rax)
nopl (%rax)