// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/txp-convert.c
// Function: unfiddle
unsigned char *unfiddle(unsigned char *source, unsigned int width, unsigned int height, unsigned int bpp) {
	unsigned char *retpixel = malloc(width*height);
	unsigned int x, y, yc0, yc1, xc0, xc1, memptr = 0;
	for(y = 0; y < height; y++) {
		yc0 = y*16;
		if(bpp == 4) {
			yc1 = y/8*(width*4-128);
			for(x = 0; x < width/2; x++) {
				xc0 = x/16*16;
				xc1 = x/16*128;
				retpixel[memptr] = source[x-xc0+xc1+yc0+yc1] & 0xF;
				memptr++;
				retpixel[memptr] = source[x-xc0+xc1+yc0+yc1] >> 4;
				memptr++;
			}
		}
		else {
			yc1 = y/8*(width*8-128);
			for(x = 0; x < width; x++) {
				xc0 = x/16*16;
				xc1 = x/16*128;
				retpixel[memptr] = source[x-xc0+xc1+yc0+yc1];
				memptr++;
			}
		}
	}
	return retpixel;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x10d0
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x12906
movl -0x28(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x4, -0x14(%rbp)
jne 0x1287f
movl -0x28(%rbp), %eax
shrl $0x3, %eax
movl -0xc(%rbp), %ecx
shll $0x2, %ecx
subl $0x80, %ecx
imull %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0xc(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x1287d
movl -0x24(%rbp), %eax
shrl $0x4, %eax
shll $0x4, %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
shrl $0x4, %eax
shll $0x7, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
subl -0x34(%rbp), %ecx
addl -0x38(%rbp), %ecx
addl -0x2c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
subl -0x34(%rbp), %ecx
addl -0x38(%rbp), %ecx
addl -0x2c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
sarl $0x4, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x127e5
jmp 0x128f6
movl -0x28(%rbp), %eax
shrl $0x3, %eax
movl -0xc(%rbp), %ecx
shll $0x3, %ecx
subl $0x80, %ecx
imull %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x128f4
movl -0x24(%rbp), %eax
shrl $0x4, %eax
shll $0x4, %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
shrl $0x4, %eax
shll $0x7, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
subl -0x34(%rbp), %ecx
addl -0x38(%rbp), %ecx
addl -0x2c(%rbp), %ecx
addl -0x30(%rbp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1289e
jmp 0x128f6
jmp 0x128f8
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x127a7
movq -0x20(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq