// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: getPixelColorsRGBA8(unsigned char*, unsigned long, unsigned char const*, LodePNGColorMode const*)
static void getPixelColorsRGBA8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels,
                                const unsigned char* LODEPNG_RESTRICT in,
                                const LodePNGColorMode* mode) {
  unsigned num_channels = 4;
  size_t i;
  if(mode->colortype == LCT_GREY) {
    if(mode->bitdepth == 8) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i];
        buffer[3] = 255;
      }
      if(mode->key_defined) {
        buffer -= numpixels * num_channels;
        for(i = 0; i != numpixels; ++i, buffer += num_channels) {
          if(buffer[0] == mode->key_r) buffer[3] = 0;
        }
      }
    } else if(mode->bitdepth == 16) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i * 2];
        buffer[3] = mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r ? 0 : 255;
      }
    } else {
      unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
      size_t j = 0;
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
        buffer[0] = buffer[1] = buffer[2] = (value * 255) / highest;
        buffer[3] = mode->key_defined && value == mode->key_r ? 0 : 255;
      }
    }
  } else if(mode->colortype == LCT_RGB) {
    if(mode->bitdepth == 8) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        lodepng_memcpy(buffer, &in[i * 3], 3);
        buffer[3] = 255;
      }
      if(mode->key_defined) {
        buffer -= numpixels * num_channels;
        for(i = 0; i != numpixels; ++i, buffer += num_channels) {
          if(buffer[0] == mode->key_r && buffer[1]== mode->key_g && buffer[2] == mode->key_b) buffer[3] = 0;
        }
      }
    } else {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = in[i * 6 + 0];
        buffer[1] = in[i * 6 + 2];
        buffer[2] = in[i * 6 + 4];
        buffer[3] = mode->key_defined
           && 256U * in[i * 6 + 0] + in[i * 6 + 1] == mode->key_r
           && 256U * in[i * 6 + 2] + in[i * 6 + 3] == mode->key_g
           && 256U * in[i * 6 + 4] + in[i * 6 + 5] == mode->key_b ? 0 : 255;
      }
    }
  } else if(mode->colortype == LCT_PALETTE) {
    if(mode->bitdepth == 8) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        unsigned index = in[i];
        /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/
        lodepng_memcpy(buffer, &mode->palette[index * 4], 4);
      }
    } else {
      size_t j = 0;
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        unsigned index = readBitsFromReversedStream(&j, in, mode->bitdepth);
        /*out of bounds of palette not checked: see lodepng_color_mode_alloc_palette.*/
        lodepng_memcpy(buffer, &mode->palette[index * 4], 4);
      }
    }
  } else if(mode->colortype == LCT_GREY_ALPHA) {
    if(mode->bitdepth == 8) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i * 2 + 0];
        buffer[3] = in[i * 2 + 1];
      }
    } else {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0];
        buffer[3] = in[i * 4 + 2];
      }
    }
  } else if(mode->colortype == LCT_RGBA) {
    if(mode->bitdepth == 8) {
      lodepng_memcpy(buffer, in, numpixels * 4);
    } else {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = in[i * 8 + 0];
        buffer[1] = in[i * 8 + 2];
        buffer[2] = in[i * 8 + 4];
        buffer[3] = in[i * 8 + 6];
      }
    }
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movl $0x4, 0x34(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x141daf
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x141be8
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141b62
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb $-0x1, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141b06
movq 0x38(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x141be3
movq 0x48(%rsp), %rdx
movl 0x34(%rsp), %eax
imulq %rax, %rdx
movq 0x50(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141be1
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
movq 0x38(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x141bbc
movq 0x50(%rsp), %rax
movb $0x0, 0x3(%rax)
jmp 0x141bbe
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141b95
jmp 0x141be3
jmp 0x141daa
movq 0x38(%rsp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x141cc5
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141cc0
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x38(%rsp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x18(%rcx)
movb %al, 0x3(%rsp)
je 0x141c7f
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq 0x40(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq %rdx
movzbl 0x1(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x38(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
sete %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141c00
jmp 0x141da8
movq 0x38(%rsp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, 0x24(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141da6
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq 0x18(%rsp), %rdi
callq 0x14fc90
movl %eax, 0x14(%rsp)
imull $0xff, 0x14(%rsp), %eax
xorl %edx, %edx
divl 0x24(%rsp)
movb %al, %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x38(%rsp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x18(%rcx)
movb %al, 0x2(%rsp)
je 0x141d65
movl 0x14(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
sete %al
movb %al, 0x2(%rsp)
movb 0x2(%rsp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141ced
jmp 0x141da8
jmp 0x141daa
jmp 0x142340
movq 0x38(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x142030
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x141eda
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141e2a
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
imulq $0x3, 0x28(%rsp), %rax
addq %rax, %rsi
movl $0x3, %edx
callq 0x14b830
movq 0x50(%rsp), %rax
movb $-0x1, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141dd5
movq 0x38(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x141ed5
movq 0x48(%rsp), %rdx
movl 0x34(%rsp), %eax
imulq %rax, %rdx
movq 0x50(%rsp), %rax
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x141ed3
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
movq 0x38(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x141eae
movq 0x50(%rsp), %rax
movzbl 0x1(%rax), %eax
movq 0x38(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x141eae
movq 0x50(%rsp), %rax
movzbl 0x2(%rax), %eax
movq 0x38(%rsp), %rcx
cmpl 0x24(%rcx), %eax
jne 0x141eae
movq 0x50(%rsp), %rax
movb $0x0, 0x3(%rax)
jmp 0x141eb0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141e61
jmp 0x141ed5
jmp 0x14202b
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142029
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb 0x4(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x38(%rsp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x18(%rcx)
movb %al, 0x1(%rsp)
je 0x141fe8
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x1(%rax,%rdx), %eax
addl %eax, %ecx
movq 0x38(%rsp), %rdx
xorl %eax, %eax
cmpl 0x1c(%rdx), %ecx
movb %al, 0x1(%rsp)
jne 0x141fe8
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl 0x2(%rax,%rcx), %ecx
shll $0x8, %ecx
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x3(%rax,%rdx), %eax
addl %eax, %ecx
movq 0x38(%rsp), %rdx
xorl %eax, %eax
cmpl 0x20(%rdx), %ecx
movb %al, 0x1(%rsp)
jne 0x141fe8
movq 0x40(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl 0x4(%rax,%rcx), %eax
shll $0x8, %eax
movq 0x40(%rsp), %rcx
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x5(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x38(%rsp), %rcx
cmpl 0x24(%rcx), %eax
sete %al
movb %al, 0x1(%rsp)
movb 0x1(%rsp), %dl
movl $0xff, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x141ee3
jmp 0x14202b
jmp 0x14233e
movq 0x38(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x142145
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x1420bc
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x1420b7
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x10(%rsp), %eax
shll $0x2, %eax
movl %eax, %eax
addq %rax, %rsi
movl $0x4, %edx
callq 0x14b830
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x142052
jmp 0x142140
movq $0x0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x14213e
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x14fc90
movl %eax, 0x4(%rsp)
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x4(%rsp), %eax
shll $0x2, %eax
movl %eax, %eax
addq %rax, %rsi
movl $0x4, %edx
callq 0x14b830
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x1420ce
jmp 0x142140
jmp 0x14233c
movq 0x38(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x142259
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x1421d8
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x1421d6
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb 0x1(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x142167
jmp 0x142254
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142252
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x1421e1
jmp 0x142254
jmp 0x14233a
movq 0x38(%rsp), %rax
cmpl $0x6, (%rax)
jne 0x142338
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x14228f
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
shlq $0x2, %rdx
callq 0x14b830
jmp 0x142336
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142334
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x1(%rax)
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x4(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x2(%rax)
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x6(%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x3(%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
jmp 0x142298
jmp 0x142336
jmp 0x142338
jmp 0x14233a
jmp 0x14233c
jmp 0x14233e
jmp 0x142340
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)