// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movb %dl, %al
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
andb $0x1, %al
movb %al, 0x87(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xac480
movl %eax, 0x5c(%rsp)
movq 0x78(%rsp), %rdi
addq $0x2, %rdi
leaq 0x60(%rsp), %rsi
addq $0x4, %rsi
callq 0xac480
movl %eax, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
cmpl $0x3, 0x54(%rsp)
jge 0xac329
movslq 0x54(%rsp), %rax
movzbl 0x60(%rsp,%rax), %eax
movl %eax, 0x50(%rsp)
movl 0x54(%rsp), %eax
addl $0x4, %eax
cltq
movzbl 0x60(%rsp,%rax), %eax
movl %eax, 0x4c(%rsp)
testb $0x1, 0x87(%rsp)
je 0xac2d3
movl 0x5c(%rsp), %eax
cmpl 0x58(%rsp), %eax
jg 0xac2d3
movl 0x50(%rsp), %eax
addl 0x4c(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movb %al, %cl
movl 0x54(%rsp), %eax
addl $0x8, %eax
cltq
movb %cl, 0x60(%rsp,%rax)
movl 0x54(%rsp), %eax
addl $0xc, %eax
cltq
movb $0x0, 0x60(%rsp,%rax)
jmp 0xac317
movl 0x50(%rsp), %eax
shll %eax
addl 0x4c(%rsp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movb %al, %cl
movl 0x54(%rsp), %eax
addl $0x8, %eax
cltq
movb %cl, 0x60(%rsp,%rax)
movl 0x50(%rsp), %eax
movl 0x4c(%rsp), %ecx
shll %ecx
addl %ecx, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movb %al, %cl
movl 0x54(%rsp), %eax
addl $0xc, %eax
cltq
movb %cl, 0x60(%rsp,%rax)
jmp 0xac319
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0xac265
movb $-0x1, 0x6b(%rsp)
xorl %eax, %eax
testb $0x1, 0x87(%rsp)
movb %al, 0xf(%rsp)
je 0xac34d
movl 0x5c(%rsp), %eax
cmpl 0x58(%rsp), %eax
setle %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, 0x6f(%rsp)
movl $0x0, 0x2c(%rsp)
cmpl $0x4, 0x2c(%rsp)
jge 0xac402
leaq 0x30(%rsp), %rax
movl 0x2c(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x78(%rsp), %rax
movl 0x2c(%rsp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0x1f(%rsp)
movzbl 0x1f(%rsp), %eax
andl $0x3, %eax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, (%rax)
movzbl 0x1f(%rsp), %eax
sarl $0x2, %eax
andl $0x3, %eax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, 0x1(%rax)
movzbl 0x1f(%rsp), %eax
sarl $0x4, %eax
andl $0x3, %eax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2(%rax)
movzbl 0x1f(%rsp), %eax
sarl $0x6, %eax
andl $0x3, %eax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, 0x3(%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xac36a
movl $0x0, 0x18(%rsp)
cmpl $0x10, 0x18(%rsp)
jge 0xac475
movslq 0x18(%rsp), %rax
movzbl 0x30(%rsp,%rax), %eax
shll $0x2, %eax
movb %al, 0x17(%rsp)
movl $0x0, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jge 0xac466
movzbl 0x17(%rsp), %eax
addl 0x10(%rsp), %eax
cltq
movb 0x60(%rsp,%rax), %dl
movq 0x90(%rsp), %rax
movl 0x18(%rsp), %ecx
shll $0x2, %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xac42a
jmp 0xac468
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xac40a
addq $0x98, %rsp
retq
nopl (%rax)