// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: getPixelColorsRGB8(unsigned char*, unsigned long, unsigned char const*, LodePNGColorMode const*)
static void getPixelColorsRGB8(unsigned char* LODEPNG_RESTRICT buffer, size_t numpixels,
                               const unsigned char* LODEPNG_RESTRICT in,
                               const LodePNGColorMode* mode) {
  const unsigned num_channels = 3;
  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];
      }
    } else if(mode->bitdepth == 16) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i * 2];
      }
    } 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;
      }
    }
  } else if(mode->colortype == LCT_RGB) {
    if(mode->bitdepth == 8) {
      lodepng_memcpy(buffer, in, numpixels * 3);
    } 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];
      }
    }
  } 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], 3);
      }
    } 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], 3);
      }
    }
  } 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];
      }
    } else {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        buffer[0] = buffer[1] = buffer[2] = in[i * 4 + 0];
      }
    }
  } else if(mode->colortype == LCT_RGBA) {
    if(mode->bitdepth == 8) {
      for(i = 0; i != numpixels; ++i, buffer += num_channels) {
        lodepng_memcpy(buffer, &in[i * 4], 3);
      }
    } 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];
      }
    }
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movl $0x3, 0x34(%rsp)
movq 0x38(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x1424ee
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x1423e5
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x1423e0
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x142392
jmp 0x1424e9
movq 0x38(%rsp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x14244f
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x14244a
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x1423f9
jmp 0x1424e7
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 0x1424e5
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x142477
jmp 0x1424e7
jmp 0x1424e9
jmp 0x142876
movq 0x38(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x14259b
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x14251e
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
imulq $0x3, 0x48(%rsp), %rdx
callq 0x14b830
jmp 0x142596
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142594
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x142527
jmp 0x142596
jmp 0x142874
movq 0x38(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x1426a3
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x14261f
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x14261d
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 $0x3, %edx
callq 0x14b830
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x1425bd
jmp 0x14269e
movq $0x0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x14269c
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 $0x3, %edx
callq 0x14b830
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x142631
jmp 0x14269e
jmp 0x142872
movq 0x38(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x14277a
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x142718
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142716
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x1426c5
jmp 0x142775
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x142773
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x142721
jmp 0x142775
jmp 0x142870
movq 0x38(%rsp), %rax
cmpl $0x6, (%rax)
jne 0x14286e
movq 0x38(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x1427eb
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x1427e6
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x28(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movl $0x3, %edx
callq 0x14b830
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x14279c
jmp 0x14286c
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x14286a
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 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x50(%rsp)
jmp 0x1427f4
jmp 0x14286c
jmp 0x14286e
jmp 0x142870
jmp 0x142872
jmp 0x142874
jmp 0x142876
addq $0x58, %rsp
retq
nopl (%rax,%rax)