// File: FreeSlave[P]vhlt/common/bspfile.cpp
// Function: ParseEntity()
bool            ParseEntity()
{
    epair_t*        e;
    entity_t*       mapent;

    if (!GetToken(true))
    {
        return false;
    }

    if (strcmp(g_token, "{"))
    {
        Error("ParseEntity: { not found");
    }

    if (g_numentities == MAX_MAP_ENTITIES)
    {
        Error("g_numentities == MAX_MAP_ENTITIES");
    }

    mapent = &g_entities[g_numentities];
    g_numentities++;

    while (1)
    {
        if (!GetToken(true))
        {
            Error("ParseEntity: EOF without closing brace");
        }
        if (!strcmp(g_token, "}"))
        {
            break;
        }
        e = ParseEpair();
        e->next = mapent->epairs;
        mapent->epairs = e;
    }

#ifdef ZHLT_INFO_COMPILE_PARAMETERS // AJM
    if (!strcmp(ValueForKey(mapent, "classname"), "info_compile_parameters"))
    {
        Log("Map entity info_compile_parameters detected, using compile settings\n");
        GetParamsFromEnt(mapent);
    }
#endif
#ifdef ZHLT_ENTITY_LIGHTSURFACE
	// ugly code
	if (!strncmp(ValueForKey (mapent, "classname"), "light", 5) && *ValueForKey (mapent, "_tex"))
	{
		SetKeyValue (mapent, "convertto", ValueForKey (mapent, "classname"));
		SetKeyValue (mapent, "classname", "light_surface");
	}
#endif
#ifdef ZHLT_ENTITY_LIGHTSHADOW
	if (!strcmp (ValueForKey (mapent, "convertfrom"), "light_shadow")
	#ifdef ZHLT_ENTITY_LIGHTBOUNCE
		|| !strcmp (ValueForKey (mapent, "convertfrom"), "light_bounce")
	#endif
		)
	{
		SetKeyValue (mapent, "convertto", ValueForKey (mapent, "classname"));
		SetKeyValue (mapent, "classname", ValueForKey (mapent, "convertfrom"));
		SetKeyValue (mapent, "convertfrom", "");
	}
#endif
#ifdef ZHLT_ENTITY_INFOSUNLIGHT
	if (!strcmp (ValueForKey (mapent, "classname"), "light_environment") &&
		!strcmp (ValueForKey (mapent, "convertfrom"), "info_sunlight"))
	{
		while (mapent->epairs)
		{
			DeleteKey (mapent, mapent->epairs->key);
		}
		memset (mapent, 0, sizeof(entity_t));
		g_numentities--;
		return true;
	}
	if (!strcmp (ValueForKey (mapent, "classname"), "light_environment") &&
		IntForKey (mapent, "_fake"))
	{
		SetKeyValue (mapent, "classname", "info_sunlight");
	}
#endif

    return true;
}

// Assembly:
subq $0x38, %rsp
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x7c9c
movb $0x0, 0x37(%rsp)
jmp 0x7fda
leaq 0x20c985d(%rip), %rdi   # 0x20d1500
leaq 0x22846(%rip), %rsi     # 0x2a4f0
callq 0x4530
cmpl $0x0, %eax
je 0x7cc2
leaq 0x22837(%rip), %rdi     # 0x2a4f2
movb $0x0, %al
callq 0xba80
cmpl $0x4000, 0x20257d8(%rip) # imm = 0x4000
jne 0x7cdc
leaq 0x22836(%rip), %rdi     # 0x2a50b
movb $0x0, %al
callq 0xba80
movslq 0x20257c1(%rip), %rcx   # 0x202d4a4
leaq 0x20257c6(%rip), %rax   # 0x202d4b0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x20257a8(%rip), %eax   # 0x202d4a4
addl $0x1, %eax
movl %eax, 0x202579f(%rip)   # 0x202d4a4
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x7d21
leaq 0x22813(%rip), %rdi     # 0x2a52d
movb $0x0, %al
callq 0xba80
leaq 0x20c97d8(%rip), %rdi   # 0x20d1500
leaq 0x22825(%rip), %rsi     # 0x2a554
callq 0x4530
cmpl $0x0, %eax
jne 0x7d3b
jmp 0x7d66
callq 0x7bd0
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rax)
jmp 0x7d05
movq 0x20(%rsp), %rdi
leaq 0x227e4(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq %rax, %rdi
leaq 0x227df(%rip), %rsi     # 0x2a560
callq 0x4530
cmpl $0x0, %eax
jne 0x7da3
leaq 0x227e6(%rip), %rdi     # 0x2a578
movb $0x0, %al
callq 0xb5d0
movq 0x20(%rsp), %rdi
callq 0x1f790
movq 0x20(%rsp), %rdi
leaq 0x227a7(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq %rax, %rdi
leaq 0x2285c(%rip), %rsi     # 0x2a61a
movl $0x5, %edx
callq 0x41f0
cmpl $0x0, %eax
jne 0x7e2a
movq 0x20(%rsp), %rdi
leaq 0x227e4(%rip), %rsi     # 0x2a5bd
callq 0x7ff0
cmpb $0x0, (%rax)
je 0x7e2a
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x2275d(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
leaq 0x227b5(%rip), %rsi     # 0x2a5c2
callq 0x8070
movq 0x20(%rsp), %rdi
leaq 0x22738(%rip), %rsi     # 0x2a556
leaq 0x227a7(%rip), %rdx     # 0x2a5cc
callq 0x8070
movq 0x20(%rsp), %rdi
leaq 0x227a4(%rip), %rsi     # 0x2a5da
callq 0x7ff0
movq %rax, %rdi
leaq 0x227a1(%rip), %rsi     # 0x2a5e6
callq 0x4530
cmpl $0x0, %eax
je 0x7e74
movq 0x20(%rsp), %rdi
leaq 0x2277f(%rip), %rsi     # 0x2a5da
callq 0x7ff0
movq %rax, %rdi
leaq 0x22789(%rip), %rsi     # 0x2a5f3
callq 0x4530
cmpl $0x0, %eax
jne 0x7eea
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x226cc(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x22724(%rip), %rsi     # 0x2a5c2
callq 0x8070
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x22721(%rip), %rsi     # 0x2a5da
callq 0x7ff0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x22689(%rip), %rsi     # 0x2a556
callq 0x8070
movq 0x20(%rsp), %rdi
leaq 0x226fc(%rip), %rsi     # 0x2a5da
leaq 0x23e54(%rip), %rdx     # 0x2bd39
callq 0x8070
movq 0x20(%rsp), %rdi
leaq 0x22660(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq %rax, %rdi
leaq 0x226fb(%rip), %rsi     # 0x2a600
callq 0x4530
cmpl $0x0, %eax
jne 0x7f82
movq 0x20(%rsp), %rdi
leaq 0x226bf(%rip), %rsi     # 0x2a5da
callq 0x7ff0
movq %rax, %rdi
leaq 0x226e8(%rip), %rsi     # 0x2a612
callq 0x4530
cmpl $0x0, %eax
jne 0x7f82
jmp 0x7f36
movq 0x20(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x7f5b
movq 0x20(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x8170
jmp 0x7f36
movq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x4210
movl 0x2025532(%rip), %eax   # 0x202d4a4
addl $-0x1, %eax
movl %eax, 0x2025529(%rip)   # 0x202d4a4
movb $0x1, 0x37(%rsp)
jmp 0x7fda
movq 0x20(%rsp), %rdi
leaq 0x225c8(%rip), %rsi     # 0x2a556
callq 0x7ff0
movq %rax, %rdi
leaq 0x22663(%rip), %rsi     # 0x2a600
callq 0x4530
cmpl $0x0, %eax
jne 0x7fd5
movq 0x20(%rsp), %rdi
leaq 0x2266d(%rip), %rsi     # 0x2a620
callq 0x8210
cmpl $0x0, %eax
je 0x7fd5
movq 0x20(%rsp), %rdi
leaq 0x2258d(%rip), %rsi     # 0x2a556
leaq 0x22642(%rip), %rdx     # 0x2a612
callq 0x8070
movb $0x1, 0x37(%rsp)
movb 0x37(%rsp), %al
andb $0x1, %al
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)