// File: /workspace/github_cpp_makefile_star2_O1/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 $0x4, %eax
sbbl $0x0, %eax
movl (%r8), %edx
cmpq $0x6, %rdx
ja 0x8b59
leaq 0x8e7e(%rip), %r10      # 0x11598
movslq (%r10,%rdx,4), %rdx
addq %r10, %rdx
jmpq *%rdx
movl 0x4(%r8), %edx
cmpl $0x8, %edx
je 0x8a67
cmpl $0x10, %edx
jne 0x8abc
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
xorl %edx, %edx
movb (%rcx,%rdx,2), %r10b
movb %r10b, -0x1(%rdi)
movb %r10b, -0x2(%rdi)
movb %r10b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8787
cmpl $0x0, 0x18(%r8)
je 0x8781
movzwl (%rcx,%rdx,2), %r10d
rolw $0x8, %r10w
movzwl %r10w, %r10d
cmpl 0x1c(%r8), %r10d
setne %r10b
negb %r10b
jmp 0x8784
movb $-0x1, %r10b
movb %r10b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x874a
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
xorl %edx, %edx
xorl %r10d, %r10d
movl 0x4(%r8), %ebx
cmpq $0x8, %rbx
jne 0x87b8
movzbl (%rcx,%rdx), %r11d
jmp 0x87f4
xorl %r11d, %r11d
testq %rbx, %rbx
je 0x87f4
movq %rbx, %r14
movq %r10, %r15
movq %r15, %r12
shrq $0x3, %r12
movzbl (%rcx,%r12), %ebp
movl %r15d, %r12d
notb %r12b
andb $0x7, %r12b
shrxl %r12d, %ebp, %r12d
andl $0x1, %r12d
incq %r15
leal (%r12,%r11,2), %r11d
decq %r14
jne 0x87c6
addq %rbx, %r10
movl %r11d, %ebx
cmpq %rbx, 0x10(%r8)
jbe 0x8836
shll $0x2, %r11d
movq 0x8(%r8), %rbx
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 0x884b
movq 0x8(%r8), %rbx
movl %r11d, %r11d
movb 0x3(%rbx,%r11), %r11b
jmp 0x8847
movb $0x0, 0x2(%rdi)
movw $0x0, (%rdi)
movb $-0x1, %r11b
testl %r9d, %r9d
je 0x884b
movb %r11b, 0x3(%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rsi, %rdx
jne 0x87a7
jmp 0x8b59
cmpl $0x8, 0x4(%r8)
jne 0x8967
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
addq $0x2, %rcx
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 0x88ba
movb $-0x1, %dl
cmpl $0x0, 0x18(%r8)
je 0x88b8
cmpl %r11d, 0x1c(%r8)
jne 0x88b8
cmpl %ebx, 0x20(%r8)
jne 0x88b8
cmpl %r10d, 0x24(%r8)
setne %dl
negb %dl
movb %dl, (%rdi)
addq %rax, %rdi
addq $0x3, %rcx
decq %rsi
jne 0x887d
jmp 0x8b59
cmpl $0x8, 0x4(%r8)
jne 0x89e1
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
xorl %edx, %edx
movb (%rcx,%rdx,2), %r8b
movb %r8b, -0x1(%rdi)
movb %r8b, -0x2(%rdi)
movb %r8b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8904
movb 0x1(%rcx,%rdx,2), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x88e7
jmp 0x8b59
cmpl $0x8, 0x4(%r8)
jne 0x8a1f
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
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 0x8957
movb 0x3(%rcx,%rdx,4), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x8930
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
addq $0x5, %rcx
movb -0x5(%rcx), %dl
movb %dl, -0x3(%rdi)
movb -0x3(%rcx), %dl
movb %dl, -0x2(%rdi)
movb -0x1(%rcx), %dl
movb %dl, -0x1(%rdi)
testl %r9d, %r9d
je 0x89d0
movb $-0x1, %dl
cmpl $0x0, 0x18(%r8)
je 0x89ce
movbew -0x5(%rcx), %r10w
movzwl %r10w, %r10d
cmpl 0x1c(%r8), %r10d
jne 0x89ce
movbew -0x3(%rcx), %r10w
movzwl %r10w, %r10d
cmpl 0x20(%r8), %r10d
jne 0x89ce
movbew -0x1(%rcx), %dx
movzwl %dx, %edx
cmpl 0x24(%r8), %edx
setne %dl
negb %dl
movb %dl, (%rdi)
addq %rax, %rdi
addq $0x6, %rcx
decq %rsi
jne 0x897a
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
xorl %edx, %edx
movb (%rcx,%rdx,4), %r8b
movb %r8b, -0x1(%rdi)
movb %r8b, -0x2(%rdi)
movb %r8b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8a0f
movb 0x2(%rcx,%rdx,4), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x89f2
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
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 0x8a57
movb 0x6(%rcx,%rdx,8), %r8b
movb %r8b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x8a30
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl %eax, %eax
addq $0x3, %rdi
xorl %edx, %edx
movb (%rcx,%rdx), %r10b
movb %r10b, -0x1(%rdi)
movb %r10b, -0x2(%rdi)
movb %r10b, -0x3(%rdi)
testl %r9d, %r9d
je 0x8aac
cmpl $0x0, 0x18(%r8)
je 0x8aa6
movzbl (%rcx,%rdx), %r10d
cmpl %r10d, 0x1c(%r8)
setne %r10b
negb %r10b
jmp 0x8aa9
movb $-0x1, %r10b
movb %r10b, (%rdi)
incq %rdx
addq %rax, %rdi
cmpq %rdx, %rsi
jne 0x8a78
jmp 0x8b59
testq %rsi, %rsi
je 0x8b59
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shlxl %edx, %r10d, %r10d
notl %r10d
movl %eax, %r11d
xorl %ebx, %ebx
xorl %r14d, %r14d
movl 0x4(%r8), %eax
xorl %r15d, %r15d
testq %rax, %rax
je 0x8b1c
movq %rax, %rdx
movq %r14, %r12
movq %r12, %r13
shrq $0x3, %r13
movzbl (%rcx,%r13), %ebp
movl %r12d, %r13d
notb %r13b
andb $0x7, %r13b
shrxl %r13d, %ebp, %r13d
andl $0x1, %r13d
incq %r12
leal (%r13,%r15,2), %r15d
decq %rdx
jne 0x8aed
addq %rax, %r14
movl %r15d, %eax
shll $0x8, %eax
subl %r15d, %eax
xorl %edx, %edx
divl %r10d
movb %al, 0x2(%rdi)
movb %al, 0x1(%rdi)
movb %al, (%rdi)
testl %r9d, %r9d
je 0x8b4e
cmpl $0x0, 0x18(%r8)
je 0x8b49
cmpl 0x1c(%r8), %r15d
setne %al
negb %al
jmp 0x8b4b
movb $-0x1, %al
movb %al, 0x3(%rdi)
incq %rbx
addq %r11, %rdi
cmpq %rsi, %rbx
jne 0x8adb
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq