// File: /workspace/github_cpp_makefile_star2_O2/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 0x6b0c(%rip), %rdi      # 0x1eee4
movq %rsi, 0x8(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x89dc
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8617
movq (%r14), %rdi
movl %eax, %esi
callq 0x9a3f
pushq $0x1
popq %rbp
leaq 0x20a90a5(%rip), %r15   # 0x20c14b0
leaq 0x6b41(%rip), %r13      # 0x1ef53
movl $0x0, 0x4(%rsp)
movl %ebp, %edi
callq 0x9b47
testb %al, %al
je 0x18546
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x4350
movl %eax, %r12d
cmpl $0x1, %eax
adcl $0x0, 0x4(%rsp)
movl %ebp, %edi
callq 0x9b47
testb %al, %al
je 0x18463
movq %r15, %rdi
leaq 0x6aba(%rip), %rsi      # 0x1ef10
callq 0x4350
testl %eax, %eax
je 0x18512
leaq 0x6aa8(%rip), %rdi      # 0x1ef12
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8d7b
jmp 0x18512
testl %r12d, %r12d
jne 0x18512
leaq 0x11e6(%rip), %rdi      # 0x1966f
xorl %eax, %eax
callq 0x89dc
movq %r15, %rdi
leaq 0x3ba3(%rip), %rsi      # 0x1c03d
callq 0x4350
movl %eax, %r14d
testl %eax, %eax
jne 0x184d0
leaq 0x6aa8(%rip), %rdi      # 0x1ef55
xorl %eax, %eax
callq 0x89dc
movl %ebp, %edi
callq 0x9b47
testb %al, %al
jne 0x184d0
leaq 0x6a67(%rip), %rdi      # 0x1ef2d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8d7b
leaq 0x1225(%rip), %rdi      # 0x196fc
movq %r15, %rsi
xorl %eax, %eax
callq 0x89dc
leaq 0x63d7e98(%rip), %rax   # 0x63f0380
cmpl $0x80, (%rax)
jl 0x18501
leaq 0x6a67(%rip), %rdi      # 0x1ef5e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8d7b
xorl %esi, %esi
testl %r14d, %r14d
setne %sil
movq %r15, %rdi
callq 0x18690
movl %ebp, %edi
callq 0x9b47
testb %al, %al
jne 0x1852e
leaq 0x6a09(%rip), %rdi      # 0x1ef2d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8d7b
movq %r15, %rdi
movq %r13, %rsi
callq 0x4350
testl %eax, %eax
jne 0x18479
jmp 0x1841a
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x1855c
cmpl $0x1, %eax
je 0x18572
leaq 0x6a5a(%rip), %rdi      # 0x1efb4
jmp 0x18563
leaq 0x6a1d(%rip), %rdi      # 0x1ef80
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8d7b
movq 0x10(%rsp), %rdi
callq 0x43b0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq