// File: /workspace/github_cpp_makefile_star2_O3/mdpkh[P]retro6k/src/main.cpp
// Function: ReadArgs(int, char**)
int ReadArgs(int argc, char** argv)
{
	// TODO: read command-line arguments.
	char* cartspec = nullptr;
	char* savespec = nullptr;
	for (char** thisargptr = argv + 1; thisargptr - argv < argc; ++thisargptr)
	{
		if ((*thisargptr)[0] == '-')
		{
			if ((*thisargptr)[1] == '-')
			{
				// long option
#define WARN_NOMATCH default: \
                       SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, \
                         "Command line option %s " \
				         "ambiguous or not understood.", \
                         *thisargptr);
				switch ((*thisargptr)[2])
				{
				case 'c':
					switch ((*thisargptr)[3])
					{
					case 'a': //--ca(rtpath): specify cart path
						goto readcartpathparameter;
					case 'o': //--co(nfigfile): specify config file location
						goto readconfigfileparameter;
					WARN_NOMATCH
					}
					break;
				case 'r':
					switch ((*thisargptr)[3])
					{
					case 'o': //--ro(mpath): specify rom path
						goto readrompathparameter;
						WARN_NOMATCH
					}
					break;
				case 's':
					switch ((*thisargptr)[3])
					{
					case 'a': //--sa(vepath): specify save path
						goto readsavepathparameter;
					case 'c': //--sc(reencappath): specify save path
						goto readscreencappathparameter;
						WARN_NOMATCH
					}
					break;
					WARN_NOMATCH
				}
#undef WARN_NOMATCH
			}
			else
			{
				// short option(s) / switch(es)
				char lastshort = 0;
				for (char* thisshortptr = (*thisargptr) + 1; 
					*thisshortptr; ++thisshortptr)
				{
					lastshort = *thisshortptr;
					switch (lastshort)
					{
						// handlers for each short option / switch
					case 'c': // specify config file location
					case 'p': // specify cart path
					case 'r': // specify rom path
					case 's': // specify save path
						break;
					default:
						SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
							"Command line switch -%c not understood.",
							lastshort);
					}
				}
				switch (lastshort)
				{
				case 'c':
					goto readconfigfileparameter;
				case 'p':
					goto readcartpathparameter;
				case 'r':
					goto readrompathparameter;
				case 's':
					goto readsavepathparameter;
					// jumps for next-argument reading
				default:
					;
				}
			}
			continue;
			// labels for reading next argument as parameter to an option
		readconfigfileparameter:
			// config file spec, if given, should become
			//only item of config.system.configloc
			++thisargptr;
			config.system.configloc.clear();
			config.system.configloc.push_back(
				std::filesystem::path(*thisargptr));
			continue;
		readcartpathparameter:
			++thisargptr;
			config.sessionpath.cartpath.push_back(
				std::filesystem::path(*thisargptr));
			continue;
		readrompathparameter:
			++thisargptr;
			config.sessionpath.rompath.push_back(
				std::filesystem::path(*thisargptr));
			continue;
		readsavepathparameter:
			++thisargptr;
			config.sessionpath.savepath.push_back(
				std::filesystem::path(*thisargptr));
			continue;
		readscreencappathparameter:
			++thisargptr;
			config.sessionpath.screencappath.push_back(
				std::filesystem::path(*thisargptr));
			continue;
		}
		else
		{
			// positional argument
			if (cartspec == nullptr)
			{
				cartspec = *thisargptr;
				continue;
			}
			if (savespec == nullptr)
			{
				savespec = *thisargptr;
				continue;
			}
			SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
				"Command line argument %s not understood.",
				*thisargptr);
		}
	}
    // TODO: actually do something with cartspec and savespec if they are non-null
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x2, %edi
jl 0xe8e3
movq %rsi, %rbp
movslq %edi, %rax
movq %rax, 0x18(%rsp)
leaq 0x8(%rsi), %r13
leaq 0x8537(%rip), %r15      # 0x16ba7
movl $0x1a001, %r14d         # imm = 0x1A001
movq %rsi, %rbx
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rsi, (%rsp)
movq 0x8(%rbx), %r12
cmpb $0x2d, (%r12)
jne 0xe6e2
movb 0x1(%r12), %cl
cmpb $0x2d, %cl
jne 0xe708
movzbl 0x2(%r12), %eax
cmpl $0x73, %eax
je 0xe845
cmpl $0x72, %eax
je 0xe813
cmpl $0x63, %eax
jne 0xe87f
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xe75c
cmpl $0x6f, %eax
je 0xe7b4
jmp 0xe87f
cmpq $0x0, 0x10(%rsp)
je 0xe789
cmpq $0x0, 0x8(%rsp)
je 0xe7aa
xorl %edi, %edi
leaq 0x84cc(%rip), %rsi      # 0x16bcf
jmp 0xe888
addq $0x2, %r12
xorl %eax, %eax
movl %ecx, %ebp
movzbl %cl, %ecx
leal -0x63(%rcx), %edx
cmpl $0x10, %edx
ja 0xe72c
btl %edx, %r14d
jae 0xe72c
movb (%r12), %cl
incq %r12
movl %ebp, %eax
jmp 0xe70e
testl %ecx, %ecx
je 0xe742
movsbl %bpl, %edx
xorl %edi, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x64c0
jmp 0xe721
movzbl %al, %eax
cmpl $0x71, %eax
jg 0xe793
cmpl $0x63, %eax
movq (%rsp), %rbp
je 0xe7b4
cmpl $0x70, %eax
jne 0xe8c7
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf4ec
leaq 0xdc84(%rip), %rdi      # 0x1c400
movq %r12, %rsi
callq 0x1146a
jmp 0xe8bc
movq %r12, 0x10(%rsp)
jmp 0xe8c7
cmpl $0x72, %eax
movq (%rsp), %rbp
je 0xe81b
cmpl $0x73, %eax
je 0xe894
jmp 0xe8c7
movq %r12, 0x8(%rsp)
jmp 0xe8c7
movq 0xdbb5(%rip), %r13      # 0x1c370
movq 0xdbb6(%rip), %rbp      # 0x1c378
cmpq %r13, %rbp
je 0xe7e2
movq %r13, %r12
movq %r12, %rdi
callq 0xeeb0
addq $0x28, %r12
cmpq %rbp, %r12
jne 0xe7ca
movq %r13, 0xdb96(%rip)      # 0x1c378
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf4ec
leaq 0xdb6e(%rip), %rdi      # 0x1c370
movq %r12, %rsi
callq 0x1146a
movq (%rsp), %rbp
jmp 0xe8bc
cmpb $0x6f, 0x3(%r12)
jne 0xe87f
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf4ec
leaq 0xdbad(%rip), %rdi      # 0x1c3e8
movq %r12, %rsi
callq 0x1146a
jmp 0xe8bc
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xe894
cmpl $0x63, %eax
jne 0xe87f
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf4ec
leaq 0xdbbb(%rip), %rdi      # 0x1c430
movq %r12, %rsi
callq 0x1146a
jmp 0xe8bc
xorl %edi, %edi
leaq 0x82eb(%rip), %rsi      # 0x16b73
movq %r12, %rdx
xorl %eax, %eax
callq 0x64c0
jmp 0xe8c7
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf4ec
leaq 0xdb64(%rip), %rdi      # 0x1c418
movq %r12, %rsi
callq 0x1146a
movq %r12, %rdi
callq 0xeeb0
movq %rbx, %r13
movq %r13, %rbx
addq $0x8, %r13
movq %r13, %rax
subq %rbp, %rax
sarq $0x3, %rax
cmpq 0x18(%rsp), %rax
jl 0xe68f
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe8fc
jmp 0xe8fc
jmp 0xe8fc
jmp 0xe8fc
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xeeb0
movq %rbx, %rdi
callq 0x6550