// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x82b06e(%rip), %ecx    # 0x8314d4
testl %ecx, %ecx
jle 0x6641
leaq 0x82b06b(%rip), %r12    # 0x8314e0
leaq 0x1a4e5(%rip), %rsi     # 0x20961
xorl %eax, %eax
xorl %r13d, %r13d
movslq %eax, %rdx
movslq %ecx, %r8
leal 0x1(%rdx), %ecx
cmpl %ecx, %r8d
movl %ecx, %ebp
cmovgl %r8d, %ebp
movzbl (%rdx,%r12), %edi
cmpl $0xa, %edi
je 0x64ac
cmpl $0xd, %edi
je 0x64ac
incq %rdx
cmpq %r8, %rdx
jl 0x6493
jmp 0x64ae
movl %edx, %ebp
cmpl %ecx, %ebp
jne 0x64d4
cltq
movzbl (%rax,%r12), %eax
cmpl $0x7b, %eax
jne 0x661c
testb $0x1, %r13b
movb $0x1, %r13b
je 0x65e0
jmp 0x6641
testb $0x1, %r13b
je 0x6641
movslq %ebp, %r10
leal -0x1(%rbp), %ecx
xorl %edx, %edx
movl %eax, %edi
cmpl %ebp, %edi
setl %r9b
jge 0x652d
movslq %edi, %r8
cmpb $0x22, (%r8,%r12)
je 0x6515
cmpl %r8d, %ecx
je 0x652d
leaq 0x1(%r8), %rdi
cmpb $0x22, 0x1(%r8,%r12)
movq %rdi, %r8
jne 0x64fa
cmpq %r10, %rdi
setl %r9b
testb %r9b, %r9b
je 0x652d
movl %edi, (%rsp,%rdx,4)
incq %rdx
incl %edi
cmpq $0x4, %rdx
jne 0x64e8
movl $0x4, %edx
cmpl $0x4, %edx
jne 0x65d5
movslq (%rsp), %rdi
cmpl %eax, %edi
jne 0x65d5
movl 0xc(%rsp), %ebx
cmpl %ecx, %ebx
jne 0x65d5
movl 0x4(%rsp), %eax
incq %rdi
subl %edi, %eax
movb $0x1, %r15b
cmpl $0x3, %eax
jne 0x65db
addq %r12, %rdi
movl $0x3, %edx
callq 0x41a0
leaq 0x1a3ee(%rip), %rsi     # 0x20961
testl %eax, %eax
jne 0x65db
movslq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movl %eax, %r15d
notl %r15d
addl %ebx, %r15d
subl %eax, %ebx
movslq %ebx, %rdi
callq 0x4430
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xaa4d
movq 0x10(%rsp), %rax
leaq (%rax,%r12), %rsi
incq %rsi
movslq %r15d, %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x4270
leaq 0x1a396(%rip), %rsi     # 0x20961
movb $0x0, (%r14,%r15)
xorl %r15d, %r15d
jmp 0x65db
xorl %r15d, %r15d
xorl %r14d, %r14d
testb %r15b, %r15b
je 0x6644
movl 0x82aeee(%rip), %eax    # 0x8314d4
cmpl %eax, %ebp
jge 0x660a
movslq %eax, %rcx
movslq %ebp, %rbp
movzbl (%rbp,%r12), %edx
cmpl $0xd, %edx
je 0x6600
cmpl $0xa, %edx
jne 0x660a
incq %rbp
cmpq %rbp, %rcx
jne 0x65f0
movl %eax, %ebp
movl 0x82aec4(%rip), %ecx    # 0x8314d4
movl %ebp, %eax
cmpl %ecx, %ebp
jl 0x6481
jmp 0x6641
cmpl $0x7d, %eax
jne 0x6641
testb $0x1, %r13b
je 0x6641
leaq 0x1768b(%rip), %rdi     # 0x1dcb9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq