// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getTxpHeader
txpHeader *getTxpHeader(unsigned char *data, unsigned int game) {
	txpHeaderPO *pohead = NULL;
	txpHeaderPW *pwhead = NULL;
	txpHeader *rethead = malloc(sizeof(txpHeader));
	
	printf("Raw header values:\n");
	
	switch(game) {
		case mgspo: {
			pohead = (txpHeaderPO *)data;
			
			printf("unknown1 - unknown2 - numTexts - texloffs - numFrame - framloff - unknown3 - unknown4\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pohead->unknown1, pohead->unknown2, pohead->numTextures, pohead->texlistOffset,
				pohead->numFrames, pohead->framelistOffset, pohead->unknown3, pohead->unknown4);
			
			rethead->namehash = 0;
			
			rethead->numtextures = pohead->numTextures;
			rethead->texturelist = pohead->texlistOffset;
			
			rethead->numframes = pohead->numFrames;
			rethead->framelist = pohead->framelistOffset;
			break;
		}
		case mgspw: {
			pwhead = (txpHeaderPW *)data;
			
			printf("unknown1 - namehash - numTexts - numFrame - unknown2 - texloffs - framloff - unknown3\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pwhead->unknown1, pwhead->namehash, pwhead->numTextures, pwhead->numFrames,
				pwhead->unknown2, pwhead->texlistOffset, pwhead->framelistOffset, pwhead->unknown3);
			
			rethead->namehash = pwhead->namehash;
			
			rethead->numtextures = pwhead->numTextures;
			rethead->texturelist = pwhead->texlistOffset;
			
			rethead->numframes = pwhead->numFrames;
			rethead->framelist = pwhead->framelistOffset;
			break;
		}
		default: {
			printf("i am asplod\n");
			break;
		}
	}
	
	printf("Processed header values:\nnamehash %08x - numtex %d - texoff %08x - numframe %d - frameoff %08x\n",
		rethead->namehash, rethead->numtextures, rethead->texturelist, rethead->numframes, rethead->framelist);
	
	return rethead;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x14, %edi
callq 0x10d0
movq %rax, -0x28(%rbp)
leaq 0x3c84(%rip), %rdi      # 0x15478
xorl %eax, %eax
callq 0x1080
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x11818
jmp 0x11807
movl -0x2c(%rbp), %eax
subl $0x1, %eax
je 0x118cb
jmp 0x1197e
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq 0x3c65(%rip), %rdi      # 0x1548c
movb $0x0, %al
callq 0x1080
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl 0xc(%rax), %r8d
movq -0x18(%rbp), %rax
movl 0x10(%rax), %r9d
movq -0x18(%rbp), %rax
movl 0x14(%rax), %r11d
movq -0x18(%rbp), %rax
movl 0x18(%rax), %r10d
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
leaq 0x3c73(%rip), %rdi      # 0x154e3
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x1198c
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x3c40(%rip), %rdi      # 0x1551a
movb $0x0, %al
callq 0x1080
movq -0x20(%rbp), %rax
movl (%rax), %esi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0xc(%rax), %r8d
movq -0x20(%rbp), %rax
movl 0x10(%rax), %r9d
movq -0x20(%rbp), %rax
movl 0x14(%rax), %r11d
movq -0x20(%rbp), %rax
movl 0x18(%rax), %r10d
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
leaq 0x3bc0(%rip), %rdi      # 0x154e3
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1080
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x1198c
leaq 0x3bec(%rip), %rdi      # 0x15571
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl 0xc(%rax), %r8d
movq -0x28(%rbp), %rax
movl 0x10(%rax), %r9d
leaq 0x3bc7(%rip), %rdi      # 0x1557e
movb $0x0, %al
callq 0x1080
movq -0x28(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)