// File: FreeSlave[P]vhlt/common/cmdlinecfg.cpp
// Function: ParseParamFile(int, char**, int&, char**&)
void ParseParamFile (const int argc, char ** const argv, int &argcnew, char **&argvnew)
{
	char token[MAXTOKEN], words[MAXTOKEN], cmdline[MAXTOKEN];
	FILE *f;
	char *s;
	const char *c, *c0;
	char filepath[_MAX_PATH];
	s = NULL;

	char tmp[_MAX_PATH];
#ifdef SYSTEM_WIN32
	GetModuleFileName (NULL, tmp, _MAX_PATH);
#else
	safe_strncpy (tmp, argv[0], _MAX_PATH);
#endif
	ExtractFilePath (tmp, filepath);
	strcat (filepath, paramfilename);
	f = fopen (filepath, "r");
	if (f)
	{
		int len = 0x100000;
		s = (char *)malloc (len+1);
		if (s)
		{
			int i, j;
			for (i=0; j=fgetc (f), i<len && j!=EOF; i++)
				s[i] = j;
			s[i] = '\0';
		}
		fclose (f);
	}
	if (s)
	{
		c = s;
		execute_t e;
		memset (&e, 0, sizeof (e));
		strcpy (words, "");
		strcpy (token, "");
		parsearg (argc, argv, cmdline, MAXTOKEN);
		while (1)
		{
			while (1)
			{
				c = nextword (c, token, MAXTOKEN);
				if (token[0] == '#' || !c)
					break;
			}
			if (!c)
				break;
			if (strlen (token) + strlen (SEPSTR) + 1 <= MAXTOKEN)
			{
				strcpy (words, token);
				strcat (words, SEPSTR);
			}
			else
			{
				error = true;
				break;
			}
			while (1)
			{
				c0 = c;
				c = nextword (c, token, MAXTOKEN);
				if (token[0] == '#' || !c)
				{
					c = c0;
					break;
				}
				if (strlen (words) + strlen (token) + strlen (SEPSTR) + 1 <= MAXTOKEN)
				{
					strcat (words, token);
					strcat (words, SEPSTR);
				}
				else
				{
					error = true;
					break;
				}
			}
			parsecommand (e, cmdline, words, MAXTOKEN);
		}
		unparsearg (argcnew, argvnew, cmdline);
		if (error)
		{
			argvnew = argv;
			argcnew = argc;
		}
		argvnew[0] = argv[0];
		free (s);
	}
	else
	{
		argvnew = argv;
		argcnew = argc;
	}
}

