// File: /workspace/github_c_makefile_star2_O2/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 $0x338, %rsp            # imm = 0x338
movq %r8, %r12
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movl %ecx, %edi
callq 0x617da
movl %eax, %r15d
xorl %eax, %eax
testb $0x18, %r15b
je 0x616f0
cmpq $0x10, %rax
je 0x616c1
movb (%r14,%rax,4), %cl
movb %cl, 0x13(%rsp,%rax,4)
incq %rax
jmp 0x616ae
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x64a4f
testb $0x10, %r15b
je 0x617c8
xorl %eax, %eax
cmpq $0x10, %rax
je 0x61748
movb 0x1(%r14,%rax,4), %cl
movb %cl, 0x13(%rsp,%rax,4)
incq %rax
jmp 0x616dc
testb $0x6, %r15b
setne %al
movl %ebp, %edx
leaq (%rbx,%rax,8), %rbp
leaq 0x1f0(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl %edx, 0xc(%rsp)
movl %r15d, %ecx
callq 0x666d8
movl (%r13), %eax
cmpl $0x1, %eax
jne 0x61755
leaq 0x10(%rsp), %r12
leaq 0x1f0(%rsp), %rsi
movq %r12, %rdi
movl %r15d, %edx
callq 0x6732c
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6668e
movq %r12, %rdi
jmp 0x6179b
addq $0x8, %rbx
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
jmp 0x617b3
movq %rbp, %r13
testb $0x40, %r15b
sete %cl
testl %eax, %eax
setne %al
leaq 0x10(%rsp), %rbp
leaq 0x1f0(%rsp), %rsi
movq %rbp, %rdi
movl %r15d, %edx
testb %al, %cl
jne 0x61785
movq %r12, %rcx
callq 0x66be0
jmp 0x6178d
movq %r12, %rcx
callq 0x64e48
movq %rbp, %rdi
movq %r13, %rsi
callq 0x6668e
movq %rbp, %rdi
callq 0x6668a
testb $0x2, %r15b
movl 0xc(%rsp), %esi
jne 0x617bd
testb $0x4, %r15b
je 0x617c8
movq %r14, %rdi
movq %rbx, %rdx
callq 0x64a4f
jmp 0x617c8
movq %r14, %rdi
movq %rbx, %rdx
callq 0x64978
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq