// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlcsg/wadcfg.cpp
// Function: LoadWadconfig(char const*, char const*)
void LoadWadconfig (const char *filename, const char *configname)
{
	Log ("Loading wad configuration '%s' from '%s' :\n", configname, filename);
	int found = 0;
	int count = 0;
	int size;
	char *buffer;
	size = LoadFile (filename, &buffer);
	ParseFromMemory (buffer, size);
	while (GetToken (true))
	{
		bool skip = true;
		if (!strcasecmp (g_token, configname))
		{
			skip = false;
			found++;
		}
		if (!GetToken (true) || strcasecmp (g_token, "{"))
		{
			Error ("parsing '%s': missing '{'.", filename);
		}
		while (1)
		{
			if (!GetToken (true))
			{
				Error ("parsing '%s': unexpected end of file.", filename);
			}
			if (!strcasecmp (g_token, "}"))
			{
				break;
			}
			if (skip)
			{
				continue;
			}
			Log (" ");
			bool include = false;
			if (!strcasecmp (g_token, "include"))
			{
				Log ("include ");
				include = true;
				if (!GetToken (true))
				{
					Error ("parsing '%s': unexpected end of file.", filename);
				}
			}
			Log ("\"%s\"\n", g_token);
			if (g_iNumWadPaths >= MAX_WADPATHS)
			{
				Error ("parsing '%s': too many wad files.", filename);
			}
			count++;
#ifdef HLCSG_AUTOWAD_NEW
			PushWadPath (g_token, !include);
#else
			wadpath_t *current = (wadpath_t *)malloc (sizeof (wadpath_t));
			hlassume (current != NULL, assume_NoMemory);
			g_pWadPaths[g_iNumWadPaths] = current;
			g_iNumWadPaths++;
			safe_strncpy (current->path, g_token, _MAX_PATH);
			current->usedbymap = true; // what's this?
			current->usedtextures = 0;
			if (include)
			{
				Developer (DEVELOPER_LEVEL_MESSAGE, "LoadWadcfgfile: including '%s'.\n", current->path);
				g_WadInclude.push_back(current->path);
			}
#endif
		}
	}
	if (found == 0)
	{
		Error ("Couldn't find wad configuration '%s' in file '%s'.\n", configname, filename);
	}
	if (found >= 2)
	{
		Error ("Found more than one wad configuration for '%s' in file '%s'.\n", configname, filename);
	}
	free (buffer); // should not be freed because it is still being used as script buffer
	//Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", configname, count, count > 1 ? "s" : "");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x73cc(%rip), %rdi      # 0x21ff4
movq %rsi, 0x8(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9e76
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9aac
movq (%r14), %rdi
movl %eax, %esi
callq 0xae8b
movl $0x1, %edi
callq 0xaf93
leaq 0x742e(%rip), %rdi      # 0x22090
testb %al, %al
je 0x1adcd
leaq 0x20a882f(%rip), %r12   # 0x20c34a0
leaq 0x73eb(%rip), %rbp      # 0x22063
leaq 0x73be(%rip), %r15      # 0x2203d
movl $0x0, 0x4(%rsp)
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x4330
movl %eax, %r13d
cmpl $0x1, %eax
adcl $0x0, 0x4(%rsp)
movl $0x1, %edi
callq 0xaf93
testb %al, %al
je 0x1acc4
movq %r12, %rdi
leaq 0x7369(%rip), %rsi      # 0x22020
callq 0x4330
testl %eax, %eax
je 0x1ad72
leaq 0x7357(%rip), %rdi      # 0x22022
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa164
jmp 0x1ad72
testl %r13d, %r13d
jne 0x1ad72
leaq 0x1a1d(%rip), %rdi      # 0x1c707
xorl %eax, %eax
callq 0x9e76
movq %r12, %rdi
leaq 0x43d2(%rip), %rsi      # 0x1f0cd
callq 0x4330
movl %eax, %r14d
testl %eax, %eax
jne 0x1ad30
leaq 0x7357(%rip), %rdi      # 0x22065
xorl %eax, %eax
callq 0x9e76
movl $0x1, %edi
callq 0xaf93
testb %al, %al
jne 0x1ad30
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa164
leaq 0x1a5d(%rip), %rdi      # 0x1c794
movq %r12, %rsi
xorl %eax, %eax
callq 0x9e76
leaq 0x63d7628(%rip), %rax   # 0x63f2370
cmpl $0x80, (%rax)
jl 0x1ad61
leaq 0x7317(%rip), %rdi      # 0x2206e
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa164
xorl %esi, %esi
testl %r14d, %r14d
setne %sil
movq %r12, %rdi
callq 0x1af08
movl $0x1, %edi
callq 0xaf93
testb %al, %al
jne 0x1ad8d
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa164
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4330
testl %eax, %eax
jne 0x1acda
movl $0x1, %edi
callq 0xaf93
testb %al, %al
jne 0x1ac87
movl 0x4(%rsp), %eax
testl %eax, %eax
leaq 0x72d1(%rip), %rdi      # 0x22090
je 0x1adcd
cmpl $0x1, %eax
je 0x1addc
leaq 0x72f7(%rip), %rdi      # 0x220c4
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa164
movq 0x10(%rsp), %rdi
callq 0x4390
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq