// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %r8, %r12
movq %rcx, %rbx
cmpl $0x1, %edx
pushq $0x4
popq %rax
movl (%r8), %ecx
sbbl $0x0, %eax
cmpq $0x6, %rcx
ja 0x716d
movq %rsi, %r14
leaq 0x75dc(%rip), %rsi      # 0xe3a4
movl %edx, %r8d
movq %rdi, %r15
movl %r8d, 0xc(%rsp)
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl 0x4(%r12), %ecx
cmpl $0x8, %ecx
je 0x70b4
cmpl $0x10, %ecx
jne 0x70fe
addq $0x3, %r15
movl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx,2), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x6e3c
cmpl $0x0, 0x18(%r12)
je 0x6e37
movzwl (%rbx,%rcx,2), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r12), %edx
setne %dl
negb %dl
jmp 0x6e39
movb $-0x1, %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x6dfb
leaq 0x10(%rsp), %rcx
addq $0x3, %r15
movl %eax, %r13d
xorl %ebp, %ebp
andq $0x0, (%rcx)
cmpq %rbp, %r14
je 0x716d
movl 0x4(%r12), %edx
cmpq $0x8, %rdx
jne 0x6e70
movzbl (%rbx,%rbp), %eax
jmp 0x6e82
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xbe10
movl 0xc(%rsp), %r8d
movl %eax, %ecx
cmpq %rcx, 0x10(%r12)
jbe 0x6ec6
movq 0x8(%r12), %rcx
shll $0x2, %eax
movb (%rcx,%rax), %cl
movb %cl, -0x3(%r15)
movq 0x8(%r12), %rcx
movb 0x1(%rcx,%rax), %cl
movb %cl, -0x2(%r15)
movq 0x8(%r12), %rcx
movb 0x2(%rcx,%rax), %cl
movb %cl, -0x1(%r15)
testl %r8d, %r8d
je 0x6edb
movq 0x8(%r12), %rcx
movl %eax, %eax
movb 0x3(%rcx,%rax), %al
jmp 0x6ed8
andw $0x0, -0x3(%r15)
movb $-0x1, %al
movb $0x0, -0x1(%r15)
testl %r8d, %r8d
je 0x6edb
movb %al, (%r15)
incq %rbp
addq %r13, %r15
jmp 0x6e56
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x6fd8
addq $0x2, %rbx
addq $0x3, %r15
subq $0x1, %r14
jb 0x716d
movzbl -0x2(%rbx), %esi
movb %sil, -0x3(%r15)
movzbl -0x1(%rbx), %edi
movb %dil, -0x2(%r15)
movzbl (%rbx), %edx
movb %dl, -0x1(%r15)
testl %r8d, %r8d
je 0x6f47
cmpl $0x0, 0x18(%r12)
movb $-0x1, %cl
je 0x6f44
cmpl %esi, 0x1c(%r12)
jne 0x6f44
cmpl %edi, 0x20(%r12)
jne 0x6f44
cmpl %edx, 0x24(%r12)
setne %cl
negb %cl
movb %cl, (%r15)
addq $0x3, %rbx
addq %rax, %r15
jmp 0x6efc
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x7048
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx,2), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x6f88
movb 0x1(%rbx,%rcx,2), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x6f64
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x707a
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx,4), %dl
movb %dl, -0x3(%r15)
movb 0x1(%rbx,%rcx,4), %dl
movb %dl, -0x2(%r15)
movb 0x2(%rbx,%rcx,4), %dl
movb %dl, -0x1(%r15)
testl %r8d, %r8d
je 0x6fd0
movb 0x3(%rbx,%rcx,4), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x6fa4
addq $0x3, %r15
subq $0x1, %r14
jb 0x716d
movb (%rbx), %cl
movb %cl, -0x3(%r15)
movb 0x2(%rbx), %cl
movb %cl, -0x2(%r15)
movzbl 0x4(%rbx), %ecx
movb %cl, -0x1(%r15)
testl %r8d, %r8d
je 0x703f
cmpl $0x0, 0x18(%r12)
movb $-0x1, %dl
je 0x703c
movbew (%rbx), %si
movzwl %si, %esi
cmpl 0x1c(%r12), %esi
jne 0x703c
movbew 0x2(%rbx), %si
movzwl %si, %esi
cmpl 0x20(%r12), %esi
jne 0x703c
movzbl 0x5(%rbx), %edx
shll $0x8, %ecx
orl %ecx, %edx
cmpl 0x24(%r12), %edx
setne %dl
negb %dl
movb %dl, (%r15)
addq $0x6, %rbx
addq %rax, %r15
jmp 0x6fdc
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx,4), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x7072
movb 0x2(%rbx,%rcx,4), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x704e
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx,8), %dl
movb %dl, -0x3(%r15)
movb 0x2(%rbx,%rcx,8), %dl
movb %dl, -0x2(%r15)
movb 0x4(%rbx,%rcx,8), %dl
movb %dl, -0x1(%r15)
testl %r8d, %r8d
je 0x70ac
movb 0x6(%rbx,%rcx,8), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x7080
addq $0x3, %r15
movl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x716d
movb (%rbx,%rcx), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x70f6
cmpl $0x0, 0x18(%r12)
je 0x70f1
movzbl (%rbx,%rcx), %edx
cmpl %edx, 0x1c(%r12)
setne %dl
negb %dl
jmp 0x70f3
movb $-0x1, %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x70bc
pushq $-0x1
popq %rdx
shlxl %ecx, %edx, %ebp
leaq 0x10(%rsp), %rdx
addq $0x3, %r15
movl %eax, %r13d
andq $0x0, (%rdx)
notl %ebp
subq $0x1, %r14
jb 0x716d
movl 0x4(%r12), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xbe10
movl %eax, %ecx
imull $0xff, %eax, %eax
xorl %edx, %edx
divl %ebp
cmpl $0x0, 0xc(%rsp)
movb %al, -0x1(%r15)
movb %al, -0x2(%r15)
movb %al, -0x3(%r15)
je 0x7168
cmpl $0x0, 0x18(%r12)
je 0x7163
cmpl 0x1c(%r12), %ecx
setne %al
negb %al
jmp 0x7165
movb $-0x1, %al
movb %al, (%r15)
addq %r13, %r15
jmp 0x7118
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq