// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/libsquish/colourblock.cpp
// Function: squish::DecompressColour(unsigned char*, void const*, bool)
void DecompressColour( u8* rgba, void const* block, bool isDxt1 )
{
    // get the block bytes
    u8 const* bytes = reinterpret_cast< u8 const* >( block );

    // unpack the endpoints
    u8 codes[16];
    int a = Unpack565( bytes, codes );
    int b = Unpack565( bytes + 2, codes + 4 );

    // generate the midpoints
    for( int i = 0; i < 3; ++i )
    {
        int c = codes[i];
        int d = codes[4 + i];

        if( isDxt1 && a <= b )
        {
            codes[8 + i] = ( u8 )( ( c + d )/2 );
            codes[12 + i] = 0;
        }
        else
        {
            codes[8 + i] = ( u8 )( ( 2*c + d )/3 );
            codes[12 + i] = ( u8 )( ( c + 2*d )/3 );
        }
    }

    // fill in alpha for the intermediate values
    codes[8 + 3] = 255;
    codes[12 + 3] = ( isDxt1 && a <= b ) ? 0 : 255;

    // unpack the indices
    u8 indices[16];
    for( int i = 0; i < 4; ++i )
    {
        u8* ind = indices + 4*i;
        u8 packed = bytes[4 + i];

        ind[0] = packed & 0x3;
        ind[1] = ( packed >> 2 ) & 0x3;
        ind[2] = ( packed >> 4 ) & 0x3;
        ind[3] = ( packed >> 6 ) & 0x3;
    }

    // store out the colours
    for( int i = 0; i < 16; ++i )
    {
        u8 offset = 4*indices[i];
        for( int j = 0; j < 4; ++j )
            rgba[4*i + j] = codes[offset + j];
    }
}

// Assembly:
pushq %rbp
pushq %rbx
movzbl (%rsi), %r8d
movzbl 0x1(%rsi), %r9d
movl %r9d, %eax
shll $0x8, %eax
orl %r8d, %eax
movl %r9d, %ecx
shrb $0x5, %cl
movl %r9d, %r10d
andb $-0x8, %r10b
orb %cl, %r10b
movb %r10b, -0x28(%rsp)
movl %eax, %r10d
shrl $0x3, %r10d
movl $0xfc, %ecx
andl %ecx, %r10d
shrl %r9d
andl $0x3, %r9d
orl %r10d, %r9d
movb %r9b, -0x27(%rsp)
leal (,%r8,8), %r9d
shrb $0x2, %r8b
andb $0x7, %r8b
orb %r9b, %r8b
movb %r8b, -0x26(%rsp)
movb $-0x1, %r8b
movb %r8b, -0x25(%rsp)
movzbl 0x2(%rsi), %r9d
movzbl 0x3(%rsi), %r11d
movl %r11d, %r10d
shll $0x8, %r10d
orl %r9d, %r10d
movl %r11d, %ebx
shrb $0x5, %bl
movl %r11d, %ebp
andb $-0x8, %bpl
orb %bl, %bpl
movb %bpl, -0x24(%rsp)
movl %r10d, %ebx
shrl $0x3, %ebx
andl %ecx, %ebx
shrl %r11d
andl $0x3, %r11d
orl %ebx, %r11d
movb %r11b, -0x23(%rsp)
leal (,%r9,8), %ecx
shrb $0x2, %r9b
andb $0x7, %r9b
orb %cl, %r9b
movb %r9b, -0x22(%rsp)
movb %r8b, -0x21(%rsp)
cmpl %r10d, %eax
setbe %al
andb %dl, %al
movl $0xc, %ecx
movzbl -0x34(%rsp,%rcx), %r8d
movzbl -0x30(%rsp,%rcx), %edx
testb %al, %al
je 0x71eb0
addl %r8d, %edx
shrl %edx
movb %dl, -0x2c(%rsp,%rcx)
xorl %edx, %edx
jmp 0x71ed1
leal (%rdx,%r8,2), %r9d
imull $0x5556, %r9d, %r9d     # imm = 0x5556
shrl $0x10, %r9d
movb %r9b, -0x2c(%rsp,%rcx)
leal (%r8,%rdx,2), %edx
imull $0x5556, %edx, %edx     # imm = 0x5556
shrl $0x10, %edx
movb %dl, -0x28(%rsp,%rcx)
incq %rcx
cmpq $0xf, %rcx
jne 0x71e94
movb $-0x1, -0x1d(%rsp)
decb %al
movb %al, -0x19(%rsp)
xorl %eax, %eax
movb 0x4(%rsi,%rax), %cl
movl %ecx, %edx
andb $0x3, %dl
movb %dl, -0x18(%rsp,%rax,4)
movl %ecx, %edx
shrb $0x2, %dl
andb $0x3, %dl
movb %dl, -0x17(%rsp,%rax,4)
movl %ecx, %edx
shrb $0x4, %dl
andb $0x3, %dl
movb %dl, -0x16(%rsp,%rax,4)
shrb $0x6, %cl
movb %cl, -0x15(%rsp,%rax,4)
incq %rax
cmpq $0x4, %rax
jne 0x71eeb
xorl %eax, %eax
movb -0x18(%rsp,%rax), %cl
shlb $0x2, %cl
movzbl %cl, %ecx
movl -0x28(%rsp,%rcx), %ecx
movl %ecx, (%rdi,%rax,4)
incq %rax
cmpq $0x10, %rax
jne 0x71f22
popq %rbx
popq %rbp
retq
nop