// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rdi, %rsi
leaq 0x60(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x65c0
leaq 0xd8(%rsp), %rdi
callq 0x60b0
movl %eax, %ebx
testb %al, %al
je 0xdf30
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r13d, %r13d
leaq 0x60(%rsp), %r14
leaq 0x18(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x6080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xdf3c
cmpq $0x0, 0x20(%rsp)
je 0xdbd1
movq 0x18(%rsp), %rax
cmpb $0x23, (%rax)
je 0xdbd1
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0xdc2b
movzbl -0x1(%rbp,%rsi), %eax
cmpl $0xd, %eax
je 0xdc1e
cmpl $0xa, %eax
jne 0xdc2b
decq %rsi
movq %r15, %rdi
callq 0x64a0
jmp 0xdc00
cmpb $0x5b, (%rbp)
je 0xde42
xorl %eax, %eax
cmpq %rax, %rsi
je 0xdbd1
cmpb $0x3d, (%rbp,%rax)
je 0xdc48
incq %rax
jmp 0xdc37
movl %eax, %r12d
incl %eax
leaq (%rax,%rbp), %rcx
subq %rax, %rsi
movq %rsi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
cmpl $0x2, %r13d
je 0xdcb0
cmpl $0x1, %r13d
jne 0xdbd1
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x4
popq %rdx
leaq 0x6dc9(%rip), %rcx      # 0x14a47
callq 0xf7a2
testb %al, %al
je 0xdcf6
leaq 0x38(%rsp), %r12
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0xf7d6
leaq 0xd76d(%rip), %rdi      # 0x1b410
movq %r12, %rsi
callq 0xf640
jmp 0xdebd
movq %r12, %rdi
movq %rbp, %rsi
pushq $0xb
popq %rdx
leaq 0x6f28(%rip), %rcx      # 0x14be8
callq 0xf7a2
testb %al, %al
je 0xdd38
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x6f17(%rip), %rcx      # 0x14bf4
callq 0xf7a2
testb %al, %al
je 0xddc8
andl $0x0, 0xd777(%rip)      # 0x1b468
jmp 0xdbd1
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x3
popq %rdx
leaq 0x6d7b(%rip), %rcx      # 0x14a81
callq 0xf7a2
testb %al, %al
je 0xdd82
leaq 0x38(%rsp), %r12
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0xf7d6
leaq 0xd6cd(%rip), %rdi      # 0x1b3f8
movq %r12, %rsi
callq 0xf640
jmp 0xdebd
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x8
popq %rdx
leaq 0x6ebe(%rip), %rcx      # 0x14c06
callq 0xf7a2
testb %al, %al
je 0xddf8
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x6ea6(%rip), %rcx      # 0x14c0f
callq 0xf7a2
testb %al, %al
je 0xdeca
orl $-0x1, 0xd6db(%rip)     # 0x1b458
jmp 0xdbd1
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x4
popq %rdx
leaq 0x6b96(%rip), %rcx      # 0x14928
callq 0xf7a2
testb %al, %al
je 0xde7c
leaq 0x38(%rsp), %r12
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0xf7d6
leaq 0xd66d(%rip), %rdi      # 0x1b428
movq %r12, %rsi
callq 0xf640
jmp 0xdebd
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x7
popq %rdx
leaq 0x6e1d(%rip), %rcx      # 0x14bf9
callq 0xf7a2
testb %al, %al
je 0xdee5
movl $0x1, 0xd675(%rip)      # 0x1b468
jmp 0xdbd1
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x9
popq %rdx
leaq 0x6e0c(%rip), %rcx      # 0x14c14
callq 0xf7a2
testb %al, %al
je 0xdbd1
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x6de6(%rip), %rcx      # 0x14c0f
callq 0xf7a2
testb %al, %al
je 0xdf15
orl $-0x1, 0xd61f(%rip)     # 0x1b45c
jmp 0xdbd1
movq %rbp, %rdi
leaq 0x6d81(%rip), %rsi      # 0x14bcd
callq 0xd437
pushq $0x1
popq %rcx
movl %ecx, %r13d
testb %al, %al
jne 0xdbd1
movq 0x18(%rsp), %rdi
leaq 0x6d6a(%rip), %rsi      # 0x14bd5
callq 0xd437
movzbl %al, %r13d
addl %r13d, %r13d
jmp 0xdbd1
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x9
popq %rdx
leaq 0x6d52(%rip), %rcx      # 0x14bde
callq 0xf7a2
testb %al, %al
je 0xdbd1
leaq 0x38(%rsp), %r12
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0xf7d6
leaq 0xd58b(%rip), %rdi      # 0x1b440
movq %r12, %rsi
callq 0xf640
movq %r12, %rdi
callq 0xd08a
jmp 0xdbd1
movq 0x10(%rsp), %rdi
callq 0x6510
movl %eax, 0xd57e(%rip)      # 0x1b458
movl %eax, 0xd580(%rip)      # 0x1b460
jmp 0xdbd1
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x6d08(%rip), %rcx      # 0x14c01
callq 0xf7a2
testb %al, %al
je 0xdbd1
movl $0x2, 0xd558(%rip)      # 0x1b468
jmp 0xdbd1
movq 0x10(%rsp), %rdi
callq 0x6510
movl %eax, 0xd537(%rip)      # 0x1b45c
movl %eax, 0xd539(%rip)      # 0x1b464
jmp 0xdbd1
leaq 0x60(%rsp), %rdi
callq 0x6090
jmp 0xdf46
leaq 0x18(%rsp), %rdi
callq 0x61c0
leaq 0x60(%rsp), %rdi
callq 0x60e0
movl %ebx, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdf70
jmp 0xdf88
jmp 0xdf70
jmp 0xdf88
jmp 0xdf88
jmp 0xdf70
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xd08a
jmp 0xdf8b
jmp 0xdf88
movq %rax, %rbx
jmp 0xdf95
jmp 0xdf88
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x61c0
leaq 0x60(%rsp), %rdi
callq 0x60e0
movq %rbx, %rdi
callq 0x6580