// File: /workspace/github_cpp_makefile_star2_O2/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 0x524f3be(%rip), %rax   # 0x526e9d4
testq %rax, %rax
je 0x1f78f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x82de77(%rip), %rcx    # 0x84d4a8
movq (%rcx), %r15
movslq (%r15), %rcx
leaq (,%rcx,4), %rdx
leaq 0x4(%r15,%rcx,4), %rbx
leaq 0x82de59(%rip), %r13    # 0x84d4a4
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 0x24ccb(%rip), %rax     # 0x44340
movslq (%rax), %rax
xorl %edi, %edi
cmpq %rax, %rsi
setle %dil
pushq $0x25
popq %rsi
callq 0x92cb
movslq %ebp, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4560
addl %r12d, (%r13)
movslq (%r15), %rax
xorl %ecx, %ecx
cmpq %rax, %rcx
jge 0x1f6bb
movl 0x4(%r15,%rcx,4), %edx
testl %edx, %edx
js 0x1f6b6
addl %r12d, %edx
movl %edx, 0x4(%r15,%rcx,4)
incq %rcx
jmp 0x1f6a0
addl 0x524f313(%rip), %eax   # 0x526e9d4
xorl %edi, %edi
cmpl $0x1000, %eax           # imm = 0x1000
setl %dil
pushq $0x24
popq %rsi
callq 0x92cb
leaq 0x524f305(%rip), %r12   # 0x526e9e0
leaq 0x52532fe(%rip), %rbp   # 0x52729e0
xorl %ebx, %ebx
movslq 0x524f2e9(%rip), %r14   # 0x526e9d4
cmpq %r14, %rbx
jge 0x1f74f
movl (%rbp), %eax
addl (%r13), %eax
xorl %edi, %edi
leaq 0x24c40(%rip), %rcx     # 0x44340
cmpl (%rcx), %eax
setle %dil
pushq $0x25
popq %rsi
callq 0x92cb
movslq (%r13), %rdi
leaq 0x82dd8f(%rip), %rax    # 0x84d4a8
addq (%rax), %rdi
movq (%r12), %rsi
movslq (%rbp), %r14
movq %r14, %rdx
callq 0x4240
movl (%r13), %eax
movslq (%r15), %rcx
addq %rbx, %rcx
movl %eax, 0x4(%r15,%rcx,4)
addl %r14d, %eax
movl %eax, (%r13)
incq %rbx
addq $0x8, %r12
addq $0x4, %rbp
jmp 0x1f6e4
addl %r14d, (%r15)
xorl %ebx, %ebx
testl %r14d, %r14d
cmovlel %ebx, %r14d
shlq $0x3, %r14
leaq 0x524f27a(%rip), %r15   # 0x526e9e0
cmpq %rbx, %r14
je 0x1f77a
movq (%rbx,%r15), %rdi
callq 0x4380
addq $0x8, %rbx
jmp 0x1f766
andl $0x0, 0x524f253(%rip)   # 0x526e9d4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq