// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlcsg/map.cpp
// Function: DeleteCurrentEntity(entity_t*)
void DeleteCurrentEntity (entity_t *entity)
{
	if (entity != &g_entities[g_numentities - 1])
	{
		Error ("DeleteCurrentEntity: internal error.");
	}
	if (entity->firstbrush + entity->numbrushes != g_nummapbrushes)
	{
		Error ("DeleteCurrentEntity: internal error.");
	}
	for (int i = entity->numbrushes - 1; i >= 0; i--)
	{
		brush_t *b = &g_mapbrushes[entity->firstbrush + i];
		if (b->firstside + b->numsides != g_numbrushsides)
		{
			Error ("DeleteCurrentEntity: internal error. (Entity %i, Brush %i)",
#ifdef HLCSG_COUNT_NEW
				b->originalentitynum, b->originalbrushnum
#else
				b->entitynum, b->brushnum
#endif
				);
		}
		memset (&g_brushsides[b->firstside], 0, b->numsides * sizeof (side_t));
		g_numbrushsides -= b->numsides;
		for (int h = 0; h < NUM_HULLS; h++)
		{
			if (b->hullshapes[h])
			{
				free (b->hullshapes[h]);
			}
		}
	}
	memset (&g_mapbrushes[entity->firstbrush], 0, entity->numbrushes * sizeof (brush_t));
	g_nummapbrushes -= entity->numbrushes;
	while (entity->epairs)
	{
		DeleteKey (entity, entity->epairs->key);
	}
	memset (entity, 0, sizeof(entity_t));
	g_numentities--;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x200c6b4(%rip), %rax   # 0x201f454
movslq (%rax), %rax
leaq (%rax,%rax,4), %rax
leaq 0x200c6b2(%rip), %rcx   # 0x201f460
leaq (%rcx,%rax,8), %rax
addq $-0x28, %rax
cmpq %rdi, %rax
je 0x12dc9
leaq 0xd0c0(%rip), %rdi      # 0x1fe82
xorl %eax, %eax
callq 0xa2a0
movl 0x1c(%rbx), %eax
addl 0x18(%rbx), %eax
cmpl 0x30ba7fb(%rip), %eax   # 0x30cd5d0
je 0x12de5
leaq 0xd0a4(%rip), %rdi      # 0x1fe82
xorl %eax, %eax
callq 0xa2a0
movslq 0x1c(%rbx), %r15
leaq 0x30ba7f0(%rip), %r14   # 0x30cd5e0
testq %r15, %r15
jle 0x12ebc
leaq (%r15,%r15,4), %rax
shlq $0x6, %rax
leaq (%rax,%r14), %rbp
addq $-0x108, %rbp           # imm = 0xFEF8
movq %rbx, (%rsp)
movslq %r15d, %r13
movslq 0x18(%rbx), %r12
leaq (%r12,%r13), %rax
decq %rax
leaq (%rax,%rax,4), %rax
shlq $0x6, %rax
leaq (%r14,%rax), %rbx
movl 0x14(%rax,%r14), %ecx
addl 0x10(%rax,%r14), %ecx
cmpl 0x3aba7a6(%rip), %ecx   # 0x3acd5e0
je 0x12e4f
movl (%rbx), %esi
movl 0x4(%rbx), %edx
leaq 0xd05f(%rip), %rdi      # 0x1fea7
xorl %eax, %eax
callq 0xa2a0
decq %r13
movslq 0x10(%rbx), %rax
imulq $0xd0, %rax, %rdi
leaq 0x3aba78c(%rip), %rax   # 0x3acd5f0
addq %rax, %rdi
movslq 0x14(%rbx), %rbx
imulq $0xd0, %rbx, %rdx
xorl %esi, %esi
callq 0x41c0
subl %ebx, 0x3aba761(%rip)   # 0x3acd5e0
leaq (%r12,%r12,4), %rbx
shlq $0x6, %rbx
addq %rbp, %rbx
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
testq %rdi, %rdi
je 0x12e9b
callq 0x43a0
incq %r12
cmpq $0x4, %r12
jne 0x12e8d
addq $-0x140, %rbp           # imm = 0xFEC0
cmpl $0x1, %r15d
movl %r13d, %r15d
movq (%rsp), %rbx
jg 0x12e10
movslq 0x18(%rbx), %rax
leaq (%rax,%rax,4), %rax
shlq $0x6, %rax
addq %rax, %r14
movslq 0x1c(%rbx), %rax
shlq $0x6, %rax
leaq (%rax,%rax,4), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x41c0
movl 0x1c(%rbx), %eax
subl %eax, 0x30ba6e6(%rip)   # 0x30cd5d0
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x12f01
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x767a
jmp 0x12eea
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq $0x0, 0x20(%rbx)
leaq 0x200c53a(%rip), %rax   # 0x201f454
decl (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq