// File: 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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
leaq 0x2012fef(%rip), %rcx   # 0x202d4a4
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x2012fec(%rip), %rcx   # 0x202d4b0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x1a4de
leaq 0x13abb(%rip), %rdi     # 0x2df92
movb $0x0, %al
callq 0xba80
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
movq 0x20(%rsp), %rcx
addl 0x1c(%rcx), %eax
cmpl 0x30c113c(%rip), %eax   # 0x30db630
je 0x1a504
leaq 0x13a95(%rip), %rdi     # 0x2df92
movb $0x0, %al
callq 0xba80
movq 0x20(%rsp), %rax
movl 0x1c(%rax), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jl 0x1a615
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
addl 0x1c(%rsp), %eax
movslq %eax, %rcx
leaq 0x30c110c(%rip), %rax   # 0x30db640
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x10(%rsp), %rcx
addl 0x14(%rcx), %eax
cmpl 0x3ac10e7(%rip), %eax   # 0x3adb640
je 0x1a578
movq 0x10(%rsp), %rax
movl (%rax), %esi
movq 0x10(%rsp), %rax
movl 0x4(%rax), %edx
leaq 0x13a46(%rip), %rdi     # 0x2dfb7
movb $0x0, %al
callq 0xba80
movq 0x10(%rsp), %rax
movslq 0x10(%rax), %rax
leaq 0x3ac10c8(%rip), %rdi   # 0x3adb650
imulq $0xd0, %rax, %rax
addq %rax, %rdi
movq 0x10(%rsp), %rax
movslq 0x14(%rax), %rax
imulq $0xd0, %rax, %rdx
xorl %esi, %esi
callq 0x4210
movq 0x10(%rsp), %rax
movl 0x14(%rax), %ecx
movl 0x3ac1089(%rip), %eax   # 0x3adb640
subl %ecx, %eax
movl %eax, 0x3ac1081(%rip)   # 0x3adb640
movl $0x0, 0xc(%rsp)
cmpl $0x4, 0xc(%rsp)
jge 0x1a603
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
cmpq $0x0, 0x38(%rax,%rcx,8)
je 0x1a5f4
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq 0x38(%rax,%rcx,8), %rdi
callq 0x4470
jmp 0x1a5f6
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x1a5c7
jmp 0x1a605
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1a513
movq 0x20(%rsp), %rax
movslq 0x18(%rax), %rax
leaq 0x30c101b(%rip), %rdi   # 0x30db640
imulq $0x140, %rax, %rax      # imm = 0x140
addq %rax, %rdi
movq 0x20(%rsp), %rax
movslq 0x1c(%rax), %rax
imulq $0x140, %rax, %rdx      # imm = 0x140
xorl %esi, %esi
callq 0x4210
movq 0x20(%rsp), %rax
movl 0x1c(%rax), %ecx
movl 0x30c0fdc(%rip), %eax   # 0x30db630
subl %ecx, %eax
movl %eax, 0x30c0fd4(%rip)   # 0x30db630
movq 0x20(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1a681
movq 0x20(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x8170
jmp 0x1a65c
movq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x4210
leaq 0x2012e0b(%rip), %rax   # 0x202d4a4
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x2012dff(%rip), %rax   # 0x202d4a4
movl %ecx, (%rax)
addq $0x28, %rsp
retq
nopl (%rax)