// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movq %r8, 0x38(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x28(%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 0x6d243
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, 0x48(%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, 0x30(%rsp)
movslq %esi, %rbp
movslq %ecx, %r15
movl %edx, %r14d
leaq (,%r15,4), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x6d21d
movq 0x8(%rsp), %rax
shrq $0x2, %rax
imull 0x20(%rsp), %eax
movq 0x30(%rsp), %rcx
shll %cl, %eax
movslq %eax, %rsi
addq 0x38(%rsp), %rsi
movq 0x10(%rsp), %rax
xorl %r12d, %r12d
leaq 0x60(%rsp), %rdi
movq %rsi, 0x58(%rsp)
movl 0x24(%rsp), %edx
movq %rax, %r13
callq 0x6ccd6
movq %r13, 0x50(%rsp)
movq %r13, %rax
xorl %ecx, %ecx
leaq 0x60(%rsp), %rdx
movq %rcx, %rsi
orq 0x8(%rsp), %rsi
movq %rsi, %rdi
imulq %r15, %rdi
addq 0x28(%rsp), %rdi
movq %rax, %r8
xorl %r9d, %r9d
cmpq %r14, %rsi
setb %r11b
movq %r9, %r10
orq %r12, %r10
cmpq %rbp, %r10
setl %r13b
andb %r11b, %r13b
cmpb $0x1, %r13b
jne 0x6d1da
btl $0x9, %ebx
jb 0x6d1b8
xorl %r10d, %r10d
movb (%rdx,%r10), %r11b
movb %r11b, (%r8,%r10)
incq %r10
cmpl $0x4, %r10d
jne 0x6d1a5
jmp 0x6d1da
movb 0x2(%rdx), %r11b
movb %r11b, (%rdi,%r10,4)
movb 0x1(%rdx), %r11b
movb %r11b, 0x1(%rdi,%r10,4)
movb (%rdx), %r11b
movb %r11b, 0x2(%rdi,%r10,4)
movb 0x3(%rdx), %r11b
movb %r11b, 0x3(%rdi,%r10,4)
addq $0x4, %rdx
incq %r9
addq $0x4, %r8
cmpq $0x4, %r9
jne 0x6d17f
incq %rcx
addq %r15, %rax
cmpq $0x4, %rcx
jne 0x6d165
movq 0x58(%rsp), %rsi
addq 0x48(%rsp), %rsi
addq $0x4, %r12
movq 0x50(%rsp), %rax
addq $0x10, %rax
cmpl 0x18(%rsp), %r12d
jl 0x6d140
movq 0x8(%rsp), %rcx
addq $0x4, %rcx
movq 0x10(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
cmpq %r14, %rcx
jb 0x6d110
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq