// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movq %r8, 0x40(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
movl %r9d, %esi
andl $0x1f, %esi
movl %r9d, %edi
andl $0x160, %edi            # imm = 0x160
leal -0x2(%rsi), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
movl $0x1, %eax
cmovel %esi, %eax
leal -0x8(%rsi), %r8d
testl $0xfffffff7, %r8d       # imm = 0xFFFFFFF7
cmovel %esi, %eax
cmpl $0x100, %edi            # imm = 0x100
movl $0x20, %esi
cmovel %edi, %esi
cmpl $0x40, %edi
cmovel %edi, %esi
testl %edx, %edx
jle 0x6b2b6
movl %r9d, %ebx
movl %esi, %edi
movl %r9d, %esi
andl $0x280, %esi            # imm = 0x280
orl %esi, %edi
orl %eax, %edi
movl %edi, 0x24(%rsp)
xorl %edi, %edi
testb $0x9, %al
sete %dil
leaq 0x8(,%rdi,8), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rsi
leal 0x3(%rsi), %eax
leal 0x6(%rsi), %r8d
testl %eax, %eax
cmovnsl %eax, %r8d
sarl $0x2, %r8d
movl %r8d, 0x20(%rsp)
addl $0x3, %edi
movq %rdi, 0x38(%rsp)
movslq %esi, %rbp
movslq %ecx, %r15
movl %edx, %r14d
leaq (,%r15,4), %rax
movq %rax, 0x48(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x70(%rsp), %rdx
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r15, 0x60(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x6b290
movq 0x8(%rsp), %rax
shrq $0x2, %rax
imull 0x20(%rsp), %eax
movq 0x38(%rsp), %rcx
shll %cl, %eax
cltq
addq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rcx
xorl %r12d, %r12d
xorl %eax, %eax
movq %rcx, 0x58(%rsp)
movq %rcx, %r10
xorl %esi, %esi
movq %rax, %rdi
orq 0x8(%rsp), %rdi
movq %rdi, %r8
imulq %r15, %r8
addq 0x30(%rsp), %r8
leaq (,%rax,4), %r9
movq %r10, 0x68(%rsp)
xorl %r13d, %r13d
cmpq %r14, %rdi
setb %r15b
movq %r13, %r11
orq %r12, %r11
cmpq %rbp, %r11
setl %cl
andb %r15b, %cl
cmpb $0x1, %cl
jne 0x6b220
btl $0x9, %ebx
jb 0x6b1fb
xorl %r11d, %r11d
movb (%r10,%r11), %cl
movb %cl, (%rdx,%r11)
incq %r11
cmpl $0x4, %r11d
jne 0x6b1e8
jmp 0x6b219
movb 0x2(%r8,%r11,4), %cl
movb %cl, (%rdx)
movb 0x1(%r8,%r11,4), %cl
movb %cl, 0x1(%rdx)
movb (%r8,%r11,4), %cl
movb %cl, 0x2(%rdx)
movb 0x3(%r8,%r11,4), %cl
movb %cl, 0x3(%rdx)
leal (%r9,%r13), %ecx
btsl %ecx, %esi
addq $0x4, %rdx
incq %r13
addq $0x4, %r10
cmpq $0x4, %r13
jne 0x6b1c4
incq %rax
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r10
addq %r15, %r10
cmpq $0x4, %rax
jne 0x6b1a0
leaq 0x70(%rsp), %rdi
movq 0x28(%rsp), %r13
movq %r13, %rdx
movl 0x24(%rsp), %ecx
movq 0xf0(%rsp), %r8
callq 0x6add8
leaq 0x70(%rsp), %rdx
addq 0x50(%rsp), %r13
movq %r13, 0x28(%rsp)
addq $0x4, %r12
movq 0x58(%rsp), %rcx
addq $0x10, %rcx
cmpl 0x18(%rsp), %r12d
jl 0x6b194
movq 0x8(%rsp), %rcx
addq $0x4, %rcx
movq 0x10(%rsp), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
cmpq %r14, %rcx
jb 0x6b160
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq