// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
movl $0x14, %edi
callq 0x1100
movq %rax, %rbx
leaq 0x30d4(%rip), %rdi      # 0xfe17
callq 0x1050
cmpl $0x1, %ebp
je 0xcdb4
testl %ebp, %ebp
jne 0xce55
leaq 0x3124(%rip), %rdi      # 0xfe80
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq 0x8(%r14), %rax
movq %rax, (%rsp)
movl 0x8(%r14), %ecx
leaq 0xc(%r14), %r13
movl 0xc(%r14), %r8d
leaq 0x10(%r14), %r12
movl 0x10(%r14), %r9d
leaq 0x14(%r14), %r15
movl 0x14(%r14), %r10d
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %r14d
subq $0x8, %rsp
leaq 0x2d21(%rip), %rdi      # 0xfac0
xorl %ebp, %ebp
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
jmp 0xce12
leaq 0x306f(%rip), %rdi      # 0xfe2a
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq 0x8(%r14), %rax
movq %rax, (%rsp)
movl 0x8(%r14), %ecx
leaq 0xc(%r14), %r12
movl 0xc(%r14), %r8d
movl 0x10(%r14), %r9d
leaq 0x14(%r14), %r13
movl 0x14(%r14), %r10d
leaq 0x18(%r14), %r15
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %ebp
subq $0x8, %rsp
leaq 0x2cc2(%rip), %rdi      # 0xfac0
xorl %eax, %eax
pushq %rbp
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
movl 0x4(%r14), %ebp
movl %ebp, (%rbx)
movq (%rsp), %rax
movl (%rax), %edx
movl %edx, 0x4(%rbx)
movl (%r13), %ecx
movl %ecx, 0x8(%rbx)
movl (%r12), %r8d
movl %r8d, 0xc(%rbx)
movl (%r15), %r9d
movl %r9d, 0x10(%rbx)
leaq 0x2cbd(%rip), %rdi      # 0xfaf7
movl %ebp, %esi
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1180