// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlcsg/qcsg.cpp
// Function: ReuseModel()
void     ReuseModel ()
{
	int i;
	for (i = g_numentities - 1; i >= 1; i--) // so it won't affect the remaining entities in the loop when we move this entity backward
	{
		const char *name = ValueForKey (&g_entities[i], "zhlt_usemodel");
		if (!*name)
		{
			continue;
		}
		int j;
		for (j = 1; j < g_numentities; j++)
		{
			if (*ValueForKey (&g_entities[j], "zhlt_usemodel"))
			{
				continue;
			}
			if (!strcmp (name, ValueForKey (&g_entities[j], "targetname")))
			{
				break;
			}
		}
		if (j == g_numentities)
		{
			if (!strcasecmp (name, "null"))
			{
				SetKeyValue (&g_entities[i], "model", "");
				continue;
			}
			Error ("zhlt_usemodel: can not find target entity '%s', or that entity is also using 'zhlt_usemodel'.\n", name);
		}
		SetKeyValue (&g_entities[i], "model", ValueForKey (&g_entities[j], "model"));
		if (j > i)
		{
			// move this entity backward
			// to prevent precache error in case of .mdl/.spr and wrong result of EntityForModel in case of map model
			entity_t tmp;
			tmp = g_entities[i];
			memmove (&g_entities[i], &g_entities[i + 1], ((j + 1) - (i + 1)) * sizeof (entity_t));
			g_entities[j] = tmp;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x2009506(%rip), %rax   # 0x201f454
movslq (%rax), %r15
cmpq $0x2, %r15
jl 0x16105
leaq 0x20094fe(%rip), %rax   # 0x201f460
leaq 0x9fdf(%rip), %rbx      # 0x1ff48
addq $0x28, %rax
movq %rax, (%rsp)
movq %r15, %r14
decq %r15
leaq (%r15,%r15,4), %r13
shlq $0x3, %r13
addq 0x12052(%rip), %r13     # 0x27fd8
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7599
cmpb $0x0, (%rax)
je 0x160fb
movq %rax, %rbp
movl $0x1, %r12d
leaq 0x20094aa(%rip), %rax   # 0x201f454
cmpl $0x2, (%rax)
jl 0x16007
movq %r15, 0x8(%rsp)
movl $0x1, %r12d
movq (%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7599
cmpb $0x0, (%rax)
jne 0x15fec
movq %r15, %rdi
leaq 0x6780(%rip), %rsi      # 0x1c758
callq 0x7599
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4450
testl %eax, %eax
je 0x16002
incq %r12
leaq 0x200945e(%rip), %rax   # 0x201f454
movslq (%rax), %rax
addq $0x28, %r15
cmpq %rax, %r12
jl 0x15fbe
movq 0x8(%rsp), %r15
leaq 0x2009446(%rip), %rax   # 0x201f454
cmpl (%rax), %r12d
jne 0x1603b
movq %rbp, %rdi
leaq 0x9b9f(%rip), %rsi      # 0x1fbbc
callq 0x4340
testl %eax, %eax
je 0x160de
leaq 0xa8cc(%rip), %rdi      # 0x208fd
movq %rbp, %rsi
xorl %eax, %eax
callq 0xa2a0
movl %r12d, %eax
leaq (%rax,%rax,4), %rbp
shlq $0x3, %rbp
addq 0x11f8b(%rip), %rbp     # 0x27fd8
movq %rbp, %rdi
leaq 0x9ef9(%rip), %rbx      # 0x1ff50
movq %rbx, %rsi
callq 0x7599
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x75d4
movslq %r12d, %rax
cmpq %rax, %r14
leaq 0x9ece(%rip), %rbx      # 0x1ff48
jg 0x160fb
movq 0x20(%r13), %rax
movq %rax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq (%r14,%r14,4), %rsi
shlq $0x3, %rsi
addq 0x11f30(%rip), %rsi     # 0x27fd8
subl %r14d, %r12d
incl %r12d
movslq %r12d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %r13, %rdi
callq 0x4530
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movups %xmm0, (%rbp)
movups %xmm1, 0x10(%rbp)
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rbp)
jmp 0x160fb
movq %r13, %rdi
leaq 0x9e68(%rip), %rsi      # 0x1ff50
leaq 0x7bca(%rip), %rdx      # 0x1dcb9
callq 0x75d4
leaq 0x9e4d(%rip), %rbx      # 0x1ff48
cmpq $0x2, %r14
jg 0x15f71
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq