// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5038, %rsp           # imm = 0x5038
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movl %edi, %ebp
movq (%rsi), %rsi
leaq 0x4030(%rsp), %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
callq 0x8ae9
leaq 0x1030(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x874d
movq %r14, %rdi
callq 0x4180
movabsq $0x73676e6974746573, %rcx # imm = 0x73676E6974746573
movq %rcx, 0x1030(%rsp,%rax)
movabsq $0x7478742e73676e, %rcx # imm = 0x7478742E73676E
movq %rcx, 0x1035(%rsp,%rax)
leaq 0x15a6d(%rip), %rsi     # 0x1f058
movq %r14, %rdi
callq 0x4380
testq %rax, %rax
je 0x9655
movq %rax, %rbx
movl $0x100001, %edi         # imm = 0x100001
callq 0x4420
testq %rax, %rax
je 0x964d
movq %rax, %r14
movq %r15, 0x18(%rsp)
movq %rbx, %rdi
callq 0x4500
cmpl $-0x1, %eax
movq %r12, 0x8(%rsp)
movl %ebp, 0x4(%rsp)
je 0x9661
xorl %r15d, %r15d
movq %r15, %r12
movb %al, (%r14,%r15)
incq %r15
movq %rbx, %rdi
callq 0x4500
cmpq $0xffffe, %r12          # imm = 0xFFFFE
ja 0x9664
cmpl $-0x1, %eax
jne 0x962b
jmp 0x9664
movq %rbx, %rdi
callq 0x42f0
movq %r12, (%r15)
movl %ebp, (%r13)
jmp 0x97db
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
xorl %r12d, %r12d
movb %r12b, (%r14,%r15)
movq %rbx, %rdi
callq 0x42f0
leaq 0x20(%rsp), %r13
movl $0x0, 0x8(%r13)
movq $0x0, (%r13)
leaq 0x3030(%rsp), %r15
movb %r12b, (%r15)
leaq 0x30(%rsp), %rbp
movb %r12b, (%rbp)
leaq 0x2030(%rsp), %rdx
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
movl $0x1000, %ecx           # imm = 0x1000
callq 0x9342
movq %r14, %r12
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x91cb
movq %rax, %r12
testq %rax, %rax
je 0x96de
cmpb $0x23, 0x30(%rsp)
jne 0x96bf
testq %r12, %r12
je 0x9795
movq %rbp, %rdi
callq 0x4180
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x978e
movq %r15, %rdi
movq %rbp, %rsi
callq 0x42c0
movq %r15, %rdi
callq 0x4180
movw $0xa, 0x3030(%rsp,%rax)
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x91cb
testq %rax, %rax
je 0x9771
cmpb $0x23, 0x30(%rsp)
je 0x9771
movq %rax, %r12
movq %r15, %rdi
callq 0x4180
movq %rax, %rbx
movq %rbp, %rdi
callq 0x4180
addq %rbx, %rax
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x976a
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4570
jmp 0x970a
movb $0x1, 0x20b5ce7(%rip)   # 0x20bf458
movq %r13, %rdi
leaq 0x2030(%rsp), %rsi
movq %r15, %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x8f6e
jmp 0x96bf
movb $0x1, 0x20b5cc3(%rip)   # 0x20bf458
leaq 0x2030(%rsp), %rdx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x940a
cmpb $0x1, 0x20b5c9f(%rip)   # 0x20bf458
movq 0x8(%rsp), %rax
jne 0x97ca
movq %rax, (%rbx)
movl 0x4(%rsp), %ecx
movl %ecx, (%r15)
movq (%rax), %rax
movq (%rbx), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x4390
addq $0x5038, %rsp           # imm = 0x5038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)