// File: /workspace/github_cpp_makefile_star2_O3/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 0x2009a24(%rip), %rax   # 0x201f444
movslq (%rax), %r15
cmpq $0x2, %r15
jl 0x15bdd
leaq 0x2009a1c(%rip), %rax   # 0x201f450
leaq 0xa52d(%rip), %rbx      # 0x1ff68
addq $0x28, %rax
movq %rax, (%rsp)
movq %r15, %r14
decq %r15
leaq (%r15,%r15,4), %r13
shlq $0x3, %r13
addq 0x12580(%rip), %r13     # 0x27fd8
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7542
cmpb $0x0, (%rax)
je 0x15bd3
movq %rax, %rbp
leaq 0x20099ce(%rip), %rax   # 0x201f444
movl (%rax), %eax
movl $0x1, %r12d
cmpl $0x2, %eax
jl 0x15ae6
movq %r15, 0x8(%rsp)
movl $0x1, %r12d
movq (%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7542
cmpb $0x0, (%rax)
jne 0x15ac0
movq %r15, %rdi
leaq 0x6ca4(%rip), %rsi      # 0x1c750
callq 0x7542
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4440
testl %eax, %eax
je 0x15ad8
incq %r12
leaq 0x200997a(%rip), %rax   # 0x201f444
movslq (%rax), %rax
addq $0x28, %r15
cmpq %rax, %r12
jl 0x15a92
jmp 0x15ae1
leaq 0x2009965(%rip), %rax   # 0x201f444
movl (%rax), %eax
movq 0x8(%rsp), %r15
cmpl %eax, %r12d
jne 0x15b13
movq %rbp, %rdi
leaq 0xa0b7(%rip), %rsi      # 0x1fbac
callq 0x4330
testl %eax, %eax
je 0x15bb6
leaq 0xae19(%rip), %rdi      # 0x20922
movq %rbp, %rsi
xorl %eax, %eax
callq 0xa164
movl %r12d, %eax
leaq (%rax,%rax,4), %rbp
shlq $0x3, %rbp
addq 0x124b3(%rip), %rbp     # 0x27fd8
movq %rbp, %rdi
leaq 0xa441(%rip), %rbx      # 0x1ff70
movq %rbx, %rsi
callq 0x7542
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x757d
movslq %r12d, %rax
cmpq %rax, %r14
leaq 0xa416(%rip), %rbx      # 0x1ff68
jg 0x15bd3
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 0x12458(%rip), %rsi     # 0x27fd8
subl %r14d, %r12d
incl %r12d
movslq %r12d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %r13, %rdi
callq 0x4520
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movups %xmm0, (%rbp)
movups %xmm1, 0x10(%rbp)
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rbp)
jmp 0x15bd3
movq %r13, %rdi
leaq 0xa3b0(%rip), %rsi      # 0x1ff70
leaq 0x80e2(%rip), %rdx      # 0x1dca9
callq 0x757d
leaq 0xa395(%rip), %rbx      # 0x1ff68
cmpq $0x2, %r14
jg 0x15a43
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq