// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
leaq 0x2009f14(%rip), %rax   # 0x201d454
movl (%rax), %r14d
movq %r14, %rax
shlq $0x20, %rax
movabsq $0x200000000, %r13      # imm = 0x200000000
subq %rax, %r13
leaq 0x2009f02(%rip), %rax   # 0x201d460
leaq 0x9933(%rip), %rbx      # 0x1ce98
addq $0x28, %rax
movq %rax, 0x10(%rsp)
cmpl $0x2, %r14d
jl 0x136f7
leaq -0x1(%r14), %rax
movq %rax, 0x18(%rsp)
imulq $0x28, %rax, %r12
addq 0x12a4c(%rip), %r12     # 0x25fd8
movq %r12, %rdi
movq %rbx, %rsi
callq 0x69ab
cmpb $0x0, (%rax)
je 0x136e0
movq %rax, %r15
movq %r12, (%rsp)
movq 0x10(%rsp), %rbp
movq %r13, 0x8(%rsp)
movq %r13, %r12
pushq $0x1
popq %r13
leaq 0x2009e95(%rip), %rax   # 0x201d454
movslq (%rax), %rax
cmpq %rax, %r13
jge 0x13614
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x69ab
cmpb $0x0, (%rax)
jne 0x135f5
movq %rbp, %rdi
leaq 0x60d7(%rip), %rsi      # 0x196b8
callq 0x69ab
movq %r15, %rdi
movq %rax, %rsi
callq 0x4480
testl %eax, %eax
je 0x1360b
incq %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
addq $0x28, %rbp
jmp 0x135b8
leaq 0x2009e42(%rip), %rax   # 0x201d454
movl (%rax), %eax
cmpl %r13d, %eax
jne 0x13641
movq %r15, %rdi
leaq 0x94f9(%rip), %rsi      # 0x1cb1c
callq 0x4350
testl %eax, %eax
je 0x136c4
leaq 0xa1db(%rip), %rdi      # 0x1d812
movq %r15, %rsi
xorl %eax, %eax
callq 0x8d7b
movq %rbp, %rdi
leaq 0x9855(%rip), %rsi      # 0x1cea0
callq 0x69ab
movq (%rsp), %r15
movq %r15, %rdi
leaq 0x9842(%rip), %rsi      # 0x1cea0
movq %rax, %rdx
callq 0x69e6
cmpl %r14d, %r13d
movq 0x8(%rsp), %r13
jl 0x136e0
movq 0x20(%r15), %rax
movq %rax, 0x40(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
imulq $0x28, %r14, %rsi
addq 0x12941(%rip), %rsi     # 0x25fd8
sarq $0x20, %r12
imulq $0x28, %r12, %rdx
movq %r15, %rdi
callq 0x4550
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm0, (%rbp)
movups %xmm1, 0x10(%rbp)
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rbp)
jmp 0x136e0
movq (%rsp), %rdi
leaq 0x97d1(%rip), %rsi      # 0x1cea0
leaq 0x7543(%rip), %rdx      # 0x1ac19
callq 0x69e6
movq 0x8(%rsp), %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r13
movq 0x18(%rsp), %r14
jmp 0x1356e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq