// File: /workspace/github_cpp_makefile_star2_O2/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 0x200ce6a(%rip), %rax   # 0x201d454
movslq (%rax), %rax
imulq $0x28, %rax, %rax
leaq 0x200ce68(%rip), %rcx   # 0x201d460
addq %rcx, %rax
addq $-0x28, %rax
cmpq %rdi, %rax
je 0x10612
leaq 0xc7c7(%rip), %rdi      # 0x1cdd2
xorl %eax, %eax
callq 0x8d7b
movl 0x1c(%rbx), %r13d
movl 0x18(%rbx), %eax
addl %r13d, %eax
cmpl 0x30bafae(%rip), %eax   # 0x30cb5d0
je 0x10636
leaq 0xc7a7(%rip), %rdi      # 0x1cdd2
xorl %eax, %eax
callq 0x8d7b
movl 0x1c(%rbx), %r13d
leal -0x1(%r13), %ebp
leaq 0x30baf9f(%rip), %r14   # 0x30cb5e0
movq %rbx, (%rsp)
movslq 0x18(%rbx), %r15
testl %r13d, %r13d
jle 0x10703
movslq %r13d, %r13
decq %r13
leaq (%r15,%r13), %rax
imulq $0x140, %rax, %rbx      # imm = 0x140
movl 0x10(%rbx,%r14), %ecx
movl 0x14(%rbx,%r14), %eax
leal (%rax,%rcx), %r12d
cmpl 0x3abaf68(%rip), %r12d  # 0x3acb5e0
je 0x1069d
addq %r14, %rbx
movl (%rbx), %esi
movl 0x4(%rbx), %edx
leaq 0xc76e(%rip), %rdi      # 0x1cdf7
xorl %eax, %eax
callq 0x8d7b
movl 0x10(%rbx), %ecx
movl 0x14(%rbx), %eax
movl 0x3abaf43(%rip), %r12d  # 0x3acb5e0
movslq %ecx, %rcx
imulq $0xd0, %rcx, %rdi
leaq 0x3abaf42(%rip), %rcx   # 0x3acb5f0
addq %rcx, %rdi
movslq %eax, %rbx
imulq $0xd0, %rbx, %rdx
xorl %esi, %esi
callq 0x41e0
subl %ebx, %r12d
movl %r12d, 0x3abaf14(%rip)  # 0x3acb5e0
addl %ebp, %r15d
movslq %r15d, %rax
imulq $0x140, %rax, %rax      # imm = 0x140
leaq (%rax,%r14), %rbx
addq $0x38, %rbx
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x106f8
movq (%rbx,%r15,8), %rdi
callq 0x43b0
incq %r15
jmp 0x106e4
decl %ebp
movq (%rsp), %rbx
jmp 0x10645
imulq $0x140, %r15, %rax      # imm = 0x140
addq %rax, %r14
movslq 0x1c(%rbx), %rax
imulq $0x140, %rax, %rdx      # imm = 0x140
movq %r14, %rdi
xorl %esi, %esi
callq 0x41e0
movl 0x1c(%rbx), %eax
subl %eax, 0x30baea5(%rip)   # 0x30cb5d0
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x10742
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x6a8a
jmp 0x1072b
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
andq $0x0, 0x20(%rbx)
movups %xmm0, (%rbx)
leaq 0x200ccfc(%rip), %rax   # 0x201d454
decl (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq