// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/libsquish/squish.cpp
// Function: squish::DecompressImage(unsigned char*, int, int, int, void const*, int)
void DecompressImage( u8* rgba, int width, int height, int pitch, void const* blocks, int flags )
{
    // 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 input
        u8 const* sourceBlock = reinterpret_cast< u8 const* >( blocks );
        int bytesPerBlock = ( ( flags & ( kDxt1 | kBc4 ) ) != 0 ) ? 8 : 16;
        sourceBlock += ( (y / 4) * ( (width + 3) / 4) ) * bytesPerBlock;

        for( int x = 0; x < width; x += 4 )
        {
            // decompress the block
            u8 targetRgba[4*16];
            Decompress( targetRgba, sourceBlock, flags );

            // write the decompressed pixels to the correct image locations
            u8 const* sourcePixel = targetRgba;
            for( int py = 0; py < 4; ++py )
            {
                for( int px = 0; px < 4; ++px )
                {
                    // get the target location
                    int sx = x + px;
                    int sy = y + py;

                    // write if we're in the image
                    if( sx < width && sy < height )
                    {
                        // copy the rgba value
                        u8* targetPixel = rgba + pitch*sy + 4*sx;
                        CopyRGBA(sourcePixel, targetPixel, flags);
                    }

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

            // advance
            sourceBlock += bytesPerBlock;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0x28(%rsp)
movl %ecx, %ebx
movl %edx, %r13d
movl %esi, %r14d
movq %rdi, 0x50(%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, 0x30(%rsp)
leal 0x3(%r14), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
movl %eax, 0xc(%rsp)
addl $0x3, %esi
movq %rsi, 0x20(%rsp)
movslq %ebx, %rax
movq %rax, 0x48(%rsp)
movslq %r13d, %rax
movq %rax, 0x18(%rsp)
movq %r14, 0x68(%rsp)
movslq %r14d, %rax
movq %rax, 0x38(%rsp)
xorl %r14d, %r14d
cmpq 0x18(%rsp), %r14
jge 0x61c38
movq %r14, %rax
shrq $0x2, %rax
imull 0xc(%rsp), %eax
movq 0x20(%rsp), %rcx
shll %cl, %eax
movslq %eax, %rsi
addq 0x28(%rsp), %rsi
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
movq %r14, 0x58(%rsp)
cmpq 0x38(%rsp), %r15
jge 0x61c2f
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x40(%rsp)
movl 0x8(%rsp), %edx
callq 0x61820
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0x61c16
movq %r12, 0x60(%rsp)
orq %r14, %r12
movq %r12, %rbp
imulq 0x48(%rsp), %rbp
addq 0x50(%rsp), %rbp
movq 0x10(%rsp), %r14
xorl %r13d, %r13d
cmpq $0x4, %r13
je 0x61c07
cmpq 0x18(%rsp), %r12
setl %al
leal (%r15,%r13), %ecx
cmpl 0x68(%rsp), %ecx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x61bfa
movl %r14d, %esi
andl $-0x4, %esi
addq %rbp, %rsi
movq %rbx, %rdi
movl 0x8(%rsp), %edx
callq 0x618b8
addq $0x4, %rbx
incq %r13
addq $0x4, %r14
jmp 0x61bc5
movq 0x60(%rsp), %r12
incq %r12
movq 0x58(%rsp), %r14
jmp 0x61ba1
movq 0x40(%rsp), %rsi
addq 0x30(%rsp), %rsi
addq $0x4, %r15
addq $0x10, 0x10(%rsp)
jmp 0x61b7d
addq $0x4, %r14
jmp 0x61b46
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq