// File: /workspace/github_cpp_makefile_star2_O3/phillip-h[P]fractal-gen/lodepng.cpp
// Function: getPixelColorRGBA8(unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char const*, unsigned long, LodePNGColorMode const*)
static void getPixelColorRGBA8(unsigned char* r, unsigned char* g,
                               unsigned char* b, unsigned char* a,
                               const unsigned char* in, size_t i,
                               const LodePNGColorMode* mode)
{
  if(mode->colortype == LCT_GREY)
  {
    if(mode->bitdepth == 8)
    {
      *r = *g = *b = in[i];
      if(mode->key_defined && *r == mode->key_r) *a = 0;
      else *a = 255;
    }
    else if(mode->bitdepth == 16)
    {
      *r = *g = *b = in[i * 2 + 0];
      if(mode->key_defined && 256U * in[i * 2 + 0] + in[i * 2 + 1] == mode->key_r) *a = 0;
      else *a = 255;
    }
    else
    {
      unsigned highest = ((1U << mode->bitdepth) - 1U); /*highest possible value for this bit depth*/
      size_t j = i * mode->bitdepth;
      unsigned value = readBitsFromReversedStream(&j, in, mode->bitdepth);
      *r = *g = *b = (value * 255) / highest;
      if(mode->key_defined && value == mode->key_r) *a = 0;
      else *a = 255;
    }
  }
  else if(mode->colortype == LCT_RGB)
  {
    if(mode->bitdepth == 8)
    {
      *r = in[i * 3 + 0]; *g = in[i * 3 + 1]; *b = in[i * 3 + 2];
      if(mode->key_defined && *r == mode->key_r && *g == mode->key_g && *b == mode->key_b) *a = 0;
      else *a = 255;
    }
    else
    {
      *r = in[i * 6 + 0];
      *g = in[i * 6 + 2];
      *b = in[i * 6 + 4];
      if(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) *a = 0;
      else *a = 255;
    }
  }
  else if(mode->colortype == LCT_PALETTE)
  {
    unsigned index;
    if(mode->bitdepth == 8) index = in[i];
    else
    {
      size_t j = i * mode->bitdepth;
      index = readBitsFromReversedStream(&j, in, mode->bitdepth);
    }

    if(index >= mode->palettesize)
    {
      /*This is an error according to the PNG spec, but common PNG decoders make it black instead.
      Done here too, slightly faster due to no error handling needed.*/
      *r = *g = *b = 0;
      *a = 255;
    }
    else
    {
      *r = mode->palette[index * 4 + 0];
      *g = mode->palette[index * 4 + 1];
      *b = mode->palette[index * 4 + 2];
      *a = mode->palette[index * 4 + 3];
    }
  }
  else if(mode->colortype == LCT_GREY_ALPHA)
  {
    if(mode->bitdepth == 8)
    {
      *r = *g = *b = in[i * 2 + 0];
      *a = in[i * 2 + 1];
    }
    else
    {
      *r = *g = *b = in[i * 4 + 0];
      *a = in[i * 4 + 2];
    }
  }
  else if(mode->colortype == LCT_RGBA)
  {
    if(mode->bitdepth == 8)
    {
      *r = in[i * 4 + 0];
      *g = in[i * 4 + 1];
      *b = in[i * 4 + 2];
      *a = in[i * 4 + 3];
    }
    else
    {
      *r = in[i * 8 + 0];
      *g = in[i * 8 + 2];
      *b = in[i * 8 + 4];
      *a = in[i * 8 + 6];
    }
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq 0x20(%rsp), %r11
movl (%r11), %eax
cmpq $0x6, %rax
ja 0x8d9a
leaq 0x8af4(%rip), %rbx      # 0x115f4
movq %rdx, %r10
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movl 0x4(%r11), %eax
cmpq $0x10, %rax
je 0x8ce2
cmpl $0x8, %eax
jne 0x8d16
movzbl (%r8,%r9), %eax
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%r11)
je 0x8d96
cmpl %eax, 0x1c(%r11)
jne 0x8d96
jmp 0x8dc0
movl 0x4(%r11), %edx
cmpq $0x8, %rdx
jne 0x8c04
movzbl (%r8,%r9), %eax
jmp 0x8d5a
cmpl $0x8, 0x4(%r11)
jne 0x8c41
leaq (%r9,%r9,2), %rax
movb (%r8,%rax), %dl
movb %dl, (%rdi)
movb 0x1(%r8,%rax), %dl
movb %dl, (%rsi)
movzbl 0x2(%r8,%rax), %eax
movb %al, (%r10)
cmpl $0x0, 0x18(%r11)
je 0x8d96
movzbl (%rdi), %edx
cmpl %edx, 0x1c(%r11)
jne 0x8d96
movzbl (%rsi), %edx
cmpl %edx, 0x20(%r11)
jne 0x8d96
cmpl %eax, 0x24(%r11)
jne 0x8d96
jmp 0x8dc0
cmpl $0x8, 0x4(%r11)
jne 0x8cae
movb (%r8,%r9,2), %al
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
movb 0x1(%r8,%r9,2), %al
jmp 0x8d98
cmpl $0x8, 0x4(%r11)
jne 0x8cc3
movb (%r8,%r9,4), %al
movb %al, (%rdi)
movb 0x1(%r8,%r9,4), %al
movb %al, (%rsi)
movb 0x2(%r8,%r9,4), %al
movb %al, (%r10)
movb 0x3(%r8,%r9,4), %al
jmp 0x8d98
testq %rdx, %rdx
je 0x8d58
imulq %rdx, %r9
xorl %eax, %eax
movq %r9, %rbx
shrq $0x3, %rbx
movl %r9d, %ebp
incq %r9
movzbl (%r8,%rbx), %ebx
notb %bpl
andb $0x7, %bpl
shrxl %ebp, %ebx, %ebx
andl $0x1, %ebx
decq %rdx
leal (%rbx,%rax,2), %eax
jne 0x8c13
jmp 0x8d5a
addq %r9, %r9
leaq (%r9,%r9,2), %rax
movb (%r8,%rax), %dl
movb %dl, (%rdi)
movb 0x2(%r8,%rax), %dl
movb %dl, (%rsi)
movzbl 0x4(%r8,%rax), %edx
movb %dl, (%r10)
cmpl $0x0, 0x18(%r11)
je 0x8d96
movzwl (%r8,%rax), %esi
rolw $0x8, %si
movzwl %si, %esi
cmpl 0x1c(%r11), %esi
jne 0x8d96
movbew 0x2(%r8,%rax), %si
movzwl %si, %esi
cmpl 0x20(%r11), %esi
jne 0x8d96
movzbl 0x5(%r8,%rax), %eax
shll $0x8, %edx
orl %edx, %eax
cmpl 0x24(%r11), %eax
jne 0x8d96
jmp 0x8dc0
movb (%r8,%r9,4), %al
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
movb 0x2(%r8,%r9,4), %al
jmp 0x8d98
movb (%r8,%r9,8), %al
movb %al, (%rdi)
movb 0x2(%r8,%r9,8), %al
movb %al, (%rsi)
movb 0x4(%r8,%r9,8), %al
movb %al, (%r10)
movb 0x6(%r8,%r9,8), %al
jmp 0x8d98
movb (%r8,%r9,2), %al
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%r11)
je 0x8d96
addq %r9, %r9
movzwl (%r8,%r9), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl 0x1c(%r11), %eax
jne 0x8d96
jmp 0x8dc0
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shlxl %eax, %edx, %ebp
notl %ebp
testq %rax, %rax
je 0x8d9f
imulq %rax, %r9
xorl %ebx, %ebx
movq %r9, %rdx
shrq $0x3, %rdx
movl %r9d, %r14d
incq %r9
movzbl (%r8,%rdx), %edx
notb %r14b
andb $0x7, %r14b
shrxl %r14d, %edx, %edx
andl $0x1, %edx
decq %rax
leal (%rdx,%rbx,2), %ebx
jne 0x8d2d
jmp 0x8da1
xorl %eax, %eax
movl %eax, %edx
cmpq %rdx, 0x10(%r11)
jbe 0x8d8d
movq 0x8(%r11), %rdx
shll $0x2, %eax
movb (%rdx,%rax), %dl
movb %dl, (%rdi)
movq 0x8(%r11), %rdx
movb 0x1(%rdx,%rax), %dl
movb %dl, (%rsi)
movq 0x8(%r11), %rdx
movb 0x2(%rdx,%rax), %dl
movb %dl, (%r10)
movq 0x8(%r11), %rdx
movb 0x3(%rdx,%rax), %al
jmp 0x8d98
xorl %eax, %eax
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
movb $-0x1, %al
movb %al, (%rcx)
popq %rbx
popq %r14
popq %rbp
retq
xorl %ebx, %ebx
movl %ebx, %eax
shll $0x8, %eax
xorl %edx, %edx
subl %ebx, %eax
divl %ebp
movb %al, (%r10)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%r11)
je 0x8d96
cmpl 0x1c(%r11), %ebx
jne 0x8d96
xorl %eax, %eax
jmp 0x8d98