// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/libsquish/squish.cpp
// Function: squish::CompressImage(unsigned char const*, int, int, int, void*, int, float*)
void CompressImage( u8 const* rgba, int width, int height, int pitch, void* blocks, int flags, float* metric )
{
    // fix any bad flags
    flags = FixFlags( flags );

    // loop over blocks
#ifdef SQUISH_USE_OPENMP
#   pragma omp parallel for
#endif
    for( int y = 0; y < height; y += 4 )
    {
        // initialise the block output
        u8* targetBlock = reinterpret_cast< u8* >( blocks );
        int bytesPerBlock = ( ( flags & ( kDxt1 | kBc4 ) ) != 0 ) ? 8 : 16;
        targetBlock += ( (y / 4) * ( (width + 3) / 4) ) * bytesPerBlock;

        for( int x = 0; x < width; x += 4 )
        {
            // build the 4x4 block of pixels
            u8 sourceRgba[16*4];
            u8* targetPixel = sourceRgba;
            int mask = 0;
            for( int py = 0; py < 4; ++py )
            {
                for( int px = 0; px < 4; ++px )
                {
                    // get the source pixel in the image
                    int sx = x + px;
                    int sy = y + py;

                    // enable if we're in the image
                    if( sx < width && sy < height )
                    {
                        // copy the rgba value
                        u8 const* sourcePixel = rgba + pitch*sy + 4*sx;
                        CopyRGBA(sourcePixel, targetPixel, flags);
                        // enable this pixel
                        mask |= ( 1 << ( 4*py + px ) );
                    }

                    // advance to the next pixel
                    targetPixel += 4;
                }
            }

            // compress it into the output
            CompressMasked( sourceRgba, mask, targetBlock, flags, metric );

            // advance
            targetBlock += bytesPerBlock;
        }
    }
}

// Assembly:
subq $0xa8, %rsp
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movl %esi, 0x9c(%rsp)
movl %edx, 0x98(%rsp)
movl %ecx, 0x94(%rsp)
movq %r8, 0x88(%rsp)
movl %r9d, 0x84(%rsp)
movl 0x84(%rsp), %edi
callq 0xa3600
movl %eax, 0x84(%rsp)
movl $0x0, 0x80(%rsp)
movl 0x80(%rsp), %eax
cmpl 0x98(%rsp), %eax
jge 0xa3aa4
movq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movl 0x84(%rsp), %edx
andl $0x9, %edx
movl $0x10, %eax
movl $0x8, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, 0x74(%rsp)
movl 0x80(%rsp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x9c(%rsp), %eax
addl $0x3, %eax
movl $0x4, %esi
cltd
idivl %esi
imull %eax, %ecx
imull 0x74(%rsp), %ecx
movq 0x78(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movl $0x0, 0x70(%rsp)
movl 0x70(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0xa3a8c
leaq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
cmpl $0x4, 0x20(%rsp)
jge 0xa3a46
movl $0x0, 0x1c(%rsp)
cmpl $0x4, 0x1c(%rsp)
jge 0xa3a34
movl 0x70(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x80(%rsp), %eax
addl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0xa3a16
movl 0x14(%rsp), %eax
cmpl 0x98(%rsp), %eax
jge 0xa3a16
movq 0xa0(%rsp), %rax
movl 0x94(%rsp), %ecx
imull 0x14(%rsp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl 0x18(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x84(%rsp), %edx
callq 0xa37b0
movl 0x20(%rsp), %ecx
shll $0x2, %ecx
addl 0x1c(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl 0x24(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x28(%rsp)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xa397a
jmp 0xa3a36
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xa3967
leaq 0x30(%rsp), %rdi
movl 0x24(%rsp), %esi
movq 0x78(%rsp), %rdx
movl 0x84(%rsp), %ecx
movq 0xb0(%rsp), %r8
callq 0xa32c0
movl 0x74(%rsp), %ecx
movq 0x78(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movl 0x70(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x70(%rsp)
jmp 0xa393c
jmp 0xa3a8e
movl 0x80(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x80(%rsp)
jmp 0xa38ba
addq $0xa8, %rsp
retq
nopl (%rax)