// File: /workspace/github_cpp_makefile_star2_O1/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 0xe308
movq %rsi, %rbp
movslq %edi, %rax
movq %rax, 0x18(%rsp)
leaq 0x8(%rsi), %r13
leaq 0x8a79(%rip), %r15      # 0x16ab7
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 0xe0ae
cmpb $0x2d, 0x1(%r12)
jne 0xe0d0
movzbl 0x2(%r12), %eax
cmpl $0x73, %eax
je 0xe16d
cmpl $0x72, %eax
je 0xe160
cmpl $0x63, %eax
jne 0xe1ae
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xe1f2
cmpl $0x6f, %eax
je 0xe24c
jmp 0xe1ae
cmpq $0x0, 0x10(%rsp)
je 0xe130
cmpq $0x0, 0x8(%rsp)
je 0xe156
xorl %edi, %edi
leaq 0x8a14(%rip), %rsi      # 0x16adf
jmp 0xe1b7
incq %r12
xorl %eax, %eax
movb (%r12), %bpl
movzbl %bpl, %ecx
leal -0x63(%rcx), %edx
cmpl $0x10, %edx
ja 0xe0f2
btl %edx, %r14d
jae 0xe0f2
incq %r12
movl %ebp, %eax
jmp 0xe0d5
testl %ecx, %ecx
je 0xe108
movsbl %bpl, %edx
xorl %edi, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x64c0
jmp 0xe0eb
movzbl %al, %eax
cmpl $0x71, %eax
jg 0xe13a
cmpl $0x63, %eax
movq (%rsp), %rbp
je 0xe1ca
cmpl $0x70, %eax
jne 0xe1c6
movl $0x7, %eax
jmp 0xe1d6
movq %r12, 0x10(%rsp)
jmp 0xe2e6
cmpl $0x72, %eax
movq (%rsp), %rbp
je 0xe1d1
cmpl $0x73, %eax
jne 0xe1c6
movl $0xc, %eax
jmp 0xe1d6
movq %r12, 0x8(%rsp)
jmp 0xe2e6
cmpb $0x6f, 0x3(%r12)
jne 0xe1ae
jmp 0xe21f
movzbl 0x3(%r12), %eax
cmpl $0x61, %eax
je 0xe2b3
cmpl $0x63, %eax
jne 0xe1ae
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xef04
leaq 0xe28f(%rip), %rdi      # 0x1c430
movq %r12, %rsi
callq 0x10ed0
jmp 0xe2db
xorl %edi, %edi
leaq 0x88cc(%rip), %rsi      # 0x16a83
movq %r12, %rdx
xorl %eax, %eax
callq 0x64c0
jmp 0xe2e6
xorl %eax, %eax
jmp 0xe1d6
movl $0x8, %eax
jmp 0xe1d6
movl $0xa, %eax
leal -0x7(%rax), %ecx
cmpl $0x5, %ecx
ja 0xe304
leaq 0x5197(%rip), %rdx      # 0x13380
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xef04
leaq 0xe1ee(%rip), %rdi      # 0x1c400
movq %r12, %rsi
callq 0x10ed0
jmp 0xe2db
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xef04
leaq 0xe1a9(%rip), %rdi      # 0x1c3e8
movq %r12, %rsi
callq 0x10ed0
jmp 0xe2db
movq 0xe11d(%rip), %r13      # 0x1c370
movq 0xe11e(%rip), %rbp      # 0x1c378
cmpq %r13, %rbp
je 0xe27a
movq %r13, %r12
movq %r12, %rdi
callq 0xe8d0
addq $0x28, %r12
cmpq %rbp, %r12
jne 0xe262
movq %r13, 0xe0fe(%rip)      # 0x1c378
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xef04
leaq 0xe0d6(%rip), %rdi      # 0x1c370
movq %r12, %rsi
callq 0x10ed0
movq %r12, %rdi
callq 0xe8d0
movq %rbx, %r13
movq (%rsp), %rbp
jmp 0xe2e6
addq $0x10, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xef04
leaq 0xe145(%rip), %rdi      # 0x1c418
movq %r12, %rsi
callq 0x10ed0
movq %r12, %rdi
callq 0xe8d0
movq %rbx, %r13
movq %r13, %rbx
addq $0x8, %r13
movq %r13, %rax
subq %rbp, %rax
sarq $0x3, %rax
cmpq 0x18(%rsp), %rax
jl 0xe05d
jmp 0xe308
testl %eax, %eax
je 0xe2e6
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe321
jmp 0xe321
jmp 0xe321
jmp 0xe321
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xe8d0
movq %rbx, %rdi
callq 0x6550