// File: /workspace/github_cpp_makefile_star2_O1/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), %r13
movq %r13, %rdi
movl $0x4, %edx
callq 0x6590
leaq 0xe8(%rsp), %rdi
callq 0x60a0
movl %eax, %ebx
testb %al, %al
je 0xf845
movb %bl, 0xf(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x10(%rsp), %r15
movq %rbp, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6360
movsbl %al, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x65a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0xf851
cmpq $0x0, 0x18(%rsp)
je 0xf3dc
movq 0x10(%rsp), %rax
cmpb $0x23, (%rax)
je 0xf3dc
movq 0x18(%rsp), %rbp
testq %rbp, %rbp
je 0xf454
movq 0x10(%rsp), %rax
movzbl -0x1(%rax,%rbp), %eax
cmpl $0xd, %eax
je 0xf442
cmpl $0xa, %eax
jne 0xf454
decq %rbp
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x6110
jmp 0xf424
movq 0x10(%rsp), %r12
cmpb $0x5b, (%r12)
je 0xf7bb
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rbp, %rbp
je 0xf485
xorl %eax, %eax
cmpb $0x3d, (%r12,%rax)
je 0xf482
incq %rax
cmpq %rax, %rbp
jne 0xf471
jmp 0xf485
movl %eax, %r14d
testl %r14d, %r14d
js 0xf3dc
movl %r14d, %ebx
leaq 0x1(%rbx), %rax
leaq (%r12,%rbx), %r13
incq %r13
subq %rax, %rbp
movq %rbp, 0x30(%rsp)
movq %r13, 0x38(%rsp)
movq 0x40(%rsp), %rax
cmpl $0x2, %eax
je 0xf59d
cmpl $0x1, %eax
jne 0xf781
cmpl $0x3, %r14d
je 0xf50a
cmpl $0x9, %r14d
je 0xf558
cmpl $0x4, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x7543(%rip), %rsi      # 0x16a27
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf6b4
cmpl $0x9, %r14d
je 0xf558
cmpl $0x4, %r14d
je 0xf534
cmpl $0x3, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x754d(%rip), %rsi      # 0x16a61
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf689
cmpl $0x9, %r14d
je 0xf558
cmpl $0x4, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x73ca(%rip), %rsi      # 0x16908
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf753
cmpl $0x9, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x765c(%rip), %rsi      # 0x16bbe
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
jne 0xf781
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movl $0x2, %edx
callq 0x11028
leaq 0xcea0(%rip), %rdi      # 0x1c430
movq %rbx, %rsi
callq 0x10ed0
jmp 0xf779
cmpl $0x8, %r14d
je 0xf5dd
cmpl $0x9, %r14d
je 0xf5fd
cmpl $0xb, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x760b(%rip), %rsi      # 0x16bc8
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf6df
cmpl $0x9, %r14d
je 0xf5fd
cmpl $0x8, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x75ff(%rip), %rsi      # 0x16be6
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf650
cmpl $0x9, %r14d
jne 0xf781
movq %r12, %rdi
leaq 0x75ed(%rip), %rsi      # 0x16bf4
movq %rbx, %rdx
callq 0x63a0
testl %eax, %eax
jne 0xf781
cmpq $0x4, %rbp
jne 0xf637
movq %r13, %rdi
leaq 0x75c8(%rip), %rsi      # 0x16bef
movq %rbp, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf78b
movq %r13, %rdi
callq 0x64e0
movl %eax, 0xce07(%rip)      # 0x1c44c
movl %eax, 0xce09(%rip)      # 0x1c454
jmp 0xf781
cmpq $0x4, %rbp
jne 0xf670
movq %r13, %rdi
leaq 0x758f(%rip), %rsi      # 0x16bef
movq %rbp, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf797
movq %r13, %rdi
callq 0x64e0
movl %eax, 0xcdca(%rip)      # 0x1c448
movl %eax, 0xcdcc(%rip)      # 0x1c450
jmp 0xf781
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movl $0x2, %edx
callq 0x11028
leaq 0xcd41(%rip), %rdi      # 0x1c3e8
movq %rbx, %rsi
callq 0x10ed0
jmp 0xf779
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movl $0x2, %edx
callq 0x11028
leaq 0xcd2e(%rip), %rdi      # 0x1c400
movq %rbx, %rsi
callq 0x10ed0
jmp 0xf779
cmpq $0x7, %rbp
je 0xf715
cmpq $0x4, %rbp
jne 0xf781
movq %r13, %rdi
leaq 0x74db(%rip), %rsi      # 0x16bd4
movq %rbp, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf7af
cmpq $0x4, %rbp
je 0xf731
cmpq $0x7, %rbp
jne 0xf781
movq %r13, %rdi
leaq 0x74ba(%rip), %rsi      # 0x16bd9
movq %rbp, %rdx
callq 0x63a0
testl %eax, %eax
je 0xf7a3
cmpq $0x4, %rbp
jne 0xf781
movq %r13, %rdi
leaq 0x74a6(%rip), %rsi      # 0x16be1
movq %rbp, %rdx
callq 0x63a0
testl %eax, %eax
jne 0xf781
movl $0x2, 0xcd07(%rip)      # 0x1c458
jmp 0xf781
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movl $0x2, %edx
callq 0x11028
leaq 0xcca7(%rip), %rdi      # 0x1c418
movq %rbx, %rsi
callq 0x10ed0
movq %rbx, %rdi
callq 0xe8d0
leaq 0x70(%rsp), %r13
jmp 0xf3dc
movl $0xffffffff, 0xccb7(%rip) # imm = 0xFFFFFFFF
jmp 0xf781
movl $0xffffffff, 0xcca7(%rip) # imm = 0xFFFFFFFF
jmp 0xf781
movl $0x1, 0xccab(%rip)      # 0x1c458
jmp 0xf781
movl $0x0, 0xcc9f(%rip)      # 0x1c458
jmp 0xf781
movl $0x1, %ebp
leaq 0x73e6(%rip), %r14      # 0x16bad
cmpq %r14, %r12
je 0xf3d7
xorl %ebx, %ebx
movsbl (%r12,%rbx), %edi
testl %edi, %edi
jne 0xf7e6
cmpb $0x0, (%rbx,%r14)
je 0xf3d7
callq 0x64a0
movsbl (%rbx,%r14), %ecx
cmpl %ecx, %eax
jne 0xf7f9
incq %rbx
jmp 0xf7d2
movl $0x2, %ebp
leaq 0x73b0(%rip), %rax      # 0x16bb5
cmpq %rax, %r12
je 0xf3d7
xorl %ebx, %ebx
leaq 0x739e(%rip), %r14      # 0x16bb5
movsbl (%r12,%rbx), %edi
testl %edi, %edi
jne 0xf82b
cmpb $0x0, (%rbx,%r14)
je 0xf3d7
callq 0x64a0
movsbl (%rbx,%r14), %ecx
cmpl %ecx, %eax
jne 0xf83e
incq %rbx
jmp 0xf817
xorl %ebp, %ebp
jmp 0xf3d7
leaq 0x70(%rsp), %rdi
callq 0x6080
jmp 0xf871
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xf86d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6390
movb 0xf(%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 0xf89b
jmp 0xf8b3
jmp 0xf89b
jmp 0xf8b3
jmp 0xf89b
jmp 0xf8b3
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xe8d0
jmp 0xf8b6
jmp 0xf8b3
movq %rax, %rbx
jmp 0xf8d2
jmp 0xf8b3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xf8d2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6390
leaq 0x70(%rsp), %rdi
callq 0x60d0
movq %rbx, %rdi
callq 0x6550