// File: /workspace/github_cpp_makefile_star2_O3/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 0x200cc01(%rip), %r14   # 0x201f444
movslq (%r14), %rax
leaq (%rax,%rax,4), %rax
leaq 0x200cbff(%rip), %rcx   # 0x201f450
leaq (%rcx,%rax,8), %rax
addq $-0x28, %rax
cmpq %rdi, %rax
je 0x1286c
leaq 0xd63d(%rip), %rdi      # 0x1fea2
xorl %eax, %eax
callq 0xa164
movl 0x1c(%rbx), %ebp
movl 0x18(%rbx), %eax
addl %ebp, %eax
cmpl 0x30bad46(%rip), %eax   # 0x30cd5c0
je 0x1288d
leaq 0xd61f(%rip), %rdi      # 0x1fea2
xorl %eax, %eax
callq 0xa164
movl 0x1c(%rbx), %ebp
leaq 0x30bad3c(%rip), %rdi   # 0x30cd5d0
testl %ebp, %ebp
jle 0x1298c
movslq %ebp, %rax
leaq (%rax,%rax,4), %rax
shlq $0x6, %rax
leaq (%rax,%rdi), %r13
addq $-0x108, %r13           # imm = 0xFEF8
movq %rbx, (%rsp)
movslq %ebp, %r15
movslq 0x18(%rbx), %r12
leaq (%r12,%r15), %rax
decq %rax
leaq (%rax,%rax,4), %r14
shlq $0x6, %r14
movl 0x10(%r14,%rdi), %ecx
movl 0x14(%r14,%rdi), %eax
leal (%rax,%rcx), %ebx
cmpl 0x3abacf1(%rip), %ebx   # 0x3acd5d0
je 0x1290e
leaq 0x30bace8(%rip), %rax   # 0x30cd5d0
addq %rax, %r14
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq 0xd5ce(%rip), %rdi      # 0x1fec7
xorl %eax, %eax
callq 0xa164
movl 0x10(%r14), %ecx
movl 0x14(%r14), %eax
movl 0x3abacc2(%rip), %ebx   # 0x3acd5d0
decq %r15
movslq %ecx, %rcx
imulq $0xd0, %rcx, %rdi
leaq 0x3abacbe(%rip), %rcx   # 0x3acd5e0
addq %rcx, %rdi
movslq %eax, %r14
imulq $0xd0, %r14, %rdx
xorl %esi, %esi
callq 0x41c0
subl %r14d, %ebx
movl %ebx, 0x3abac91(%rip)   # 0x3acd5d0
leaq (%r12,%r12,4), %rbx
shlq $0x6, %rbx
addq %r13, %rbx
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
testq %rdi, %rdi
je 0x1295b
callq 0x4390
incq %r14
cmpq $0x4, %r14
jne 0x1294d
addq $-0x140, %r13           # imm = 0xFEC0
cmpl $0x1, %ebp
movl %r15d, %ebp
movq (%rsp), %rbx
leaq 0x30bac54(%rip), %rdi   # 0x30cd5d0
jg 0x128b6
movl 0x1c(%rbx), %ebp
leaq 0x200cab8(%rip), %r14   # 0x201f444
movslq 0x18(%rbx), %rax
leaq (%rax,%rax,4), %rax
shlq $0x6, %rax
addq %rax, %rdi
movslq %ebp, %rax
shlq $0x6, %rax
leaq (%rax,%rax,4), %rdx
xorl %esi, %esi
callq 0x41c0
movl 0x1c(%rbx), %eax
subl %eax, 0x30bac0a(%rip)   # 0x30cd5c0
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x129cd
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x7623
jmp 0x129b6
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq $0x0, 0x20(%rbx)
decl (%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq