// File: /workspace/github_cpp_makefile_star2_O2/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, %rbp
movq %rsi, %r12
movl %edi, 0x4(%rsp)
movq (%rsi), %rsi
leaq 0x4030(%rsp), %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
callq 0x796d
leaq 0x30(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7756
movq %r14, %rdi
callq 0x4190
movabsq $0x73676e6974746573, %rcx # imm = 0x73676E6974746573
movq %rcx, 0x30(%rsp,%rax)
movabsq $0x7478742e73676e, %rcx # imm = 0x7478742E73676E
movq %rcx, 0x35(%rsp,%rax)
leaq 0x13e4e(%rip), %rsi     # 0x1bfc8
movq %r14, %rdi
callq 0x43a0
testq %rax, %rax
je 0x8311
movq %rax, %rbx
movl $0x100001, %edi         # imm = 0x100001
callq 0x4450
testq %rax, %rax
je 0x8309
movq %rax, %r13
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x4530
cmpq $0xfffff, %r14          # imm = 0xFFFFF
ja 0x81c7
cmpl $-0x1, %eax
je 0x81c7
movb %al, (%r13,%r14)
incq %r14
jmp 0x81a7
movb $0x0, (%r13,%r14)
movq %rbx, %rdi
callq 0x4300
testq %r13, %r13
je 0x8311
movq %rbp, 0x8(%rsp)
movq %r15, 0x18(%rsp)
leaq 0x20(%rsp), %rax
andl $0x0, 0x8(%rax)
andq $0x0, (%rax)
xorl %eax, %eax
leaq 0x3030(%rsp), %r15
movb %al, (%r15)
leaq 0x1030(%rsp), %rbp
movb %al, (%rbp)
leaq 0x2030(%rsp), %rbx
movl 0x4(%rsp), %edi
movq %r12, 0x10(%rsp)
movq %r12, %rsi
movq %rbx, %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x7f6c
movq %r13, %r14
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7e45
movq %rax, %r14
testq %rax, %rax
je 0x8253
cmpb $0x23, 0x1030(%rsp)
jne 0x8231
testq %r14, %r14
je 0x8324
movq %rbp, %rdi
callq 0x4190
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x831d
movq %r15, %rdi
movq %rbp, %rsi
callq 0x42e0
movq %r15, %rdi
callq 0x4190
movw $0xa, 0x3030(%rsp,%rax)
movq %r14, %rdi
movq %rbp, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7e45
testq %rax, %rax
je 0x82ef
cmpb $0x23, 0x1030(%rsp)
je 0x82ef
movq %rax, %r12
movq %r15, %rdi
callq 0x4190
movq %rax, %r14
movq %rbp, %rdi
callq 0x4190
addq %r14, %rax
addq $0x2, %rax
cmpq $0x1000, %rax           # imm = 0x1000
ja 0x82e5
movq %r15, %rdi
movq %rbp, %rsi
callq 0x45a0
movq %r12, %r14
jmp 0x827f
movb $0x1, 0x20b517c(%rip)   # 0x20bd468
movq %r12, %r14
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1000, %ecx           # imm = 0x1000
callq 0x7cfe
jmp 0x8231
movq %rbx, %rdi
callq 0x4300
movq %r12, (%r15)
movl 0x4(%rsp), %eax
movl %eax, (%rbp)
jmp 0x836a
movb $0x1, 0x20b5144(%rip)   # 0x20bd468
leaq 0x2030(%rsp), %rdx
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x802e
cmpb $0x1, 0x20b5120(%rip)   # 0x20bd468
movq 0x10(%rsp), %rax
jne 0x8359
movq %rax, (%rbx)
movl 0x4(%rsp), %ecx
movl %ecx, (%r14)
movq (%rax), %rax
movq (%rbx), %rcx
movq %rax, (%rcx)
movq %r13, %rdi
callq 0x43b0
addq $0x5038, %rsp           # imm = 0x5038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq