// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getFrameInfos
frameHeader *getFrameInfos(FILE *f, txpHeader header, textureHeader *textures, unsigned int game) {
	unsigned int i;
	frameHeaderPW *pwframe = NULL;
	frameHeaderPO *poframe = NULL;
	frameHeader *rethead = malloc(header.numframes * sizeof(frameHeader));
	fseek(f, header.framelist, SEEK_SET);
	
	printf("Raw frame values:\n");
	
	switch(game) {
		case mgspo: {
			printf(" index ~ unknown1 -   hash   - unknown2 - wdth - hght - unknown3 - texture  - unknown4 -    fx    -    fy    -  fwidth  - fheight  - unknown5\n");
			poframe = malloc(header.numframes * sizeof(frameHeaderPO));
			fread(poframe, header.numframes * sizeof(frameHeaderPO), 1, f);
			for(i = 0; i < header.numframes; i++) {
				printf("idx %02d ~ %08x - %08x - %08x - %04x - %04x - %08x - %08x - %08x - %f - %f - %f - %f - %08x\n", i,
					poframe[i].unknown1, poframe[i].hash, poframe[i].unknown2, poframe[i].width, poframe[i].height,
					poframe[i].unknown3, poframe[i].texture, poframe[i].unknown4,
					poframe[i].fx, poframe[i].fy, poframe[i].fwidth, poframe[i].fheight,
					poframe[i].unknown5);
				
				rethead[i].texpixels = NULL;
				rethead[i].palpixels = NULL;
				rethead[i].hash = poframe[i].hash;
				rethead[i].width = poframe[i].width;
				rethead[i].height = poframe[i].height;
				/* this is just the offset to the matching texture header */
				rethead[i].sourcetexture = (poframe[i].texture - header.texturelist) / 16;
				/* portableops doesnt store the source x and y directly, but as relative floats
				   so we need the sourcetexture first */
				rethead[i].sourcex = (unsigned int)(textures[rethead[i].sourcetexture].width * poframe[i].fx);
				rethead[i].sourcey = (unsigned int)(textures[rethead[i].sourcetexture].height * poframe[i].fy);
				
				/* portableops has one palette per texture */
				rethead[i].palette = textures[rethead[i].sourcetexture].palette;
			}
			free(poframe);
			break;
		}
		case mgspw: {
			pwframe = malloc(header.numframes * sizeof(frameHeaderPW));
			fread(pwframe, header.numframes * sizeof(frameHeaderPW), 1, f);
			for(i = 0; i < header.numframes; i++) {
				printf("idx %02d ~ %08x - %08x - %08x - %08x - %f - %f - %f - %f - %04x - %04x - %04x - %04x\n", i,
					pwframe[i].unknown1, pwframe[i].hash, pwframe[i].texture, pwframe[i].palette,
					pwframe[i].fx, pwframe[i].fy, pwframe[i].fwidth, pwframe[i].fheight,
					pwframe[i].width, pwframe[i].height, pwframe[i].x, pwframe[i].y);
			
				rethead[i].texpixels = NULL;
				rethead[i].palpixels = NULL;
				rethead[i].hash = pwframe[i].hash;
				rethead[i].width = pwframe[i].width;
				rethead[i].height = pwframe[i].height;
				/* this is just the offset to the matching texture header */
				rethead[i].sourcetexture = (pwframe[i].texture - header.texturelist) / 20;
				/* peacewalker has an absolute source x and y stored as well as relative ones */
				rethead[i].sourcex = pwframe[i].x;
				rethead[i].sourcey = pwframe[i].y;
				
				/* peacewalker has one palette per frame */
				rethead[i].palette = pwframe[i].palette;
			}
			free(pwframe);
			break;
		}
		default: {
			printf("TRIPLE FAULT YAY\n");
			break;
		}
	}
	
	printf("Processed frame values:\n");
	printf(" index ~   hash   - wdth - hgth - tx - srcx - srcy - palette\n");
	for(i = 0; i < header.numframes; i++) printf("idx %02d ~ %08x - %04d - %04d - %02d - %04d - %04d - %08x\n", i,
				rethead[i].hash, rethead[i].width, rethead[i].height, rethead[i].sourcetexture,
				rethead[i].sourcex, rethead[i].sourcey, rethead[i].palette);
	
	return rethead;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x80, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl 0xc(%rax), %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl 0x10(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
movl %edx, -0x48(%rbp)
callq 0x10f0
movl -0x48(%rbp), %eax
leaq 0x3630(%rip), %rdi      # 0x15779
callq 0x1080
movl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
je 0x1216b
jmp 0x1215a
movl -0x44(%rbp), %eax
subl $0x1, %eax
je 0x123d5
jmp 0x12675
leaq 0x361a(%rip), %rdi      # 0x1578c
movb $0x0, %al
callq 0x1080
movq -0x50(%rbp), %rax
movl 0xc(%rax), %eax
imulq $0x30, %rax, %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl 0xc(%rax), %eax
imulq $0x30, %rax, %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x1040
movl $0x0, -0x28(%rbp)
movq -0x50(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0xc(%rcx), %eax
jae 0x123c7
movl -0x28(%rbp), %eax
movl %eax, %ecx
movl %ecx, %esi
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq (%rcx,%rcx,2), %r14
shlq $0x4, %r14
movq %r14, -0x58(%rbp)
movl (%rax,%r14), %edx
movl 0x4(%rax,%r14), %ecx
movl 0x8(%rax,%r14), %r8d
movzwl 0xc(%rax,%r14), %r9d
movzwl 0xe(%rax,%r14), %edi
movl 0x10(%rax,%r14), %r10d
movl 0x14(%rax,%r14), %r11d
movl 0x18(%rax,%r14), %ebx
movss 0x1c(%rax,%r14), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x20(%rax,%r14), %xmm1
cvtss2sd %xmm1, %xmm1
movss 0x24(%rax,%r14), %xmm2
cvtss2sd %xmm2, %xmm2
movss 0x28(%rax,%r14), %xmm3
cvtss2sd %xmm3, %xmm3
movl 0x2c(%rax,%r14), %r14d
movq %rsp, %rax
movl %r14d, 0x20(%rax)
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %edi, (%rax)
leaq 0x35c7(%rip), %rdi      # 0x1581b
movb $0x4, %al
callq 0x1080
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x28(%rbp), %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq $0x0, 0x20(%rcx,%rdx)
movq -0x40(%rbp), %rcx
movl -0x28(%rbp), %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq $0x0, 0x28(%rcx,%rdx)
movq -0x38(%rbp), %rcx
movl -0x28(%rbp), %edx
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x4(%rcx,%rdx), %esi
movq -0x40(%rbp), %rcx
movl %esi, (%rcx,%rdx)
movq -0x38(%rbp), %rcx
movl -0x28(%rbp), %edx
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rdx
movzwl 0xc(%rcx,%rdx), %esi
movq -0x40(%rbp), %rcx
movl %esi, 0x4(%rcx,%rdx)
movq -0x38(%rbp), %rcx
movl -0x28(%rbp), %edx
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rdx
movzwl 0xe(%rcx,%rdx), %esi
movq -0x40(%rbp), %rcx
movl %esi, 0x8(%rcx,%rdx)
movq -0x38(%rbp), %rdx
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x14(%rdx,%rcx), %edx
movl 0x8(%rax), %eax
subl %eax, %edx
shrl $0x4, %edx
movq -0x40(%rbp), %rax
movl %edx, 0x14(%rax,%rcx)
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x14(%rax,%rcx), %esi
leaq (%rsi,%rsi,4), %rsi
movl 0x8(%rdx,%rsi,8), %edx
cvtsi2ss %rdx, %xmm0
movq -0x38(%rbp), %rdx
movss 0x1c(%rdx,%rcx), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %rdx
movl %edx, 0xc(%rax,%rcx)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rdx
movl -0x28(%rbp), %ecx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x14(%rdx,%rcx), %edx
leaq (%rdx,%rdx,4), %rdx
movl 0xc(%rax,%rdx,8), %eax
cvtsi2ss %rax, %xmm0
movq -0x38(%rbp), %rax
movss 0x20(%rax,%rcx), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x121b4
movq -0x38(%rbp), %rdi
callq 0x1030
jmp 0x12683
movq -0x50(%rbp), %rax
movl 0xc(%rax), %eax
imulq $0x28, %rax, %rdi
callq 0x10d0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl 0xc(%rax), %eax
imulq $0x28, %rax, %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x1040
movl $0x0, -0x28(%rbp)
movq -0x50(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0xc(%rcx), %eax
jae 0x1266a
movl -0x28(%rbp), %esi
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0x8(%rax), %r8d
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movl 0xc(%rax), %r9d
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movss 0x10(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movss 0x14(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movss 0x18(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movss 0x1c(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movzwl 0x20(%rax), %ebx
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movzwl 0x22(%rax), %r11d
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movzwl 0x24(%rax), %r10d
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movzwl 0x26(%rax), %eax
leaq 0x3363(%rip), %rdi      # 0x15878
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x4, %al
callq 0x1080
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq $0x0, 0x20(%rax)
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl 0x4(%rax), %edx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rax
movl %edx, (%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movzwl 0x20(%rax), %edx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rax
movl %edx, 0x4(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movzwl 0x22(%rax), %edx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rax
movl %edx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl 0x8(%rax), %eax
subl 0x8(%rcx), %eax
movl $0x14, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzwl 0x24(%rax), %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzwl 0x26(%rax), %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x12410
movq -0x30(%rbp), %rdi
callq 0x1030
jmp 0x12683
leaq 0x3252(%rip), %rdi      # 0x158ce
movb $0x0, %al
callq 0x1080
leaq 0x3256(%rip), %rdi      # 0x158e0
movb $0x0, %al
callq 0x1080
leaq 0x3261(%rip), %rdi      # 0x158f9
movb $0x0, %al
callq 0x1080
movl $0x0, -0x28(%rbp)
movq -0x50(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0xc(%rcx), %eax
jae 0x1275c
movl -0x28(%rbp), %esi
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x30, %rdi, %rdi
addq %rdi, %rax
movl 0x8(%rax), %r8d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x30, %rdi, %rdi
addq %rdi, %rax
movl 0x14(%rax), %r9d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x30, %rdi, %rdi
addq %rdi, %rax
movl 0xc(%rax), %r11d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x30, %rdi, %rdi
addq %rdi, %rax
movl 0x10(%rax), %r10d
movq -0x40(%rbp), %rax
movl -0x28(%rbp), %edi
imulq $0x30, %rdi, %rdi
addq %rdi, %rax
movl 0x18(%rax), %eax
leaq 0x31fd(%rip), %rdi      # 0x15937
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1080
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x126a6
movq -0x40(%rbp), %rax
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)