// Assembly:
subq $0x5078, %rsp           # imm = 0x5078
movl %edi, 0x5074(%rsp)
movq %rsi, 0x5068(%rsp)
movq %rdx, 0x5060(%rsp)
movq %rcx, 0x5058(%rsp)
movq $0x0, 0x2040(%rsp)
leaq 0x30(%rsp), %rdi
movq 0x5068(%rsp), %rax
movq (%rax), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x9af0
leaq 0x30(%rsp), %rdi
leaq 0x1030(%rsp), %rsi
callq 0x96d0
leaq 0x1030(%rsp), %rdi
leaq 0x1fed3(%rip), %rsi     # 0x2a8a0
callq 0x4670
leaq 0x1030(%rsp), %rdi
leaq 0x22707(%rip), %rsi     # 0x2d0e8
callq 0x4460
movq %rax, 0x2048(%rsp)
cmpq $0x0, 0x2048(%rsp)
je 0xaaa7
movl $0x100000, 0x2c(%rsp)   # imm = 0x100000
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x4500
movq %rax, 0x2040(%rsp)
cmpq $0x0, 0x2040(%rsp)
je 0xaa9a
movl $0x0, 0x28(%rsp)
movq 0x2048(%rsp), %rdi
callq 0x45e0
movl %eax, 0x24(%rsp)
movl 0x28(%rsp), %ecx
xorl %eax, %eax
cmpl 0x2c(%rsp), %ecx
movb %al, 0x17(%rsp)
jge 0xaa5c
cmpl $-0x1, 0x24(%rsp)
setne %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0xaa66
jmp 0xaa89
movl 0x24(%rsp), %eax
movb %al, %dl
movq 0x2040(%rsp), %rax
movslq 0x28(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0xaa2f
movq 0x2040(%rsp), %rax
movslq 0x28(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x2048(%rsp), %rdi
callq 0x43a0
cmpq $0x0, 0x2040(%rsp)
je 0xad2b
movq 0x2040(%rsp), %rax
movq %rax, 0x2038(%rsp)
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4210
leaq 0x3050(%rsp), %rdi
leaq 0x21253(%rip), %rsi     # 0x2bd39
callq 0x4380
leaq 0x4050(%rsp), %rdi
leaq 0x2123f(%rip), %rsi     # 0x2bd39
callq 0x4380
movl 0x5074(%rsp), %edi
movq 0x5068(%rsp), %rsi
leaq 0x2050(%rsp), %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0xa6b0
jmp 0xab22
movq 0x2038(%rsp), %rdi
leaq 0x4050(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0xa510
movq %rax, 0x2038(%rsp)
movsbl 0x4050(%rsp), %eax
cmpl $0x23, %eax
je 0xab5c
cmpq $0x0, 0x2038(%rsp)
jne 0xab5e
jmp 0xab60
jmp 0xab22
cmpq $0x0, 0x2038(%rsp)
jne 0xab70
jmp 0xacb9
leaq 0x4050(%rsp), %rdi
callq 0x41c0
addq $0x1, %rax
addq $0x1, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0xabb8
leaq 0x3050(%rsp), %rdi
leaq 0x4050(%rsp), %rsi
callq 0x4380
leaq 0x3050(%rsp), %rdi
leaq 0x21187(%rip), %rsi     # 0x2bd38
callq 0x4670
jmp 0xabc4
movb $0x1, 0x20c28f9(%rip)   # 0x20cd4b8
jmp 0xacb9
jmp 0xabc6
movq 0x2038(%rsp), %rax
movq %rax, 0x2030(%rsp)
movq 0x2038(%rsp), %rdi
leaq 0x4050(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0xa510
movq %rax, 0x2038(%rsp)
movsbl 0x4050(%rsp), %eax
cmpl $0x23, %eax
je 0xac10
cmpq $0x0, 0x2038(%rsp)
jne 0xac22
movq 0x2030(%rsp), %rax
movq %rax, 0x2038(%rsp)
jmp 0xac95
leaq 0x3050(%rsp), %rdi
callq 0x41c0
movq %rax, 0x8(%rsp)
leaq 0x4050(%rsp), %rdi
callq 0x41c0
movq %rax, %rcx
movq 0x8(%rsp), %rax
addq %rcx, %rax
addq $0x1, %rax
addq $0x1, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0xac87
leaq 0x3050(%rsp), %rdi
leaq 0x4050(%rsp), %rsi
callq 0x4670
leaq 0x3050(%rsp), %rdi
leaq 0x210b8(%rip), %rsi     # 0x2bd38
callq 0x4670
jmp 0xac90
movb $0x1, 0x20c282a(%rip)   # 0x20cd4b8
jmp 0xac95
jmp 0xabc6
leaq 0x2050(%rsp), %rsi
leaq 0x3050(%rsp), %rdx
leaq 0x18(%rsp), %rdi
movl $0x1000, %ecx           # imm = 0x1000
callq 0xa260
jmp 0xab20
movq 0x5060(%rsp), %rdi
movq 0x5058(%rsp), %rsi
leaq 0x2050(%rsp), %rdx
callq 0xa7c0
testb $0x1, 0x20c27db(%rip)   # 0x20cd4b8
je 0xad03
movq 0x5068(%rsp), %rcx
movq 0x5058(%rsp), %rax
movq %rcx, (%rax)
movl 0x5074(%rsp), %ecx
movq 0x5060(%rsp), %rax
movl %ecx, (%rax)
movq 0x5068(%rsp), %rax
movq (%rax), %rcx
movq 0x5058(%rsp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq 0x2040(%rsp), %rdi
callq 0x4470
jmp 0xad4f
movq 0x5068(%rsp), %rcx
movq 0x5058(%rsp), %rax
movq %rcx, (%rax)
movl 0x5074(%rsp), %ecx
movq 0x5060(%rsp), %rax
movl %ecx, (%rax)
addq $0x5078, %rsp           # imm = 0x5078
retq
nopw (%rax,%rax)