// File: /workspace/github_c_makefile_star2_O3/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 0x6044
movl %edx, %r9d
leaq 0x8575(%rip), %rdx      # 0xe184
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x4(%r8), %ecx
cmpl $0x8, %ecx
je 0x5f4e
cmpl $0x10, %ecx
jne 0x5f9c
testq %rsi, %rsi
je 0x6044
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 0x5c73
cmpl $0x0, 0x18(%r8)
je 0x5c6f
movzwl (%r10,%rcx,2), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r8), %edx
setne %dl
negb %dl
jmp 0x5c71
movb $-0x1, %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5c3f
jmp 0x6044
testq %rsi, %rsi
je 0x6044
movl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x4(%r8), %ebx
cmpq $0x8, %rbx
jne 0x5ca3
movzbl (%r10,%rcx), %r11d
jmp 0x5ce6
xorl %r11d, %r11d
testq %rbx, %rbx
je 0x5ce6
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 0x5cb1
addq %rbx, %rdx
movl %r11d, %ebx
cmpq %rbx, 0x10(%r8)
jbe 0x5d28
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 0x5d3d
movq 0x8(%r8), %rbx
movl %r11d, %r11d
movb 0x3(%rbx,%r11), %r11b
jmp 0x5d39
movb $0x0, 0x2(%rdi)
movw $0x0, (%rdi)
movb $-0x1, %r11b
testl %r9d, %r9d
je 0x5d3d
movb %r11b, 0x3(%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rsi, %rcx
jne 0x5c92
jmp 0x6044
cmpl $0x8, 0x4(%r8)
jne 0x5e51
testq %rsi, %rsi
je 0x6044
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 0x5dac
movb $-0x1, %cl
cmpl $0x0, 0x18(%r8)
je 0x5daa
cmpl %r11d, 0x1c(%r8)
jne 0x5daa
cmpl %ebx, 0x20(%r8)
jne 0x5daa
cmpl %edx, 0x24(%r8)
setne %cl
negb %cl
movb %cl, (%rdi)
addq %rax, %rdi
addq $0x3, %r10
decq %rsi
jne 0x5d6f
jmp 0x6044
cmpl $0x8, 0x4(%r8)
jne 0x5ed0
testq %rsi, %rsi
je 0x6044
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 0x5df2
movb 0x1(%r10,%rcx,2), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5dd9
jmp 0x6044
cmpl $0x8, 0x4(%r8)
jne 0x5f0a
testq %rsi, %rsi
je 0x6044
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 0x5e41
movb 0x3(%r10,%rcx,4), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5e1e
jmp 0x6044
testq %rsi, %rsi
je 0x6044
movl %eax, %eax
addq $0x3, %rdi
movb (%r10), %cl
movb %cl, -0x3(%rdi)
movb 0x2(%r10), %cl
movb %cl, -0x2(%rdi)
movzbl 0x4(%r10), %ecx
movb %cl, -0x1(%rdi)
testl %r9d, %r9d
je 0x5ebf
movb $-0x1, %dl
cmpl $0x0, 0x18(%r8)
je 0x5ebd
movzwl (%r10), %r11d
rolw $0x8, %r11w
movzwl %r11w, %r11d
cmpl 0x1c(%r8), %r11d
jne 0x5ebd
movzwl 0x2(%r10), %r11d
rolw $0x8, %r11w
movzwl %r11w, %r11d
cmpl 0x20(%r8), %r11d
jne 0x5ebd
shll $0x8, %ecx
movzbl 0x5(%r10), %edx
orl %ecx, %edx
cmpl 0x24(%r8), %edx
setne %dl
negb %dl
movb %dl, (%rdi)
addq %rax, %rdi
addq $0x6, %r10
decq %rsi
jne 0x5e60
jmp 0x6044
testq %rsi, %rsi
je 0x6044
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 0x5efa
movb 0x2(%r10,%rcx,4), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5ee1
jmp 0x6044
testq %rsi, %rsi
je 0x6044
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 0x5f3e
movb 0x6(%r10,%rcx,8), %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5f1b
jmp 0x6044
testq %rsi, %rsi
je 0x6044
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 0x5f8c
cmpl $0x0, 0x18(%r8)
je 0x5f88
movzbl (%r10,%rcx), %edx
cmpl %edx, 0x1c(%r8)
setne %dl
negb %dl
jmp 0x5f8a
movb $-0x1, %dl
movb %dl, (%rdi)
incq %rcx
addq %rax, %rdi
cmpq %rcx, %rsi
jne 0x5f5f
jmp 0x6044
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
shll %cl, %r11d
testq %rsi, %rsi
je 0x6044
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 0x6001
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 0x5fcf
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 0x6033
cmpl $0x0, 0x18(%r8)
je 0x602e
cmpl 0x1c(%r8), %r15d
setne %al
negb %al
jmp 0x6030
movb $-0x1, %al
movb %al, 0x3(%rdi)
incq %rbx
addq -0x8(%rsp), %rdi
cmpq %rsi, %rbx
jne 0x5fbd
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq