// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/loadtextures.cpp
// Function: NewTextures_Write()
void NewTextures_Write ()
{
	if (!g_newtextures_num)
	{
		return;
	}

	int i;
	dmiptexlump_t *texdata = (dmiptexlump_t *)g_dtexdata;

	byte *dataaddr = (byte *)&texdata->dataofs[texdata->nummiptex];
	int datasize = (g_dtexdata + g_texdatasize) - dataaddr;
	byte *newdataaddr = (byte *)&texdata->dataofs[texdata->nummiptex + g_newtextures_num];
	hlassume (g_texdatasize + (newdataaddr - dataaddr) <= g_max_map_miptex, assume_MAX_MAP_MIPTEX);
	memmove (newdataaddr, dataaddr, datasize);
	g_texdatasize += newdataaddr - dataaddr;
	for (i = 0; i < texdata->nummiptex; i++)
	{
		if (texdata->dataofs[i] < 0) // bad texture
		{
			continue;
		}
		texdata->dataofs[i] += newdataaddr - dataaddr;
	}

	hlassume (texdata->nummiptex + g_newtextures_num < MAX_MAP_TEXTURES, assume_MAX_MAP_TEXTURES);
	for (i = 0; i < g_newtextures_num; i++)
	{
		hlassume (g_texdatasize + g_newtextures_size[i] <= g_max_map_miptex, assume_MAX_MAP_MIPTEX);
		memcpy (g_dtexdata + g_texdatasize, g_newtextures_data[i], g_newtextures_size[i]);
		texdata->dataofs[texdata->nummiptex + i] = g_texdatasize;
		g_texdatasize += g_newtextures_size[i];
	}
	texdata->nummiptex += g_newtextures_num;

	for (int i = 0; i < g_newtextures_num; i++)
	{
		free (g_newtextures_data[i]);
	}
	g_newtextures_num = 0;
}

// Assembly:
movslq 0x524f3ec(%rip), %rax   # 0x52719c4
testq %rax, %rax
je 0x22769
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x82dea5(%rip), %rcx    # 0x850498
movq (%rcx), %r15
movslq (%r15), %rcx
leaq (,%rcx,4), %rdx
leaq 0x4(%r15,%rcx,4), %rbx
leaq 0x82de87(%rip), %r13    # 0x850494
movslq (%r13), %rsi
leal (%r15,%rsi), %ebp
subl %ebx, %ebp
addq %rcx, %rax
leaq (,%rax,4), %r12
subq %rdx, %r12
leaq (%r15,%rax,4), %r14
addq $0x4, %r14
addq %r12, %rsi
leaq 0x24cf9(%rip), %rax     # 0x47330
movslq (%rax), %rax
xorl %edi, %edi
cmpq %rax, %rsi
setle %dil
movl $0x25, %esi
callq 0xa6ed
movslq %ebp, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4540
addl %r12d, (%r13)
movslq (%r15), %rax
testq %rax, %rax
jle 0x22682
leaq 0x4(%r15), %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %esi
testl %esi, %esi
js 0x2267a
addl %r12d, %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpq %rax, %rdx
jb 0x2266d
addl 0x524f33c(%rip), %eax   # 0x52719c4
xorl %edi, %edi
cmpl $0x1000, %eax           # imm = 0x1000
setl %dil
movl $0x24, %esi
callq 0xa6ed
movl 0x524f321(%rip), %eax   # 0x52719c4
testl %eax, %eax
jle 0x2274e
movl (%r13), %eax
leaq 0x524f31a(%rip), %r14   # 0x52719d0
leaq 0x5253313(%rip), %r12   # 0x52759d0
xorl %ebp, %ebp
addl (%r12), %eax
xorl %edi, %edi
leaq 0x24c64(%rip), %rcx     # 0x47330
cmpl (%rcx), %eax
setle %dil
movl $0x25, %esi
callq 0xa6ed
movslq (%r13), %rdi
leaq 0x82ddb1(%rip), %rax    # 0x850498
addq (%rax), %rdi
movq (%r14), %rsi
movslq (%r12), %rbx
movq %rbx, %rdx
callq 0x4240
movl (%r13), %eax
movslq (%r15), %rcx
addq %rbp, %rcx
movl %eax, 0x4(%r15,%rcx,4)
addl %ebx, %eax
movl %eax, (%r13)
incq %rbp
movslq 0x524f2ac(%rip), %rbx   # 0x52719c4
addq $0x8, %r14
addq $0x4, %r12
cmpq %rbx, %rbp
jl 0x226bf
addl %ebx, (%r15)
testl %ebx, %ebx
jle 0x22751
shlq $0x3, %rbx
xorl %r14d, %r14d
leaq 0x524f296(%rip), %r15   # 0x52719d0
movq (%r14,%r15), %rdi
callq 0x4370
addq $0x8, %r14
cmpq %r14, %rbx
jne 0x2273a
jmp 0x22751
addl %eax, (%r15)
movl $0x0, 0x524f269(%rip)   # 0x52719c4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq