// File: /workspace/github_cpp_makefile_star2_O3/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 $0x278, %rsp            # imm = 0x278
movq %rdi, %rsi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl $0x4, %edx
callq 0x6590
leaq 0xe8(%rsp), %rdi
callq 0x60a0
movl %eax, %ebx
testb %al, %al
je 0xfdd5
movb %bl, 0x7(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebx, %ebx
leaq 0x8(%rsp), %r15
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6360
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x65a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xfde1
cmpq $0x0, 0x10(%rsp)
je 0xf9bf
movq 0x8(%rsp), %r13
cmpb $0x23, (%r13)
je 0xf9bf
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0xfa3a
movzbl -0x1(%r13,%r12), %eax
cmpl $0xd, %eax
je 0xfa23
cmpl $0xa, %eax
jne 0xfa4a
decq %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x6110
movq 0x8(%rsp), %r13
jmp 0xfa09
cmpb $0x5b, (%r13)
jne 0xf9bf
jmp 0xfbb4
cmpb $0x5b, (%r13)
je 0xfbb4
xorl %ebp, %ebp
cmpb $0x3d, (%r13,%rbp)
je 0xfa6c
incq %rbp
cmpq %rbp, %r12
jne 0xfa57
jmp 0xf9bf
movl %ebp, %edx
leal 0x1(%rbp), %eax
movq %rbx, %rcx
leaq (%rax,%r13), %rbx
subq %rax, %r12
movq %r12, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
cmpl $0x2, %ecx
movq %rcx, 0x40(%rsp)
je 0xfb39
cmpl $0x1, %ecx
jne 0xfd85
cmpl $0x3, %ebp
je 0xfc55
cmpl $0x9, %ebp
je 0xfaf7
cmpl $0x4, %ebp
jne 0xfd85
movq %r13, %rdi
leaq 0x705a(%rip), %rsi      # 0x16b17
movq %rdx, %rbx
callq 0x63a0
testl %eax, %eax
je 0xfd00
movq %r13, %rdi
leaq 0x6f21(%rip), %rsi      # 0x169f8
movq %rbx, %r12
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xfd57
cmpq $0x9, %rbp
movq %r12, %rdx
jne 0xfd85
movq %r13, %rdi
leaq 0x71ad(%rip), %rsi      # 0x16cae
callq 0x63a0
testl %eax, %eax
jne 0xfd85
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
movl $0x2, %edx
callq 0x115c8
leaq 0xc904(%rip), %rdi      # 0x1c430
movq %rbx, %rsi
callq 0x1146a
jmp 0xfd7d
cmpl $0x8, %ebp
je 0xfc97
cmpl $0x9, %ebp
je 0xfcbe
cmpl $0xb, %ebp
jne 0xfd85
movq %r13, %rdi
leaq 0x715a(%rip), %rsi      # 0x16cb8
callq 0x63a0
testl %eax, %eax
jne 0xfd85
cmpq $0x7, %r12
je 0xfd8f
cmpq $0x4, %r12
jne 0xfd85
cmpl $0x65657266, (%rbx)     # imm = 0x65657266
je 0xfdc9
movq %rbx, %rdi
leaq 0x713c(%rip), %rsi      # 0x16cd1
movq %r12, %rdx
callq 0x63a0
testl %eax, %eax
jne 0xfd85
movl $0x2, 0xc8a9(%rip)      # 0x1c458
jmp 0xfd85
movl $0x1, %ebx
leaq 0x70dd(%rip), %r12      # 0x16c9d
cmpq %r12, %r13
je 0xf9bf
movb $0x5b, %bpl
movl $0x1, %ebx
movb $0x5b, %al
movsbl %al, %edi
callq 0x64a0
movsbl %bpl, %ecx
cmpl %ecx, %eax
jne 0xfbff
movb (%r13,%rbx), %al
movb (%rbx,%r12), %bpl
incq %rbx
movl %ebp, %ecx
orb %al, %cl
jne 0xfbd3
movl $0x1, %ebx
jmp 0xf9bf
movl $0x2, %ebx
leaq 0x709a(%rip), %rax      # 0x16ca5
cmpq %rax, %r13
je 0xf9bf
movb $0x5b, %bpl
movl $0x1, %ebx
movb $0x5b, %al
leaq 0x7080(%rip), %r12      # 0x16ca5
movsbl %al, %edi
callq 0x64a0
movsbl %bpl, %ecx
cmpl %ecx, %eax
jne 0xfd50
movb (%r13,%rbx), %al
movb (%rbx,%r12), %bpl
incq %rbx
movl %ebp, %ecx
orb %al, %cl
jne 0xfc25
movl $0x2, %ebx
jmp 0xf9bf
movq %r13, %rdi
leaq 0x6ef2(%rip), %rsi      # 0x16b51
callq 0x63a0
testl %eax, %eax
jne 0xfd85
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
movl $0x2, %edx
callq 0x115c8
leaq 0xc75e(%rip), %rdi      # 0x1c3e8
movq %rbx, %rsi
callq 0x1146a
jmp 0xfd7d
movq %r13, %rdi
leaq 0x7035(%rip), %rsi      # 0x16cd6
movq %rdx, 0x38(%rsp)
callq 0x63a0
testl %eax, %eax
je 0xfd28
cmpq $0x9, %rbp
movq 0x38(%rsp), %rdx
jne 0xfd85
movq %r13, %rdi
leaq 0x701c(%rip), %rsi      # 0x16ce4
callq 0x63a0
testl %eax, %eax
jne 0xfd85
cmpq $0x4, %r12
jne 0xfce7
cmpl $0x6f747561, (%rbx)     # imm = 0x6F747561
je 0xfdb1
movq %rbx, %rdi
callq 0x64e0
movl %eax, 0xc757(%rip)      # 0x1c44c
movl %eax, 0xc759(%rip)      # 0x1c454
jmp 0xfd85
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
movl $0x2, %edx
callq 0x115c8
leaq 0xc6e2(%rip), %rdi      # 0x1c400
movq %rbx, %rsi
callq 0x1146a
jmp 0xfd7d
cmpq $0x4, %r12
jne 0xfd3a
cmpl $0x6f747561, (%rbx)     # imm = 0x6F747561
je 0xfdbd
movq %rbx, %rdi
callq 0x64e0
movl %eax, 0xc700(%rip)      # 0x1c448
movl %eax, 0xc702(%rip)      # 0x1c450
jmp 0xfd85
xorl %ebx, %ebx
jmp 0xf9bf
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
movl $0x2, %edx
callq 0x115c8
leaq 0xc6a3(%rip), %rdi      # 0x1c418
movq %rbx, %rsi
callq 0x1146a
movq %rbx, %rdi
callq 0xeeb0
movq 0x40(%rsp), %rbx
jmp 0xf9bf
movq %rbx, %rdi
leaq 0x6f30(%rip), %rsi      # 0x16cc9
movq %r12, %rdx
callq 0x63a0
testl %eax, %eax
jne 0xfd85
movl $0x1, 0xc6a9(%rip)      # 0x1c458
jmp 0xfd85
movl $0xffffffff, 0xc691(%rip) # imm = 0xFFFFFFFF
jmp 0xfd85
movl $0xffffffff, 0xc681(%rip) # imm = 0xFFFFFFFF
jmp 0xfd85
movl $0x0, 0xc685(%rip)      # 0x1c458
jmp 0xfd85
leaq 0x70(%rsp), %rdi
callq 0x6080
jmp 0xfe01
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xfdfd
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6390
movb 0x7(%rsp), %bl
leaq 0x70(%rsp), %rdi
callq 0x60d0
movl %ebx, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfe2b
jmp 0xfe43
jmp 0xfe2b
jmp 0xfe43
jmp 0xfe2b
jmp 0xfe43
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xeeb0
jmp 0xfe46
jmp 0xfe43
movq %rax, %rbx
jmp 0xfe62
jmp 0xfe43
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xfe62
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6390
leaq 0x70(%rsp), %rdi
callq 0x60d0
movq %rbx, %rdi
callq 0x6550