// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getTextureInfos
textureHeader *getTextureInfos(FILE *f, txpHeader header, unsigned int game) {
	unsigned int i, j;
	textureHeaderPW *pwtex = NULL;
	textureHeaderPO *potex = NULL;
	textureHeader *rethead = malloc(header.numtextures * sizeof(textureHeader));
	fseek(f, header.texturelist, SEEK_SET);
	
	printf("Raw texture values:\n");
	printf(" index ~ wdth - unk1 - hght - unk2 - bpp  - unk3 - comp - unk4 -  offset  - palette\n");
	
	switch(game) {
		case mgspo: {
			potex = malloc(header.numtextures * sizeof(textureHeaderPO));
			fread(potex, header.numtextures * sizeof(textureHeaderPO), 1, f);
			for(i = 0; i < header.numtextures; i++) {
				printf("idx %02d ~ %04x - %04x - %04x - %04x - %04x - %04x - %04x - %04x - %08x - %08x\n", i,
					potex[i].width, potex[i].unknown1, potex[i].height, potex[i].unknown2,
					potex[i].bpp, potex[i].unknown3, potex[i].compressed, potex[i].unknown4,
					potex[i].offset, potex[i].palette);
				
				rethead[i].texpixels = NULL;
				rethead[i].palpixels = NULL;
				rethead[i].bpp = potex[i].bpp;
				rethead[i].compressed = potex[i].compressed;
				rethead[i].width = potex[i].width;
				rethead[i].height = potex[i].height;
				
				rethead[i].offset = potex[i].offset;
				/* portableops has one per-texture palette */
				rethead[i].palette = potex[i].palette;
			}
			free(potex);
			break;
		}
		case mgspw: {
			pwtex = malloc(header.numtextures * sizeof(textureHeaderPW));
			fread(pwtex, header.numtextures * sizeof(textureHeaderPW), 1, f);
			for(i = 0; i < header.numtextures; i++) {
				printf("idx %02d ~ %04x - %04x - %04x - %04x - %04x - %04x\n", i,
					pwtex[i].bpp, pwtex[i].compressed, pwtex[i].width, pwtex[i].unknown1,
					pwtex[i].height, pwtex[i].unknown2);
				for(j = 0; i < 6; j++) printf("%02x ", pwtex[i].unknown3[j]);
				printf("\n%08x - %08x\n", pwtex[i].offset, pwtex[i].zoffset);
				
				rethead[i].texpixels = NULL;
				rethead[i].palpixels = NULL;
				rethead[i].bpp = pwtex[i].bpp;
				rethead[i].compressed = pwtex[i].compressed;
				rethead[i].width = pwtex[i].width;
				rethead[i].height = pwtex[i].height;
				/* peacewalker has two different offsets for compressed and uncompressed */
				rethead[i].offset = pwtex[i].compressed ? pwtex[i].zoffset : pwtex[i].offset;
				/* peacewalker has per-frame palettes, not per-texture palettes */
				rethead[i].palette = 0;
			}
			free(pwtex);
			break;
		}
		default: {
			printf("i am asplod again\n");
			break;
		}
	}
	
	printf("Processed texture data:\n");
	printf(" index ~ bpp  - comp - wdth - hght -  offset  - palette\n");
	for(i = 0; i < header.numtextures; i++) printf("idx %02d ~ %04x - %04x - %04d - %04d - %08x - %08x\n", i,
				rethead[i].bpp, rethead[i].compressed, rethead[i].width, rethead[i].height,
				rethead[i].offset, rethead[i].palette);
	
	return rethead;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl 0x4(%rax), %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movl 0x8(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
movl %edx, -0x54(%rbp)
callq 0x10f0
movl -0x54(%rbp), %eax
leaq 0x3ba7(%rip), %rdi      # 0x155de
movb %al, -0x4d(%rbp)
callq 0x1080
movb -0x4d(%rbp), %al
leaq 0x3baa(%rip), %rdi      # 0x155f3
callq 0x1080
movl -0x24(%rbp), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x11a6b
jmp 0x11a5a
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0x11d2b
jmp 0x11ff2
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
movq -0x20(%rbp), %rcx
movl $0x1, %edx
callq 0x1040
movl $0x0, -0x28(%rbp)
movq -0x60(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x11d1d
movl -0x28(%rbp), %esi
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
andq $0xfff, %rax            # imm = 0xFFF
movzwl %ax, %edx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0xc, %rax
andq $0xf, %rax
movzwl %ax, %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x10, %rax
andq $0xfff, %rax            # imm = 0xFFF
movzwl %ax, %r8d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x1c, %rax
andq $0xf, %rax
movzwl %ax, %r9d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0xf, %rax
movzwl %ax, %r15d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x24, %rax
andq $0xfff, %rax            # imm = 0xFFF
movzwl %ax, %r14d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x30, %rax
andq $0xf, %rax
movzwl %ax, %ebx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movq (%rax), %rax
shrq $0x34, %rax
movzwl %ax, %r11d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movl 0x8(%rax), %r10d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rax
movl 0xc(%rax), %eax
leaq 0x3a7e(%rip), %rdi      # 0x15648
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x0, %al
callq 0x1080
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0xf, %rax
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x30, %rax
andq $0xf, %rax
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
andq $0xfff, %rax            # imm = 0xFFF
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x10, %rax
andq $0xfff, %rax            # imm = 0xFFF
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x11aaa
movq -0x40(%rbp), %rdi
callq 0x1030
jmp 0x12000
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
imulq $0x14, %rax, %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl 0x4(%rax), %eax
imulq $0x14, %rax, %rsi
movq -0x20(%rbp), %rcx
movl $0x1, %edx
callq 0x1040
movl $0x0, -0x28(%rbp)
movq -0x60(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x11fe7
movl -0x28(%rbp), %esi
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0xf, %eax
movzwl %ax, %edx
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xfff, %eax            # imm = 0xFFF
movzwl %ax, %ecx
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x14, %rdi, %rdi
addq %rdi, %rax
movl (%rax), %eax
shrl $0x10, %eax
andl $0xfff, %eax            # imm = 0xFFF
movzwl %ax, %r8d
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x14, %rdi, %rdi
addq %rdi, %rax
movl (%rax), %eax
shrl $0x1c, %eax
movzwl %ax, %r9d
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x14, %rdi, %rdi
addq %rdi, %rax
movw 0x4(%rax), %ax
andw $0xfff, %ax             # imm = 0xFFF
movzwl %ax, %r10d
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x14, %rdi, %rdi
addq %rdi, %rax
movw 0x4(%rax), %ax
shrw $0xc, %ax
movzwl %ax, %eax
leaq 0x3881(%rip), %rdi      # 0x15698
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x1080
movl $0x0, -0x2c(%rbp)
cmpl $0x6, -0x28(%rbp)
jae 0x11e62
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl -0x2c(%rbp), %ecx
movzbl 0x6(%rax,%rcx), %esi
leaq 0x387c(%rip), %rdi      # 0x156cc
movb $0x0, %al
callq 0x1080
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11e2d
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %esi
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
leaq 0x3847(%rip), %rdi      # 0x156d2
movb $0x0, %al
callq 0x1080
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0xf, %eax
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xfff, %eax            # imm = 0xFFF
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x10, %eax
andl $0xfff, %eax            # imm = 0xFFF
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movw 0x4(%rax), %ax
andw $0xfff, %ax             # imm = 0xFFF
movzwl %ax, %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xfff, %eax            # imm = 0xFFF
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x11f9c
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x64(%rbp)
jmp 0x11fb0
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x14(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x11d66
movq -0x38(%rbp), %rdi
callq 0x1030
jmp 0x12000
leaq 0x36e7(%rip), %rdi      # 0x156e0
movb $0x0, %al
callq 0x1080
leaq 0x36ec(%rip), %rdi      # 0x156f3
movb $0x0, %al
callq 0x1080
leaq 0x36f7(%rip), %rdi      # 0x1570c
movb $0x0, %al
callq 0x1080
movl $0x0, -0x28(%rbp)
movq -0x60(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x120c2
movl -0x28(%rbp), %esi
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0x8(%rax), %r8d
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0xc(%rax), %r9d
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0x10(%rax), %r10d
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0x14(%rax), %eax
leaq 0x36a0(%rip), %rdi      # 0x15745
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x1080
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x12023
movq -0x48(%rbp), %rax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)