// File: /workspace/github_c_makefile_star2_O2/Joy-Division[P]tools-zoe/tex-to_image.c
// Function: texToRgba
void texToRgba( textureAttributes header, paletteEntry *paletteTable, unsigned char *texPixelData, unsigned char *rgbaPixelData, unsigned int bpp, unsigned int totalTexPixels, unsigned int widthAligned ) {
	unsigned int curTexPixel = 0, curRgbaPixel = 0, skipPixel = widthAligned - header.textureWidth, currentRow = 0;
	if( bpp == palMode4bpp ) {
		uint8_t pixelA, pixelB;
		for( curTexPixel = 0; curTexPixel < totalTexPixels; curTexPixel++ ) {
			if( curTexPixel == (header.textureWidth/2)*(currentRow + 1) + (skipPixel/2)*currentRow ) {
				curTexPixel += (skipPixel/2);
				currentRow++;
			}
			pixelB = texPixelData[curTexPixel] >> 4;
			pixelA = texPixelData[curTexPixel] & 0x0F;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelA].red;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelA].green;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelA].blue;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelA].alpha;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelB].red;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelB].green;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelB].blue;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[pixelB].alpha;
			curRgbaPixel++;
		}
	}
	else if( bpp == palMode8bpp ) {
		for( curTexPixel = 0; curTexPixel < totalTexPixels; curTexPixel++ ) {
			if( curTexPixel == header.textureWidth*(currentRow + 1) + skipPixel*currentRow ) {
				curTexPixel += skipPixel;
				currentRow++;
			}
			rgbaPixelData[curRgbaPixel] = paletteTable[texPixelData[curTexPixel]].red;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[texPixelData[curTexPixel]].green;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[texPixelData[curTexPixel]].blue;
			curRgbaPixel++;
			rgbaPixelData[curRgbaPixel] = paletteTable[texPixelData[curTexPixel]].alpha;
			curRgbaPixel++;
		}
	}
	// printf("Done with frame\n");
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x30(%rsp), %eax
movl 0x38(%rsp), %edi
movzwl %si, %esi
subl %esi, %edi
testl %r9d, %r9d
je 0xa101
cmpl $0x1, %r9d
jne 0xa1c0
xorl %r14d, %r14d
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpl %eax, %r10d
jae 0xa1c0
leal 0x1(%r14), %r11d
movl %r11d, %ebx
imull %esi, %ebx
movl %r14d, %ebp
imull %edi, %ebp
addl %ebx, %ebp
movl %edi, %ebx
cmpl %ebp, %r10d
je 0xa0a8
xorl %ebx, %ebx
movl %r14d, %r11d
leal (%rbx,%r10), %r14d
movzbl (%rcx,%r14), %r15d
movb (%rdx,%r15,4), %bpl
movl %r9d, %r15d
movb %bpl, (%r8,%r15)
leal 0x1(%r9), %r15d
movzbl (%rcx,%r14), %r12d
movb 0x1(%rdx,%r12,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x2(%r9), %r15d
movzbl (%rcx,%r14), %r12d
movb 0x2(%rdx,%r12,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x3(%r9), %r15d
movzbl (%rcx,%r14), %r14d
movb 0x3(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
addl $0x4, %r9d
addl %ebx, %r10d
incl %r10d
movl %r11d, %r14d
jmp 0xa081
shrl %esi
shrl %edi
xorl %r14d, %r14d
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpl %eax, %r10d
jae 0xa1c0
leal 0x1(%r14), %r11d
movl %r11d, %ebx
imull %esi, %ebx
movl %r14d, %ebp
imull %edi, %ebp
addl %ebx, %ebp
movl %edi, %ebx
cmpl %ebp, %r10d
je 0xa135
xorl %ebx, %ebx
movl %r14d, %r11d
leal (%rbx,%r10), %r14d
movzbl (%rcx,%r14), %r14d
movl %r14d, %r15d
andl $0xf, %r15d
movb (%rdx,%r15,4), %bpl
movl %r9d, %r12d
movb %bpl, (%r8,%r12)
leal 0x1(%r9), %r12d
movb 0x1(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x2(%r9), %r12d
movb 0x2(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x3(%r9), %r12d
movb 0x3(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x4(%r9), %r15d
shrl $0x4, %r14d
movb (%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x5(%r9), %r15d
movb 0x1(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x6(%r9), %r15d
movb 0x2(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x7(%r9), %r15d
movb 0x3(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
addl $0x8, %r9d
addl %ebx, %r10d
incl %r10d
movl %r11d, %r14d
jmp 0xa10e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq