// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/libsquish/alpha.cpp
// Function: squish::DecompressAlphaDxt5(unsigned char*, void const*)
void DecompressAlphaDxt5( u8* rgba, void const* block )
{
    // get the two alpha values
    u8 const* bytes = reinterpret_cast< u8 const* >( block );
    int alpha0 = bytes[0];
    int alpha1 = bytes[1];

    // compare the values to build the codebook
    u8 codes[8];
    codes[0] = ( u8 )alpha0;
    codes[1] = ( u8 )alpha1;
    if( alpha0 <= alpha1 )
    {
        // use 5-alpha codebook
        for( int i = 1; i < 5; ++i )
            codes[1 + i] = ( u8 )( ( ( 5 - i )*alpha0 + i*alpha1 )/5 );
        codes[6] = 0;
        codes[7] = 255;
    }
    else
    {
        // use 7-alpha codebook
        for( int i = 1; i < 7; ++i )
            codes[1 + i] = ( u8 )( ( ( 7 - i )*alpha0 + i*alpha1 )/7 );
    }

    // decode the indices
    u8 indices[16];
    u8 const* src = bytes + 2;
    u8* dest = indices;
    for( int i = 0; i < 2; ++i )
    {
        // grab 3 bytes
        int value = 0;
        for( int j = 0; j < 3; ++j )
        {
            int byte = *src++;
            value |= ( byte << 8*j );
        }

        // unpack 8 3-bit values from it
        for( int j = 0; j < 8; ++j )
        {
            int index = ( value >> 3*j ) & 0x7;
            *dest++ = ( u8 )index;
        }
    }

    // write out the indexed codebook values
    for( int i = 0; i < 16; ++i )
        rgba[4*i + 3] = codes[indices[i]];
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x18(%rsp)
movq -0x18(%rsp), %rax
movzbl (%rax), %eax
movl %eax, -0x1c(%rsp)
movq -0x18(%rsp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x20(%rsp)
movl -0x1c(%rsp), %eax
movb %al, -0x28(%rsp)
movl -0x20(%rsp), %eax
movb %al, -0x27(%rsp)
movl -0x1c(%rsp), %eax
cmpl -0x20(%rsp), %eax
jg 0xa8dff
movl $0x1, -0x2c(%rsp)
cmpl $0x5, -0x2c(%rsp)
jge 0xa8df3
movl $0x5, %eax
subl -0x2c(%rsp), %eax
imull -0x1c(%rsp), %eax
movl -0x2c(%rsp), %ecx
imull -0x20(%rsp), %ecx
addl %ecx, %eax
movl $0x5, %ecx
cltd
idivl %ecx
movb %al, %cl
movl -0x2c(%rsp), %eax
addl $0x1, %eax
cltq
movb %cl, -0x28(%rsp,%rax)
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
jmp 0xa8daf
movb $0x0, -0x22(%rsp)
movb $-0x1, -0x21(%rsp)
jmp 0xa8e4d
movl $0x1, -0x30(%rsp)
cmpl $0x7, -0x30(%rsp)
jge 0xa8e4b
movl $0x7, %eax
subl -0x30(%rsp), %eax
imull -0x1c(%rsp), %eax
movl -0x30(%rsp), %ecx
imull -0x20(%rsp), %ecx
addl %ecx, %eax
movl $0x7, %ecx
cltd
idivl %ecx
movb %al, %cl
movl -0x30(%rsp), %eax
addl $0x1, %eax
cltq
movb %cl, -0x28(%rsp,%rax)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0xa8e07
jmp 0xa8e4d
movq -0x18(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x50(%rsp)
leaq -0x48(%rsp), %rax
movq %rax, -0x58(%rsp)
movl $0x0, -0x5c(%rsp)
cmpl $0x2, -0x5c(%rsp)
jge 0xa8f22
movl $0x0, -0x60(%rsp)
movl $0x0, -0x64(%rsp)
cmpl $0x3, -0x64(%rsp)
jge 0xa8ec9
movq -0x50(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rsp)
movzbl (%rax), %eax
movl %eax, -0x68(%rsp)
movl -0x68(%rsp), %eax
movl -0x64(%rsp), %ecx
shll $0x3, %ecx
shll %cl, %eax
orl -0x60(%rsp), %eax
movl %eax, -0x60(%rsp)
movl -0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rsp)
jmp 0xa8e88
movl $0x0, -0x6c(%rsp)
cmpl $0x8, -0x6c(%rsp)
jge 0xa8f10
movl -0x60(%rsp), %eax
imull $0x3, -0x6c(%rsp), %ecx
sarl %cl, %eax
andl $0x7, %eax
movl %eax, -0x70(%rsp)
movl -0x70(%rsp), %eax
movb %al, %cl
movq -0x58(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rsp)
movb %cl, (%rax)
movl -0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rsp)
jmp 0xa8ed1
jmp 0xa8f12
movl -0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rsp)
jmp 0xa8e6d
movl $0x0, -0x74(%rsp)
cmpl $0x10, -0x74(%rsp)
jge 0xa8f61
movslq -0x74(%rsp), %rax
movzbl -0x48(%rsp,%rax), %eax
movb -0x28(%rsp,%rax), %dl
movq -0x8(%rsp), %rax
movl -0x74(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rsp)
jmp 0xa8f2a
retq
nopw %cs:(%rax,%rax)