// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movl %edi, 0x4(%rsp)
movq (%rsi), %rsi
leaq 0x4030(%rsp), %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
callq 0x8c21
leaq 0x1030(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8878
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 0x1592f(%rip), %rsi     # 0x1f068
movq %r14, %rdi
callq 0x4390
testq %rax, %rax
je 0x979b
movq %rax, %rbx
movl $0x100001, %edi         # imm = 0x100001
callq 0x4430
movq %rax, %r14
testq %rax, %rax
je 0x9791
movq %r12, %rbp
movq %rbx, %rdi
callq 0x4510
xorl %r15d, %r15d
cmpl $-0x1, %eax
je 0x9789
movq %r15, %r12
movb %al, (%r14,%r15)
incq %r15
movq %rbx, %rdi
callq 0x4510
cmpq $0xffffe, %r12          # imm = 0xFFFFE
jbe 0x9769
movb $0x0, (%r14,%r15)
movq %rbp, %r12
movq %rbx, %rdi
callq 0x4300
jmp 0x979e
xorl %r14d, %r14d
testq %r14, %r14
je 0x98c4
movq %r13, 0x18(%rsp)
leaq 0x20(%rsp), %rax
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
xorl %eax, %eax
leaq 0x2030(%rsp), %r15
movb %al, (%r15)
leaq 0x30(%rsp), %rbp
movb %al, (%rbp)
leaq 0x3030(%rsp), %rbx
movl 0x4(%rsp), %edi
movq %r12, 0x10(%rsp)
movq %r12, %rsi
movq %rbx, %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x948c
movq %r14, %r12
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x935c
movq %rax, %r12
testq %rax, %rax
je 0x9817
cmpb $0x23, 0x30(%rsp)
jne 0x97f8
testq %r12, %r12
je 0x98dc
movq %rbp, %rdi
callq 0x4180
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x98d5
movq %r15, %rdi
movq %rbp, %rsi
callq 0x42d0
movq %r15, %rdi
callq 0x4180
movw $0xa, 0x2030(%rsp,%rax)
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x935c
testq %rax, %rax
je 0x98aa
cmpb $0x23, 0x30(%rsp)
je 0x98aa
movq %rax, %r12
movq %r15, %rdi
callq 0x4180
movq %rax, %r13
movq %rbp, %rdi
callq 0x4180
addq %r13, %rax
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x98a3
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4580
jmp 0x9843
movb $0x1, 0x20b5bbe(%rip)   # 0x20bf468
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x90a8
jmp 0x97f8
movq %r12, (%r13)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x9922
movb $0x1, 0x20b5b8c(%rip)   # 0x20bf468
leaq 0x3030(%rsp), %rdx
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x9554
cmpb $0x1, 0x20b5b68(%rip)   # 0x20bf468
movq 0x10(%rsp), %rax
jne 0x9911
movq %rax, (%rbx)
movl 0x4(%rsp), %ecx
movl %ecx, (%r15)
movq (%rax), %rax
movq (%rbx), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x43a0
addq $0x5038, %rsp           # imm = 0x5038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq