// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/libsquish/squish.cpp
// Function: squish::CompressMasked(unsigned char const*, int, void*, int, float*)
void CompressMasked( u8 const* rgba, int mask, void* block, int flags, float* metric )
{
    // fix any bad flags
    flags = FixFlags( flags );

    if ( ( flags & ( kBc4 | kBc5 ) ) != 0 )
    {
        u8 alpha[16*4];
        for( int i = 0; i < 16; ++i )
        {
            alpha[i*4 + 3] = rgba[i*4 + 0]; // copy R to A
        }

        u8* rBlock = reinterpret_cast< u8* >( block );
        CompressAlphaDxt5( alpha, mask, rBlock );

        if ( ( flags & ( kBc5 ) ) != 0 )
        {
            for( int i = 0; i < 16; ++i )
            {
                alpha[i*4 + 3] = rgba[i*4 + 1]; // copy G to A
            }

            u8* gBlock = reinterpret_cast< u8* >( block ) + 8;
            CompressAlphaDxt5( alpha, mask, gBlock );
        }

        return;
    }

    // get the block locations
    void* colourBlock = block;
    void* alphaBlock = block;
    if( ( flags & ( kDxt3 | kDxt5 ) ) != 0 )
        colourBlock = reinterpret_cast< u8* >( block ) + 8;

    // create the minimal point set
    ColourSet colours( rgba, mask, flags );

    // check the compression type and compress colour
    if( colours.GetCount() == 1 )
    {
        // always do a single colour fit
        SingleColourFit fit( &colours, flags );
        fit.Compress( colourBlock );
    }
    else if( ( flags & kColourRangeFit ) != 0 || colours.GetCount() == 0 )
    {
        // do a range fit
        RangeFit fit( &colours, flags, metric );
        fit.Compress( colourBlock );
    }
    else
    {
        // default to a cluster fit (could be iterative or not)
        ClusterFit fit( &colours, flags, metric );
        fit.Compress( colourBlock );
    }

    // compress alpha separately if necessary
    if( ( flags & kDxt3 ) != 0 )
        CompressAlphaDxt3( rgba, mask, alphaBlock );
    else if( ( flags & kDxt5 ) != 0 )
        CompressAlphaDxt5( rgba, mask, alphaBlock );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movl %ecx, %r15d
movq %rdx, %rbx
movl %esi, %r9d
movq %rdi, %r14
movl %ecx, %eax
andl $0x1f, %eax
andl $0x160, %ecx            # imm = 0x160
movd %eax, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
pcmpeqd 0x11b73(%rip), %xmm0    # 0x7e6d0
movmskps %xmm0, %edx
testl %edx, %edx
movl $0x1, %ebp
cmovnel %eax, %ebp
cmpl $0x100, %ecx            # imm = 0x100
movl $0x20, %r12d
cmovel %ecx, %r12d
cmpl $0x40, %ecx
cmovel %ecx, %r12d
cmpl $0x8, %ebp
jae 0x6cbfb
movq %r8, 0x10(%rsp)
andl $0x280, %r15d           # imm = 0x280
orl %r12d, %r15d
orl %ebp, %r15d
xorl %eax, %eax
cmpl $0x2, %ebp
setae %al
movq %rbx, 0x18(%rsp)
leaq (%rbx,%rax,8), %rbx
leaq 0x200(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %r9d, 0xc(%rsp)
movl %r9d, %edx
movl %r15d, %ecx
callq 0x71fa0
movl (%r13), %eax
cmpl $0x1, %eax
jne 0x6cc4f
leaq 0x20(%rsp), %r12
leaq 0x200(%rsp), %rsi
movq %r12, %rdi
movl %r15d, %edx
callq 0x72afc
movq %r12, %rdi
movq %rbx, %rsi
callq 0x71f56
movq %r12, %rdi
jmp 0x6cc99
xorl %eax, %eax
movb (%r14,%rax,4), %cl
movb %cl, 0x23(%rsp,%rax,4)
incq %rax
cmpq $0x10, %rax
jne 0x6cbfd
leaq 0x20(%rsp), %rdi
movl %r9d, %r15d
movl %r9d, %esi
movq %rbx, %rdx
callq 0x703c5
cmpl $0x10, %ebp
jb 0x6ccc4
xorl %eax, %eax
movb 0x1(%r14,%rax,4), %cl
movb %cl, 0x23(%rsp,%rax,4)
incq %rax
cmpq $0x10, %rax
jne 0x6cc2c
addq $0x8, %rbx
leaq 0x20(%rsp), %rdi
movl %r15d, %esi
movq %rbx, %rdx
jmp 0x6ccb5
movq %rbx, %r13
testb $0x40, %r12b
sete %cl
testl %eax, %eax
setne %al
leaq 0x20(%rsp), %rbx
leaq 0x200(%rsp), %rsi
movq %rbx, %rdi
movl %r15d, %edx
testb %al, %cl
jne 0x6cc81
movq 0x10(%rsp), %rcx
callq 0x723bc
jmp 0x6cc8b
movq 0x10(%rsp), %rcx
callq 0x709cc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x71f56
movq %rbx, %rdi
callq 0x71f52
testb $0x2, %bpl
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rdx
jne 0x6ccbc
cmpl $0x4, %ebp
jb 0x6ccc4
movq %r14, %rdi
callq 0x703c5
jmp 0x6ccc4
movq %r14, %rdi
callq 0x702ec
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq