// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getFramePixels
void getFramePixels(FILE *f, txpHeader header, textureHeader *textures, frameHeader *frames) {
	unsigned int i/*, j*/, palsize;
	uint32_t compressedsize;
	unsigned char *palette = NULL;
	for(i = 0; i < header.numframes; i++) {
		frames[i].texpixels = textures[frames[i].sourcetexture].texpixels;
		if(frames[i].palette == textures[frames[i].sourcetexture].palette) frames[i].palpixels = textures[frames[i].sourcetexture].palpixels;
		else {
			fseek(f, frames[i].palette, SEEK_SET);
			switch(textures[frames[i].sourcetexture].bpp) {
				case 4: {
					palsize = 16*4;
					break;
				}
				case 5: {
					palsize = 256*4;
					break;
				}
				case 6: {
					fseek(f, 20, SEEK_CUR);
					fread(&compressedsize, 4, 1, f);
					palsize = compressedsize;
					fseek(f, textures[i].palette, SEEK_SET);
					break;
				}
			}
			
			palette = malloc(palsize);
			fread(palette, palsize, 1, f);
			frames[i].palpixels = buildPalette(palette, textures[frames[i].sourcetexture].bpp);
			free(palette);
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0xc(%rcx), %eax
jae 0x12fdc
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rdx
movl 0x14(%rdx), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jne 0x12ea6
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rcx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
jmp 0x12fcc
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movl 0x18(%rax,%rcx), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movl 0x14(%rcx,%rdx), %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x3c(%rbp)
subl $0x4, %eax
je 0x12f02
jmp 0x12eee
movl -0x3c(%rbp), %eax
subl $0x5, %eax
je 0x12f0b
jmp 0x12ef8
movl -0x3c(%rbp), %eax
subl $0x6, %eax
je 0x12f14
jmp 0x12f62
movl $0x40, -0x20(%rbp)
jmp 0x12f62
movl $0x400, -0x20(%rbp)     # imm = 0x400
jmp 0x12f62
movq -0x8(%rbp), %rdi
movl $0x14, %esi
movl $0x1, %edx
callq 0x10f0
movq -0x8(%rbp), %rcx
leaq -0x24(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x1040
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
movl -0x20(%rbp), %eax
movl %eax, %edi
callq 0x10d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
movq -0x8(%rbp), %rcx
movl $0x1, %edx
callq 0x1040
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
callq 0x12910
movq %rax, %rcx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rdi
callq 0x1030
jmp 0x12fce
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x12dfb
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)