// File: /workspace/github_c_makefile_star2_O1/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 0xcccc
cmpl $0x1, %r9d
jne 0xcd8e
testl %eax, %eax
je 0xcd8e
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r14d, %r14d
leal 0x1(%r14), %r11d
movl %r11d, %ebx
imull %esi, %ebx
movl %r14d, %ebp
imull %edi, %ebp
addl %ebx, %ebp
movl %edi, %ebx
cmpl %ebp, %r9d
je 0xcc6b
movl %r14d, %r11d
xorl %ebx, %ebx
leal (%rbx,%r9), %r14d
movzbl (%rcx,%r14), %r15d
movb (%rdx,%r15,4), %bpl
movl %r10d, %r15d
movb %bpl, (%r8,%r15)
leal 0x1(%r10), %r15d
movzbl (%rcx,%r14), %r12d
movb 0x1(%rdx,%r12,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x2(%r10), %r15d
movzbl (%rcx,%r14), %r12d
movb 0x2(%rdx,%r12,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x3(%r10), %r15d
movzbl (%rcx,%r14), %r14d
movb 0x3(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
addl $0x4, %r10d
addl %ebx, %r9d
incl %r9d
movl %r11d, %r14d
cmpl %eax, %r9d
jb 0xcc4d
jmp 0xcd8e
testl %eax, %eax
je 0xcd8e
shrl %esi
shrl %edi
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r14d, %r14d
leal 0x1(%r14), %r11d
movl %r11d, %ebx
imull %esi, %ebx
movl %r14d, %ebp
imull %edi, %ebp
addl %ebx, %ebp
movl %edi, %ebx
cmpl %ebp, %r9d
je 0xccff
movl %r14d, %r11d
xorl %ebx, %ebx
leal (%rbx,%r9), %r14d
movzbl (%rcx,%r14), %r14d
movl %r14d, %r15d
andl $0xf, %r15d
movb (%rdx,%r15,4), %bpl
movl %r10d, %r12d
movb %bpl, (%r8,%r12)
leal 0x1(%r10), %r12d
movb 0x1(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x2(%r10), %r12d
movb 0x2(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x3(%r10), %r12d
movb 0x3(%rdx,%r15,4), %bpl
movb %bpl, (%r8,%r12)
leal 0x4(%r10), %r15d
shrl $0x4, %r14d
movb (%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x5(%r10), %r15d
movb 0x1(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x6(%r10), %r15d
movb 0x2(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
leal 0x7(%r10), %r15d
movb 0x3(%rdx,%r14,4), %bpl
movb %bpl, (%r8,%r15)
addl $0x8, %r10d
addl %ebx, %r9d
incl %r9d
movl %r11d, %r14d
cmpl %eax, %r9d
jb 0xcce1
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq