// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x438, %rsp            # imm = 0x438
movq %rdi, 0x430(%rsp)
movl %esi, 0x42c(%rsp)
movq %rdx, 0x420(%rsp)
movl %ecx, 0x41c(%rsp)
movq %r8, 0x410(%rsp)
movl 0x41c(%rsp), %edi
callq 0xa3600
movl %eax, 0x41c(%rsp)
movl 0x41c(%rsp), %eax
andl $0x18, %eax
cmpl $0x0, %eax
je 0xa3439
movl $0x0, 0x3cc(%rsp)
cmpl $0x10, 0x3cc(%rsp)
jge 0xa336c
movq 0x430(%rsp), %rax
movl 0x3cc(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movl 0x3cc(%rsp), %eax
shll $0x2, %eax
addl $0x3, %eax
cltq
movb %cl, 0x3d0(%rsp,%rax)
movl 0x3cc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3cc(%rsp)
jmp 0xa331e
movq 0x420(%rsp), %rax
movq %rax, 0x3c0(%rsp)
leaq 0x3d0(%rsp), %rdi
movl 0x42c(%rsp), %esi
movq 0x3c0(%rsp), %rdx
callq 0xa8760
movl 0x41c(%rsp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xa3434
movl $0x0, 0x3bc(%rsp)
cmpl $0x10, 0x3bc(%rsp)
jge 0xa3404
movq 0x430(%rsp), %rax
movl 0x3bc(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movl 0x3bc(%rsp), %eax
shll $0x2, %eax
addl $0x3, %eax
cltq
movb %cl, 0x3d0(%rsp,%rax)
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0xa33b6
movq 0x420(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x3b0(%rsp)
leaq 0x3d0(%rsp), %rdi
movl 0x42c(%rsp), %esi
movq 0x3b0(%rsp), %rdx
callq 0xa8760
jmp 0xa35f0
movq 0x420(%rsp), %rax
movq %rax, 0x3a8(%rsp)
movq 0x420(%rsp), %rax
movq %rax, 0x3a0(%rsp)
movl 0x41c(%rsp), %eax
andl $0x6, %eax
cmpl $0x0, %eax
je 0xa347c
movq 0x420(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x3a8(%rsp)
movq 0x430(%rsp), %rsi
movl 0x42c(%rsp), %edx
movl 0x41c(%rsp), %ecx
leaq 0x258(%rsp), %rdi
callq 0xac6b0
leaq 0x258(%rsp), %rdi
callq 0xa43d0
cmpl $0x1, %eax
jne 0xa34f4
movl 0x41c(%rsp), %edx
leaq 0x218(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0xaeaa0
movq 0x3a8(%rsp), %rsi
leaq 0x218(%rsp), %rdi
callq 0xac610
leaq 0x218(%rsp), %rdi
callq 0xa43e0
jmp 0xa3596
movl 0x41c(%rsp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0xa3515
leaq 0x258(%rsp), %rdi
callq 0xa43d0
cmpl $0x0, %eax
jne 0xa355d
movl 0x41c(%rsp), %edx
movq 0x410(%rsp), %rcx
leaq 0x1d8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0xad680
movq 0x3a8(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
callq 0xac610
leaq 0x1d8(%rsp), %rdi
callq 0xa43f0
jmp 0xa3594
movl 0x41c(%rsp), %edx
movq 0x410(%rsp), %rcx
movq %rsp, %rdi
leaq 0x258(%rsp), %rsi
callq 0xa90c0
movq 0x3a8(%rsp), %rsi
movq %rsp, %rdi
callq 0xac610
movq %rsp, %rdi
callq 0xa4400
jmp 0xa3596
movl 0x41c(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa35c3
movq 0x430(%rsp), %rdi
movl 0x42c(%rsp), %esi
movq 0x3a0(%rsp), %rdx
callq 0xa8530
jmp 0xa35f0
movl 0x41c(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xa35ee
movq 0x430(%rsp), %rdi
movl 0x42c(%rsp), %esi
movq 0x3a0(%rsp), %rdx
callq 0xa8760
jmp 0xa35f0
addq $0x438, %rsp            # imm = 0x438
retq
nopl (%rax,%rax)