// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/common/bspfile.cpp
// Function: FindWadValue()
char *FindWadValue ()
	// return NULL for syntax error
	// this function needs to be as stable as possible because it might be called from ripent
{
	int linestart, lineend;
	bool inentity = false;
	for (linestart = 0; linestart < g_entdatasize; )
	{
		for (lineend = linestart; lineend < g_entdatasize; lineend++)
			if (g_dentdata[lineend] == '\r' || g_dentdata[lineend] == '\n')
				break;
		if (lineend == linestart + 1)
		{
			if (g_dentdata[linestart] == '{')
			{
				if (inentity)
					return NULL;
				inentity = true;
			}
			else if (g_dentdata[linestart] == '}')
			{
				if (!inentity)
					return NULL;
				inentity = false;
				return _strdup (""); // only parse the first entity
			}
			else
				return NULL;
		}
		else
		{
			if (!inentity)
				return NULL;
			int quotes[4];
			int i, j;
			for (i = 0, j = linestart; i < 4; i++, j++)
			{
				for (; j < lineend; j++)
					if (g_dentdata[j] == '\"')
						break;
				if (j >= lineend)
					break;
				quotes[i] = j;
			}
			if (i != 4 || quotes[0] != linestart || quotes[3] != lineend - 1)
			{
				return NULL;
			}
			if (quotes[1] - (quotes[0] + 1) == (int)strlen ("wad") && !strncmp (&g_dentdata[quotes[0] + 1], "wad", strlen ("wad")))
			{
				int len = quotes[3] - (quotes[2] + 1);
				char *value = (char *)malloc (len + 1);
				hlassume (value != NULL, assume_NoMemory);
				memcpy (value, &g_dentdata[quotes[2] + 1], len);
				value[len] = '\0';
				return value;
			}
		}
		for (linestart = lineend; linestart < g_entdatasize; linestart++)
			if (g_dentdata[linestart] != '\r' && g_dentdata[linestart] != '\n')
				break;
	}
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl 0x829789(%rip), %eax    # 0x82f4d4
movslq %eax, %rcx
xorl %ebx, %ebx
leaq 0x829789(%rip), %r14    # 0x82f4e0
xorl %edx, %edx
xorl %r8d, %r8d
cmpl %eax, %r8d
jge 0x5ea3
movl %r8d, %r9d
movslq %r8d, %r11
movq %rcx, %rdi
subq %r11, %rdi
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x5d97
leaq (%r11,%rsi), %r10
movzbl (%r14,%r10), %r10d
cmpl $0xa, %r10d
je 0x5d92
cmpl $0xd, %r10d
je 0x5d92
incq %rsi
jmp 0x5d73
addl %r8d, %esi
jmp 0x5d99
movl %eax, %esi
leaq 0x1(%r11), %r10
movslq %esi, %rdi
cmpl %r10d, %esi
jne 0x5dc4
movzbl (%r11,%r14), %r8d
cmpl $0x7b, %r8d
jne 0x5e80
testb $0x1, %dl
jne 0x5ea3
movb $0x1, %dl
jmp 0x5e48
testb $0x1, %dl
je 0x5ea3
xorl %r11d, %r11d
movl %r8d, %r15d
cmpq $0x4, %r11
je 0x5e78
movslq %r15d, %r15
cmpq %rdi, %r15
jge 0x5dfd
cmpb $0x22, (%r15,%r14)
je 0x5df1
incq %r15
jmp 0x5de0
movl %r15d, (%rsp,%r11,4)
incq %r11
incl %r15d
jmp 0x5dd3
cmpq $0x4, %r11
jne 0x5ea3
cmpl %r9d, (%rsp)
jne 0x5ea3
movl 0xc(%rsp), %r8d
leal -0x1(%rsi), %r9d
cmpl %r9d, %r8d
jne 0x5ea3
movl 0x4(%rsp), %r9d
subl %r10d, %r9d
cmpl $0x3, %r9d
jne 0x5e48
cmpb $0x77, (%r10,%r14)
jne 0x5e48
cmpb $0x61, 0x1(%r10,%r14)
jne 0x5e48
cmpb $0x64, 0x2(%r10,%r14)
je 0x5eb1
cmpl %eax, %esi
cmovlel %eax, %esi
cmpq %rcx, %rdi
jge 0x5e68
movzbl (%rdi,%r14), %r8d
cmpl $0xd, %r8d
je 0x5e63
cmpl $0xa, %r8d
jne 0x5e70
incq %rdi
jmp 0x5e4d
movl %esi, %r8d
jmp 0x5d5c
movl %edi, %r8d
jmp 0x5d5c
cmpl %r8d, (%rsp)
je 0x5e11
jmp 0x5ea3
cmpl $0x7d, %r8d
jne 0x5ea3
testb $0x1, %dl
je 0x5ea1
leaq 0x14d87(%rip), %rdi     # 0x1ac19
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x45d0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movslq 0x8(%rsp), %r15
movl %r15d, %ebp
notl %ebp
addl %r8d, %ebp
subl %r15d, %r8d
movslq %r8d, %rdi
callq 0x4450
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
pushq $0x1
popq %rsi
callq 0x9517
leaq (%r15,%r14), %rsi
incq %rsi
movslq %ebp, %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4280
movb $0x0, (%rbx,%r14)
jmp 0x5ea3