// File: /workspace/github_cpp_makefile_star2_O1/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 0x6e54(%rip), %rdi      # 0x21fb8
movl $0x0, 0x4(%rsp)
movq %rsi, 0x8(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9fb2
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9beb
movq (%r14), %rdi
movl %eax, %esi
callq 0xafb0
movl $0x1, %edi
callq 0xb0b8
testb %al, %al
je 0x1b2ef
leaq 0x20a8302(%rip), %r15   # 0x20c34b0
leaq 0x6e72(%rip), %r13      # 0x22027
leaq 0x6e45(%rip), %rbp      # 0x22001
movl $0x0, 0x4(%rsp)
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x4340
movl %eax, %r12d
cmpl $0x1, %eax
adcl $0x0, 0x4(%rsp)
movl $0x1, %edi
callq 0xb0b8
testb %al, %al
je 0x1b201
movq %r15, %rdi
leaq 0x6df0(%rip), %rsi      # 0x21fe4
callq 0x4340
testl %eax, %eax
je 0x1b2af
leaq 0x6dde(%rip), %rdi      # 0x21fe6
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa2a0
jmp 0x1b2af
testl %r12d, %r12d
jne 0x1b2af
leaq 0x14e8(%rip), %rdi      # 0x1c70f
xorl %eax, %eax
callq 0x9fb2
movq %r15, %rdi
leaq 0x3ea5(%rip), %rsi      # 0x1f0dd
callq 0x4340
movl %eax, %r14d
testl %eax, %eax
jne 0x1b26d
leaq 0x6dde(%rip), %rdi      # 0x22029
xorl %eax, %eax
callq 0x9fb2
movl $0x1, %edi
callq 0xb0b8
testb %al, %al
jne 0x1b26d
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa2a0
leaq 0x1528(%rip), %rdi      # 0x1c79c
movq %r15, %rsi
xorl %eax, %eax
callq 0x9fb2
leaq 0x63d70fb(%rip), %rax   # 0x63f2380
cmpl $0x80, (%rax)
jl 0x1b29e
leaq 0x6d9e(%rip), %rdi      # 0x22032
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa2a0
xorl %esi, %esi
testl %r14d, %r14d
setne %sil
movq %r15, %rdi
callq 0x1b454
movl $0x1, %edi
callq 0xb0b8
testb %al, %al
jne 0x1b2ca
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0xa2a0
movq %r15, %rdi
movq %r13, %rsi
callq 0x4340
testl %eax, %eax
jne 0x1b217
movl $0x1, %edi
callq 0xb0b8
testb %al, %al
jne 0x1b1c4
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
jne 0x1b30d
leaq 0x6d56(%rip), %rdi      # 0x22054
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa2a0
cmpl $0x2, %ebp
jl 0x1b328
leaq 0x6d6f(%rip), %rdi      # 0x22088
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa2a0
movq 0x10(%rsp), %rdi
callq 0x43a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq