// File: FreeSlave[P]vhlt/hlcsg/map.cpp
// Function: CopyCurrentBrush(entity_t*, brush_s const*)
brush_t *CopyCurrentBrush (entity_t *entity, const brush_t *brush)
{
	if (entity->firstbrush + entity->numbrushes != g_nummapbrushes)
	{
		Error ("CopyCurrentBrush: internal error.");
	}
	brush_t *newb = &g_mapbrushes[g_nummapbrushes];
	g_nummapbrushes++;
	hlassume (g_nummapbrushes <= MAX_MAP_BRUSHES, assume_MAX_MAP_BRUSHES);
	memcpy (newb, brush, sizeof (brush_t));
	newb->firstside = g_numbrushsides;
	g_numbrushsides += brush->numsides;
	hlassume (g_numbrushsides <= MAX_MAP_SIDES, assume_MAX_MAP_SIDES);
	memcpy (&g_brushsides[newb->firstside], &g_brushsides[brush->firstside], brush->numsides * sizeof (side_t));
	newb->entitynum = entity - g_entities;
	newb->brushnum = entity->numbrushes;
	entity->numbrushes++;
#ifdef HLCSG_HULLBRUSH
	for (int h = 0; h < NUM_HULLS; h++)
	{
		if (brush->hullshapes[h] != NULL)
		{
			newb->hullshapes[h] = _strdup (brush->hullshapes[h]);
		}
		else
		{
			newb->hullshapes[h] = NULL;
		}
	}
#endif
	return newb;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
movq 0x20(%rsp), %rcx
addl 0x1c(%rcx), %eax
cmpl 0x30c133c(%rip), %eax   # 0x30db630
je 0x1a304
leaq 0x13c73(%rip), %rdi     # 0x2df70
movb $0x0, %al
callq 0xba80
movslq 0x30c1325(%rip), %rcx   # 0x30db630
leaq 0x30c132e(%rip), %rax   # 0x30db640
imulq $0x140, %rcx, %rcx      # imm = 0x140
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0x30c1309(%rip), %eax   # 0x30db630
addl $0x1, %eax
movl %eax, 0x30c1300(%rip)   # 0x30db630
cmpl $0x8000, 0x30c12f6(%rip) # imm = 0x8000
setle %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x28, %esi
callq 0xc400
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x140, %edx            # imm = 0x140
callq 0x4310
movl 0x3ac12d9(%rip), %ecx   # 0x3adb640
movq 0x10(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x18(%rsp), %rax
movl 0x14(%rax), %eax
addl 0x3ac12c3(%rip), %eax   # 0x3adb640
movl %eax, 0x3ac12bd(%rip)   # 0x3adb640
cmpl $0x30000, 0x3ac12b3(%rip) # imm = 0x30000
setle %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x27, %esi
callq 0xc400
movq 0x10(%rsp), %rax
movslq 0x10(%rax), %rax
leaq 0x3ac12a0(%rip), %rdi   # 0x3adb650
imulq $0xd0, %rax, %rax
addq %rax, %rdi
movq 0x18(%rsp), %rax
movslq 0x10(%rax), %rax
leaq 0x3ac1286(%rip), %rsi   # 0x3adb650
imulq $0xd0, %rax, %rax
addq %rax, %rsi
movq 0x18(%rsp), %rax
movslq 0x14(%rax), %rax
imulq $0xd0, %rax, %rdx
callq 0x4310
movq 0x20(%rsp), %rax
leaq 0x20130bb(%rip), %rcx   # 0x202d4b0
subq %rcx, %rax
movl $0x28, %ecx
cqto
idivq %rcx
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x20(%rsp), %rax
movl 0x1c(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x20(%rsp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movl $0x0, 0xc(%rsp)
cmpl $0x4, 0xc(%rsp)
jge 0x1a495
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rcx
cmpq $0x0, 0x38(%rax,%rcx,8)
je 0x1a473
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq 0x38(%rax,%rcx,8), %rdi
callq 0x46b0
movq %rax, %rdx
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, 0x38(%rax,%rcx,8)
jmp 0x1a486
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq $0x0, 0x38(%rax,%rcx,8)
jmp 0x1a488
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x1a432
movq 0x10(%rsp), %rax
addq $0x28, %rsp
retq
nop