// File: /workspace/github_cpp_makefile_star2_O3/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
movslq 0x82b083(%rip), %rax    # 0x8314c4
xorl %ebx, %ebx
testq %rax, %rax
jle 0x657a
leaq 0x82b07d(%rip), %r14    # 0x8314d0
xorl %edi, %edi
xorl %ecx, %ecx
movslq %edi, %r8
leaq 0x1(%r8), %rsi
cmpl %esi, %eax
movl %esi, %edx
cmovgl %eax, %edx
movq %r8, %r9
movzbl (%r9,%r14), %r10d
cmpl $0xa, %r10d
je 0x6483
cmpl $0xd, %r10d
je 0x6483
incq %r9
cmpq %rax, %r9
jl 0x6468
jmp 0x6486
movl %r9d, %edx
cmpl %esi, %edx
jne 0x64a8
movzbl (%r8,%r14), %esi
cmpl $0x7b, %esi
jne 0x6558
testb $0x1, %cl
movb $0x1, %cl
je 0x652c
jmp 0x657a
testb $0x1, %cl
je 0x657a
xorl %r8d, %r8d
movl %edi, %r9d
cmpl %edx, %r9d
jge 0x64e7
movslq %r9d, %r10
addq %r14, %r10
cmpb $0x22, (%r10)
je 0x64d5
incl %r9d
incq %r10
cmpl %r9d, %edx
jne 0x64c2
jmp 0x64e7
movl %r9d, (%rsp,%r8,4)
incq %r8
incl %r9d
cmpq $0x4, %r8
jne 0x64b7
jmp 0x64f1
cmpq $0x4, %r8
jne 0x657a
cmpl %edi, (%rsp)
jne 0x657a
movl 0xc(%rsp), %edi
leal -0x1(%rdx), %r8d
cmpl %r8d, %edi
jne 0x657a
movl 0x4(%rsp), %r8d
subl %esi, %r8d
cmpl $0x3, %r8d
jne 0x652c
cmpb $0x77, (%rsi,%r14)
jne 0x652c
cmpb $0x61, 0x1(%rsi,%r14)
jne 0x652c
cmpb $0x64, 0x2(%rsi,%r14)
je 0x6588
cmpl %eax, %edx
jge 0x654c
movslq %edx, %rdx
movzbl (%rdx,%r14), %esi
cmpl $0xd, %esi
je 0x6542
cmpl $0xa, %esi
jne 0x654c
incq %rdx
cmpq %rdx, %rax
jne 0x6533
jmp 0x657a
movl %edx, %edi
cmpl %eax, %edx
jl 0x6457
jmp 0x657a
cmpl $0x7d, %esi
jne 0x657a
testb $0x1, %cl
je 0x6578
leaq 0x17740(%rip), %rdi     # 0x1dca9
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x45a0
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 %edi, %ebp
subl %r15d, %edi
movslq %edi, %rdi
callq 0x4420
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa91d
leaq (%r15,%r14), %rsi
incq %rsi
movslq %ebp, %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4260
movb $0x0, (%rbx,%r14)
jmp 0x657a