// File: /workspace/github_c_makefile_star2_O1/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
movq %rcx, %r10
cmpl $0x1, %edx
movl $0x4, %eax
sbbl $0x0, %eax
movl (%r8), %ecx
cmpq $0x6, %rcx
ja 0x59d8
movl %edx, %r9d
leaq 0x8b04(%rip), %rdx      # 0xe0a4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x4(%r8), %ecx
cmpl $0x8, %ecx
je 0x58e2
cmpl $0x10, %ecx
jne 0x5930
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx,2), %dl
movb %dl, -0x1(%rdi)
movb %dl, -0x2(%rdi)
movb %dl, -0x3(%rdi)
testl %r9d, %r9d
je 0x5604
cmpl $0x0, 0x18(%r8)
je 0x5600
movzwl (%r10,%rcx,2), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r8), %edx
setne %dl
negb %dl
jmp 0x5602
movb $-0x1, %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x55d0
jmp 0x59d8
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x4(%r8), %ebx
cmpq $0x8, %rbx
jne 0x5634
movzbl (%r10,%rcx), %r11d
jmp 0x5677
xorl %r11d, %r11d
testq %rbx, %rbx
je 0x5677
movq %rbx, %r14
movq %rdx, %r15
movq %r15, %r12
shrq $0x3, %r12
movzbl (%r10,%r12), %ebp
movl %r15d, %r12d
notb %r12b
movzbl %r12b, %r12d
andl $0x7, %r12d
xorl %r13d, %r13d
btl %r12d, %ebp
setb %r13b
incq %r15
leal (%r13,%r11,2), %r11d
decq %r14
jne 0x5642
addq %rbx, %rdx
movl %r11d, %ebx
cmpq %rbx, 0x10(%r8)
jbe 0x56b9
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 0x56ce
movq 0x8(%r8), %rbx
movl %r11d, %r11d
movb 0x3(%rbx,%r11), %r11b
jmp 0x56ca
movb $0x0, 0x2(%rdi)
movw $0x0, (%rdi)
movb $-0x1, %r11b
testl %r9d, %r9d
je 0x56ce
movb %r11b, 0x3(%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rsi, %rcx
jne 0x5623
jmp 0x59d8
cmpl $0x8, 0x4(%r8)
jne 0x57e2
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
addq $0x2, %r10
movzbl -0x2(%r10), %r11d
movb %r11b, -0x3(%rdi)
movzbl -0x1(%r10), %ebx
movb %bl, -0x2(%rdi)
movzbl (%r10), %edx
movb %dl, -0x1(%rdi)
testl %r9d, %r9d
je 0x573d
movb $-0x1, %cl
cmpl $0x0, 0x18(%r8)
je 0x573b
cmpl %r11d, 0x1c(%r8)
jne 0x573b
cmpl %ebx, 0x20(%r8)
jne 0x573b
cmpl %edx, 0x24(%r8)
setne %cl
negb %cl
movb %cl, (%rdi)
addq %rax, %rdi
addq $0x3, %r10
decq %rsi
jne 0x5700
jmp 0x59d8
cmpl $0x8, 0x4(%r8)
jne 0x5864
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx,2), %dl
movb %dl, -0x1(%rdi)
movb %dl, -0x2(%rdi)
movb %dl, -0x3(%rdi)
testl %r9d, %r9d
je 0x5783
movb 0x1(%r10,%rcx,2), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x576a
jmp 0x59d8
cmpl $0x8, 0x4(%r8)
jne 0x589e
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx,4), %dl
movb %dl, -0x3(%rdi)
movb 0x1(%r10,%rcx,4), %dl
movb %dl, -0x2(%rdi)
movb 0x2(%r10,%rcx,4), %dl
movb %dl, -0x1(%rdi)
testl %r9d, %r9d
je 0x57d2
movb 0x3(%r10,%rcx,4), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x57af
jmp 0x59d8
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
addq $0x5, %r10
movb -0x5(%r10), %cl
movb %cl, -0x3(%rdi)
movb -0x3(%r10), %cl
movb %cl, -0x2(%rdi)
movb -0x1(%r10), %cl
movb %cl, -0x1(%rdi)
testl %r9d, %r9d
je 0x5853
movb $-0x1, %cl
cmpl $0x0, 0x18(%r8)
je 0x5851
movzwl -0x5(%r10), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r8), %edx
jne 0x5851
movzwl -0x3(%r10), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x20(%r8), %edx
jne 0x5851
movzwl -0x1(%r10), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
cmpl 0x24(%r8), %ecx
setne %cl
negb %cl
movb %cl, (%rdi)
addq %rax, %rdi
addq $0x6, %r10
decq %rsi
jne 0x57f5
jmp 0x59d8
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx,4), %dl
movb %dl, -0x1(%rdi)
movb %dl, -0x2(%rdi)
movb %dl, -0x3(%rdi)
testl %r9d, %r9d
je 0x588e
movb 0x2(%r10,%rcx,4), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5875
jmp 0x59d8
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx,8), %dl
movb %dl, -0x3(%rdi)
movb 0x2(%r10,%rcx,8), %dl
movb %dl, -0x2(%rdi)
movb 0x4(%r10,%rcx,8), %dl
movb %dl, -0x1(%rdi)
testl %r9d, %r9d
je 0x58d2
movb 0x6(%r10,%rcx,8), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x58af
jmp 0x59d8
testq %rsi, %rsi
je 0x59d8
movl %eax, %eax
addq $0x3, %rdi
xorl %ecx, %ecx
movb (%r10,%rcx), %dl
movb %dl, -0x1(%rdi)
movb %dl, -0x2(%rdi)
movb %dl, -0x3(%rdi)
testl %r9d, %r9d
je 0x5920
cmpl $0x0, 0x18(%r8)
je 0x591c
movzbl (%r10,%rcx), %edx
cmpl %edx, 0x1c(%r8)
setne %dl
negb %dl
jmp 0x591e
movb $-0x1, %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x58f3
jmp 0x59d8
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shll %cl, %r11d
testq %rsi, %rsi
je 0x59d8
notl %r11d
movl %eax, %eax
movq %rax, -0x8(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movl 0x4(%r8), %eax
xorl %r15d, %r15d
testq %rax, %rax
je 0x5995
movq %rax, %rdx
movq %r14, %r12
movq %r12, %r13
shrq $0x3, %r13
movzbl (%r10,%r13), %ebp
movl %r12d, %r13d
notb %r13b
movzbl %r13b, %r13d
andl $0x7, %r13d
xorl %ecx, %ecx
btl %r13d, %ebp
setb %cl
incq %r12
leal (%rcx,%r15,2), %r15d
decq %rdx
jne 0x5963
addq %rax, %r14
movl %r15d, %eax
shll $0x8, %eax
subl %r15d, %eax
xorl %edx, %edx
divl %r11d
movb %al, 0x2(%rdi)
movb %al, 0x1(%rdi)
movb %al, (%rdi)
testl %r9d, %r9d
je 0x59c7
cmpl $0x0, 0x18(%r8)
je 0x59c2
cmpl 0x1c(%r8), %r15d
setne %al
negb %al
jmp 0x59c4
movb $-0x1, %al
movb %al, 0x3(%rdi)
incq %rbx
addq -0x8(%rsp), %rdi
cmpq %rsi, %rbx
jne 0x5951
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq