// File: /workspace/github_cpp_makefile_star2_O3/phillip-h[P]fractal-gen/lodepng.cpp
// Function: getPixelColorsRGBA8(unsigned char*, unsigned long, unsigned int, unsigned char const*, LodePNGColorMode const*)
static void getPixelColorsRGBA8(unsigned char* buffer, size_t numpixels,
                                unsigned has_alpha, const unsigned char* in,
                                const LodePNGColorMode* mode)
{
  unsigned num_channels = has_alpha ? 4 : 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];
        if(has_alpha) buffer[3] = mode->key_defined && in[i] == mode->key_r ? 0 : 255;
      }
    }
    else if(mode->bitdepth == 16)
    {
      for(i = 0; i != numpixels; ++i, buffer += num_channels)
      {
        buffer[0] = buffer[1] = buffer[2] = in[i * 2];
        if(has_alpha) 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;
        if(has_alpha) 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)
      {
        buffer[0] = in[i * 3 + 0];
        buffer[1] = in[i * 3 + 1];
        buffer[2] = in[i * 3 + 2];
        if(has_alpha) buffer[3] = mode->key_defined && buffer[0] == mode->key_r
           && buffer[1]== mode->key_g && buffer[2] == mode->key_b ? 0 : 255;
      }
    }
    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];
        if(has_alpha) 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)
  {
    unsigned index;
    size_t j = 0;
    for(i = 0; i != numpixels; ++i, buffer += num_channels)
    {
      if(mode->bitdepth == 8) index = in[i];
      else index = readBitsFromReversedStream(&j, in, mode->bitdepth);

      if(index >= mode->palettesize)
      {
        /*This is an error according to the PNG spec, but most PNG decoders make it black instead.
        Done here too, slightly faster due to no error handling needed.*/
        buffer[0] = buffer[1] = buffer[2] = 0;
        if(has_alpha) buffer[3] = 255;
      }
      else
      {
        buffer[0] = mode->palette[index * 4 + 0];
        buffer[1] = mode->palette[index * 4 + 1];
        buffer[2] = mode->palette[index * 4 + 2];
        if(has_alpha) buffer[3] = 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];
        if(has_alpha) 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];
        if(has_alpha) buffer[3] = in[i * 4 + 2];
      }
    }
  }
  else if(mode->colortype == LCT_RGBA)
  {
    if(mode->bitdepth == 8)
    {
      for(i = 0; i != numpixels; ++i, buffer += num_channels)
      {
        buffer[0] = in[i * 4 + 0];
        buffer[1] = in[i * 4 + 1];
        buffer[2] = in[i * 4 + 2];
        if(has_alpha) buffer[3] = 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];
        if(has_alpha) buffer[3] = in[i * 8 + 6];
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %edx, %r9d
cmpl $0x1, %edx
movl (%r8), %edx
movl $0x4, %eax
sbbl $0x0, %eax
cmpq $0x6, %rdx
ja 0x8ad8
leaq 0x8f40(%rip), %r10      # 0x115d8
movslq (%r10,%rdx,4), %rdx
addq %r10, %rdx
jmpq *%rdx
movl 0x4(%r8), %edx
cmpl $0x8, %edx
je 0x89e6
cmpl $0x10, %edx
jne 0x8a3b
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx,2), %r10b
movb %r10b, -0x1(%rdi)
movb %r10b, -0x2(%rdi)
movb %r10b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8705
cmpl $0x0, 0x18(%r8)
je 0x86ff
movzwl (%rcx,%rdx,2), %r10d
rolw $0x8, %r10w
movzwl %r10w, %r10d
cmpl 0x1c(%r8), %r10d
setne %r10b
negb %r10b
jmp 0x8702
movb $-0x1, %r10b
movb %r10b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x86c8
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
movl %eax, %eax
xorl %edx, %edx
xorl %r10d, %r10d
movl 0x4(%r8), %ebx
cmpq $0x8, %rbx
jne 0x8736
movzbl (%rcx,%rdx), %r11d
jmp 0x8772
xorl %r11d, %r11d
testq %rbx, %rbx
je 0x8772
movq %rbx, %r14
movq %r10, %r15
movq %r15, %r12
shrq $0x3, %r12
movzbl (%rcx,%r12), %ebp
movl %r15d, %r12d
incq %r15
notb %r12b
andb $0x7, %r12b
shrxl %r12d, %ebp, %r12d
andl $0x1, %r12d
decq %r14
leal (%r12,%r11,2), %r11d
jne 0x8744
addq %rbx, %r10
movl %r11d, %ebx
cmpq %rbx, 0x10(%r8)
jbe 0x87b4
movq 0x8(%r8), %rbx
shll $0x2, %r11d
movb (%rbx,%r11), %bl
movb %bl, (%rdi)
movq 0x8(%r8), %rbx
movb 0x1(%rbx,%r11), %bl
movb %bl, 0x1(%rdi)
movq 0x8(%r8), %rbx
movb 0x2(%rbx,%r11), %bl
movb %bl, 0x2(%rdi)
testl %r9d, %r9d
je 0x87c9
movq 0x8(%r8), %rbx
movl %r11d, %r11d
movb 0x3(%rbx,%r11), %r11b
jmp 0x87c5
movb $-0x1, %r11b
movb $0x0, 0x2(%rdi)
movw $0x0, (%rdi)
testl %r9d, %r9d
je 0x87c9
movb %r11b, 0x3(%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rsi, %rdx
jne 0x8725
jmp 0x8ad8
cmpl $0x8, 0x4(%r8)
jne 0x88e5
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
addq $0x2, %rcx
movl %eax, %eax
movzbl -0x2(%rcx), %r11d
movb %r11b, -0x3(%rdi)
movzbl -0x1(%rcx), %ebx
movb %bl, -0x2(%rdi)
movzbl (%rcx), %r10d
movb %r10b, -0x1(%rdi)
testl %r9d, %r9d
je 0x8838
cmpl $0x0, 0x18(%r8)
movb $-0x1, %dl
je 0x8836
cmpl %r11d, 0x1c(%r8)
jne 0x8836
cmpl %ebx, 0x20(%r8)
jne 0x8836
cmpl %r10d, 0x24(%r8)
setne %dl
negb %dl
movb %dl, (%rdi)
addq %rax, %rdi
addq $0x3, %rcx
decq %rsi
jne 0x87fb
jmp 0x8ad8
cmpl $0x8, 0x4(%r8)
jne 0x8960
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx,2), %r8b
movb %r8b, -0x1(%rdi)
movb %r8b, -0x2(%rdi)
movb %r8b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8882
movb 0x1(%rcx,%rdx,2), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x8865
jmp 0x8ad8
cmpl $0x8, 0x4(%r8)
jne 0x899e
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx,4), %r8b
movb %r8b, -0x3(%rdi)
movb 0x1(%rcx,%rdx,4), %r8b
movb %r8b, -0x2(%rdi)
movb 0x2(%rcx,%rdx,4), %r8b
movb %r8b, -0x1(%rdi)
testl %r9d, %r9d
je 0x88d5
movb 0x3(%rcx,%rdx,4), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x88ae
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
movb (%rcx), %dl
movb %dl, -0x3(%rdi)
movb 0x2(%rcx), %dl
movb %dl, -0x2(%rdi)
movzbl 0x4(%rcx), %edx
movb %dl, -0x1(%rdi)
testl %r9d, %r9d
je 0x894f
cmpl $0x0, 0x18(%r8)
movb $-0x1, %r10b
je 0x894c
movbew (%rcx), %r11w
movzwl %r11w, %r11d
cmpl 0x1c(%r8), %r11d
jne 0x894c
movbew 0x2(%rcx), %r11w
movzwl %r11w, %r11d
cmpl 0x20(%r8), %r11d
jne 0x894c
movzbl 0x5(%rcx), %r10d
shll $0x8, %edx
orl %edx, %r10d
cmpl 0x24(%r8), %r10d
setne %r10b
negb %r10b
movb %r10b, (%rdi)
addq %rax, %rdi
addq $0x6, %rcx
decq %rsi
jne 0x88f4
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx,4), %r8b
movb %r8b, -0x1(%rdi)
movb %r8b, -0x2(%rdi)
movb %r8b, -0x3(%rdi)
testl %r9d, %r9d
je 0x898e
movb 0x2(%rcx,%rdx,4), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x8971
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx,8), %r8b
movb %r8b, -0x3(%rdi)
movb 0x2(%rcx,%rdx,8), %r8b
movb %r8b, -0x2(%rdi)
movb 0x4(%rcx,%rdx,8), %r8b
movb %r8b, -0x1(%rdi)
testl %r9d, %r9d
je 0x89d6
movb 0x6(%rcx,%rdx,8), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x89af
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
addq $0x3, %rdi
movl %eax, %eax
xorl %edx, %edx
movb (%rcx,%rdx), %r10b
movb %r10b, -0x1(%rdi)
movb %r10b, -0x2(%rdi)
movb %r10b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8a2b
cmpl $0x0, 0x18(%r8)
je 0x8a25
movzbl (%rcx,%rdx), %r10d
cmpl %r10d, 0x1c(%r8)
setne %r10b
negb %r10b
jmp 0x8a28
movb $-0x1, %r10b
movb %r10b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x89f7
jmp 0x8ad8
testq %rsi, %rsi
je 0x8ad8
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %eax, %r11d
xorl %ebx, %ebx
xorl %r14d, %r14d
shlxl %edx, %r10d, %r10d
notl %r10d
movl 0x4(%r8), %eax
xorl %r15d, %r15d
testq %rax, %rax
je 0x8a9b
movq %rax, %rdx
movq %r14, %r12
movq %r12, %r13
shrq $0x3, %r13
movzbl (%rcx,%r13), %ebp
movl %r12d, %r13d
incq %r12
notb %r13b
andb $0x7, %r13b
shrxl %r13d, %ebp, %r13d
andl $0x1, %r13d
decq %rdx
leal (%r13,%r15,2), %r15d
jne 0x8a6c
addq %rax, %r14
movl %r15d, %eax
shll $0x8, %eax
xorl %edx, %edx
subl %r15d, %eax
divl %r10d
movb %al, 0x2(%rdi)
movb %al, 0x1(%rdi)
movb %al, (%rdi)
testl %r9d, %r9d
je 0x8acd
cmpl $0x0, 0x18(%r8)
je 0x8ac8
cmpl 0x1c(%r8), %r15d
setne %al
negb %al
jmp 0x8aca
movb $-0x1, %al
movb %al, 0x3(%rdi)
incq %rbx
addq %r11, %rdi
cmpq %rsi, %rbx
jne 0x8a5a
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq