// File: /workspace/github_c_makefile_star2_O2/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: getPixelColorsRGBA8
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
sbbl $0x0, %eax
movl (%r8), %ecx
cmpq $0x6, %rcx
ja 0x47e9
movl %edx, %r8d
movq %rsi, %r14
movq %rdi, %r15
leaq 0x6c5b(%rip), %rdx      # 0xb0a4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movl %r8d, 0xc(%rsp)
jmpq *%rcx
movl 0x4(%r12), %ecx
cmpl $0x8, %ecx
je 0x4733
cmpl $0x10, %ecx
jne 0x477d
movl %eax, %eax
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
movb (%rbx,%rcx,2), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x44b7
cmpl $0x0, 0x18(%r12)
je 0x44b2
movzwl (%rbx,%rcx,2), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r12), %edx
setne %dl
negb %dl
jmp 0x44b4
movb $-0x1, %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x4476
leaq 0x10(%rsp), %rcx
andq $0x0, (%rcx)
movl %eax, %r13d
addq $0x3, %r15
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x47e9
movl 0x4(%r12), %edx
cmpq $0x8, %rdx
jne 0x44eb
movzbl (%rbx,%rbp), %eax
jmp 0x44fd
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x8e18
movl 0xc(%rsp), %r8d
movl %eax, %ecx
cmpq %rcx, 0x10(%r12)
jbe 0x4541
shll $0x2, %eax
movq 0x8(%r12), %rcx
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 0x4556
movq 0x8(%r12), %rcx
movl %eax, %eax
movb 0x3(%rcx,%rax), %al
jmp 0x4553
andw $0x0, -0x3(%r15)
movb $0x0, -0x1(%r15)
movb $-0x1, %al
testl %r8d, %r8d
je 0x4556
movb %al, (%r15)
incq %rbp
addq %r13, %r15
jmp 0x44d1
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x4653
addq $0x2, %rbx
addq $0x3, %r15
subq $0x1, %r14
jb 0x47e9
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 0x45c2
movb $-0x1, %cl
cmpl $0x0, 0x18(%r12)
je 0x45bf
cmpl %esi, 0x1c(%r12)
jne 0x45bf
cmpl %edi, 0x20(%r12)
jne 0x45bf
cmpl %edx, 0x24(%r12)
setne %cl
negb %cl
movb %cl, (%r15)
addq $0x3, %rbx
addq %rax, %r15
jmp 0x4577
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x46c7
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
movb (%rbx,%rcx,2), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x4603
movb 0x1(%rbx,%rcx,2), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x45df
cmpl $0x8, 0x4(%r12)
movl %eax, %eax
jne 0x46f9
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
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 0x464b
movb 0x3(%rbx,%rcx,4), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x461f
addq $0x3, %r15
subq $0x1, %r14
jb 0x47e9
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 0x46be
movb $-0x1, %dl
cmpl $0x0, 0x18(%r12)
je 0x46bb
movzwl (%rbx), %esi
rolw $0x8, %si
movzwl %si, %esi
cmpl 0x1c(%r12), %esi
jne 0x46bb
movzwl 0x2(%rbx), %esi
rolw $0x8, %si
movzwl %si, %esi
cmpl 0x20(%r12), %esi
jne 0x46bb
shll $0x8, %ecx
movzbl 0x5(%rbx), %edx
orl %ecx, %edx
cmpl 0x24(%r12), %edx
setne %dl
negb %dl
movb %dl, (%r15)
addq $0x6, %rbx
addq %rax, %r15
jmp 0x4657
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
movb (%rbx,%rcx,4), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x46f1
movb 0x2(%rbx,%rcx,4), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x46cd
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
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 0x472b
movb 0x6(%rbx,%rcx,8), %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x46ff
movl %eax, %eax
addq $0x3, %r15
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x47e9
movb (%rbx,%rcx), %dl
movb %dl, -0x1(%r15)
movb %dl, -0x2(%r15)
movb %dl, -0x3(%r15)
testl %r8d, %r8d
je 0x4775
cmpl $0x0, 0x18(%r12)
je 0x4770
movzbl (%rbx,%rcx), %edx
cmpl %edx, 0x1c(%r12)
setne %dl
negb %dl
jmp 0x4772
movb $-0x1, %dl
movb %dl, (%r15)
incq %rcx
addq %rax, %r15
jmp 0x473b
pushq $-0x1
popq %rbp
shll %cl, %ebp
leaq 0x10(%rsp), %rcx
andq $0x0, (%rcx)
notl %ebp
movl %eax, %r13d
addq $0x3, %r15
subq $0x1, %r14
jb 0x47e9
movl 0x4(%r12), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x8e18
movl %eax, %ecx
imull $0xff, %eax, %eax
xorl %edx, %edx
divl %ebp
movb %al, -0x1(%r15)
movb %al, -0x2(%r15)
movb %al, -0x3(%r15)
cmpl $0x0, 0xc(%rsp)
je 0x47e4
cmpl $0x0, 0x18(%r12)
je 0x47df
cmpl 0x1c(%r12), %ecx
setne %al
negb %al
jmp 0x47e1
movb $-0x1, %al
movb %al, (%r15)
addq %r13, %r15
jmp 0x4794
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq