// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, 0x38(%rsp)
movl %ecx, %ebx
movl %edx, %r12d
movl %esi, %r14d
movq %rdi, 0x60(%rsp)
movl %r9d, %edi
callq 0x617da
xorl %esi, %esi
movl %eax, 0x8(%rsp)
testb $0x9, %al
sete %sil
leaq 0x8(,%rsi,8), %rax
movq %rax, 0x40(%rsp)
leal 0x3(%r14), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
movl %eax, 0xc(%rsp)
addl $0x3, %esi
movq %rsi, 0x30(%rsp)
movslq %ebx, %rax
movq %rax, 0x58(%rsp)
movslq %r12d, %rax
movq %rax, 0x28(%rsp)
movq %r14, 0x78(%rsp)
movslq %r14d, %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
leaq 0x80(%rsp), %rbx
cmpq 0x28(%rsp), %r14
jge 0x61a9e
movq %r14, %rax
shrq $0x2, %rax
imull 0xc(%rsp), %eax
movq 0x30(%rsp), %rcx
shll %cl, %eax
movslq %eax, %r15
addq 0x38(%rsp), %r15
movq $0x0, 0x10(%rsp)
xorl %edx, %edx
movq %r14, 0x68(%rsp)
cmpq 0x48(%rsp), %rdx
jge 0x61a95
movq %r15, 0x50(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rdx, 0x18(%rsp)
cmpq $0x4, %rbp
je 0x61a55
movq %rbp, 0x70(%rsp)
orq %r14, %rbp
movq %rbp, %r14
imulq 0x58(%rsp), %r14
addq 0x60(%rsp), %r14
movq 0x10(%rsp), %r15
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x61a3d
cmpq 0x28(%rsp), %rbp
setl %al
leal (%rdx,%r13), %ecx
cmpl 0x78(%rsp), %ecx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x61a30
movl %r15d, %edi
andl $-0x4, %edi
addq %r14, %rdi
movq %rbx, %rsi
movl 0x8(%rsp), %edx
callq 0x618b8
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rax
addl %r13d, %eax
btsl %eax, %r12d
addq $0x4, %rbx
incq %r13
addq $0x4, %r15
jmp 0x619ea
movq 0x70(%rsp), %rbp
incq %rbp
addq $0x4, 0x20(%rsp)
movq 0x68(%rsp), %r14
jmp 0x619c2
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
movq 0x50(%rsp), %r15
movq %r15, %rdx
movl 0x8(%rsp), %ecx
movq 0x100(%rsp), %r8
callq 0x61680
movq 0x18(%rsp), %rdx
addq 0x40(%rsp), %r15
addq $0x4, %rdx
addq $0x10, 0x10(%rsp)
jmp 0x6199f
addq $0x4, %r14
jmp 0x61969
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq