// File: 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:
subq $0x38, %rsp
cmpl $0x0, 0x5262189(%rip)   # 0x52a79e4
jne 0x45862
jmp 0x45aee
leaq 0x840c3f(%rip), %rax    # 0x8864a8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
addq $0x4, %rax
movq 0x28(%rsp), %rcx
movslq (%rcx), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
leaq 0x840c13(%rip), %rax    # 0x8864a8
movq (%rax), %rax
leaq 0x840c05(%rip), %rcx    # 0x8864a4
movslq (%rcx), %rcx
addq %rcx, %rax
movq 0x20(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rax
addq $0x4, %rax
movq 0x28(%rsp), %rcx
movl (%rcx), %ecx
addl 0x526211d(%rip), %ecx   # 0x52a79e4
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
leaq 0x840bc7(%rip), %rax    # 0x8864a4
movslq (%rax), %rax
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
leaq 0x37a49(%rip), %rcx     # 0x7d340
movslq (%rcx), %rcx
cmpq %rcx, %rax
setle %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x25, %esi
callq 0xbf00
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
movslq 0x1c(%rsp), %rdx
callq 0x4570
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
subq %rax, %rcx
leaq 0x840b6c(%rip), %rax    # 0x8864a4
movslq (%rax), %rax
addq %rcx, %rax
movl %eax, %ecx
leaq 0x840b5d(%rip), %rax    # 0x8864a4
movl %ecx, (%rax)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x459a1
movq 0x28(%rsp), %rax
movslq 0x34(%rsp), %rcx
cmpl $0x0, 0x4(%rax,%rcx,4)
jge 0x45971
jmp 0x45994
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rax
subq %rax, %rsi
movq 0x28(%rsp), %rax
movslq 0x34(%rsp), %rcx
movslq 0x4(%rax,%rcx,4), %rdx
addq %rsi, %rdx
movl %edx, 0x4(%rax,%rcx,4)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x45951
movq 0x28(%rsp), %rax
movl (%rax), %eax
addl 0x5262036(%rip), %eax   # 0x52a79e4
cmpl $0x1000, %eax           # imm = 0x1000
setl %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x24, %esi
callq 0xbf00
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x526200c(%rip), %eax   # 0x52a79e4
jge 0x45a9f
leaq 0x840abf(%rip), %rax    # 0x8864a4
movl (%rax), %eax
movslq 0x34(%rsp), %rdx
leaq 0x5265ffd(%rip), %rcx   # 0x52ab9f0
addl (%rcx,%rdx,4), %eax
leaq 0x37943(%rip), %rcx     # 0x7d340
cmpl (%rcx), %eax
setle %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x25, %esi
callq 0xbf00
leaq 0x840a8f(%rip), %rax    # 0x8864a8
movq (%rax), %rdi
leaq 0x840a81(%rip), %rax    # 0x8864a4
movslq (%rax), %rax
addq %rax, %rdi
movslq 0x34(%rsp), %rcx
leaq 0x5261fbb(%rip), %rax   # 0x52a79f0
movq (%rax,%rcx,8), %rsi
movslq 0x34(%rsp), %rcx
leaq 0x5265fab(%rip), %rax   # 0x52ab9f0
movslq (%rax,%rcx,4), %rdx
callq 0x4280
leaq 0x840a4f(%rip), %rax    # 0x8864a4
movl (%rax), %edx
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movl (%rcx), %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,4)
movslq 0x34(%rsp), %rcx
leaq 0x5265f76(%rip), %rax   # 0x52ab9f0
movl (%rax,%rcx,4), %ecx
leaq 0x840a20(%rip), %rax    # 0x8864a4
addl (%rax), %ecx
leaq 0x840a17(%rip), %rax    # 0x8864a4
movl %ecx, (%rax)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x459ce
movl 0x5261f3f(%rip), %ecx   # 0x52a79e4
movq 0x28(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x5261f24(%rip), %eax   # 0x52a79e4
jge 0x45ae4
movslq 0xc(%rsp), %rcx
leaq 0x5261f22(%rip), %rax   # 0x52a79f0
movq (%rax,%rcx,8), %rdi
callq 0x43a0
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x45ab6
movl $0x0, 0x5261ef6(%rip)   # 0x52a79e4
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)