// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsi, %rbp
movslq %edi, %rax
movq %rax, 0x18(%rsp)
movl $0x1a001, %r14d         # imm = 0x1A001
xorl %eax, %eax
xorl %ecx, %ecx
movq %rsi, %r13
movq %rsi, 0x10(%rsp)
movq %r13, %r15
movq %rax, %rbx
addq $0x8, %r13
movq %r13, %rax
subq %rbp, %rax
sarq $0x3, %rax
cmpq 0x18(%rsp), %rax
jge 0xcb64
movq %rcx, %rdx
movq (%r13), %r12
cmpb $0x2d, (%r12)
jne 0xc994
movb 0x1(%r12), %cl
cmpb $0x2d, %cl
movq %rdx, 0x8(%rsp)
jne 0xc9d3
movzbl 0x2(%r12), %eax
cmpl $0x73, %eax
je 0xcace
cmpl $0x72, %eax
je 0xca9e
cmpl $0x63, %eax
jne 0xcb06
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xca3d
cmpl $0x6f, %eax
je 0xca68
jmp 0xcb06
movq %r12, %rax
movq %rdx, %rcx
testq %rbx, %rbx
je 0xc91a
movq %rbx, %rax
movq %r12, %rcx
testq %rdx, %rdx
je 0xc91a
xorl %edi, %edi
leaq 0x8144(%rip), %rsi      # 0x14aff
movq %rdx, %r15
movq %r12, %rdx
xorl %eax, %eax
callq 0x64f0
movq %rbx, %rax
movq %r15, %rcx
jmp 0xc91a
addq $0x2, %r12
xorl %eax, %eax
movl %ecx, %ebp
movzbl %cl, %ecx
leal -0x63(%rcx), %edx
cmpl $0x10, %edx
ja 0xc9f7
btl %edx, %r14d
jae 0xc9f7
movb (%r12), %cl
incq %r12
movl %ebp, %eax
jmp 0xc9d9
testl %ecx, %ecx
je 0xca11
movsbl %bpl, %edx
xorl %edi, %edi
leaq 0x80cf(%rip), %rsi      # 0x14ad7
xorl %eax, %eax
callq 0x64f0
jmp 0xc9ec
cmpb $0x63, %al
movq 0x10(%rsp), %rbp
je 0xca68
movzbl %al, %edx
cmpl $0x70, %edx
je 0xca3d
cmpl $0x72, %edx
je 0xcaa6
movq %rbx, %rax
movq 0x8(%rsp), %rcx
cmpl $0x73, %edx
je 0xcb26
jmp 0xc91a
addq $0x10, %r15
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0xd7e4
leaq 0xe9b5(%rip), %rdi      # 0x1b410
movq %r12, %rsi
callq 0xf640
jmp 0xcb4c
addq $0x10, %r15
leaq 0xe90d(%rip), %r13      # 0x1b380
movq %r13, %rdi
callq 0xd41a
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0xd7e4
movq %r13, %rdi
movq %r12, %rsi
callq 0xf640
jmp 0xcb4c
cmpb $0x6f, 0x3(%r12)
jne 0xcb06
addq $0x10, %r15
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0xd7e4
leaq 0xe934(%rip), %rdi      # 0x1b3f8
movq %r12, %rsi
callq 0xf640
jmp 0xcb4c
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xcb26
cmpl $0x63, %eax
jne 0xcb06
addq $0x10, %r15
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0xd7e4
leaq 0xe944(%rip), %rdi      # 0x1b440
movq %r12, %rsi
callq 0xf640
jmp 0xcb4c
xorl %edi, %edi
leaq 0x7f94(%rip), %rsi      # 0x14aa3
movq %r12, %rdx
xorl %eax, %eax
callq 0x64f0
movq %rbx, %rax
movq 0x8(%rsp), %rcx
jmp 0xc91a
addq $0x10, %r15
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0xd7e4
leaq 0xe8e4(%rip), %rdi      # 0x1b428
movq %r12, %rsi
callq 0xf640
movq %r12, %rdi
callq 0xd08a
movq %rbx, %rax
movq 0x8(%rsp), %rcx
movq %r15, %r13
jmp 0xc91a
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcb7d
jmp 0xcb7d
jmp 0xcb7d
jmp 0xcb7d
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xd08a
movq %rbx, %rdi
callq 0x6580