// File: 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:
subq $0x58, %rsp
movq 0x60(%rsp), %rax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq 0x60(%rsp), %rax
cmpl $0x0, (%rax)
jne 0xb59c
movq 0x60(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0xb476
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xb469
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
movq 0x60(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xb469
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
jmp 0xb471
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb597
movq 0x60(%rsp), %rax
cmpl $0x10, 0x4(%rax)
jne 0xb4fa
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xb4ed
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
shlq %rdx
movzbl 0x1(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x60(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xb4ed
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
jmp 0xb4f5
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb595
movq 0x60(%rsp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
movq 0x60(%rsp), %rcx
movl 0x4(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rsi
movq 0x60(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq 0x18(%rsp), %rdi
callq 0x15f70
movl %eax, 0x14(%rsp)
imull $0xff, 0x14(%rsp), %eax
xorl %edx, %edx
divl 0x24(%rsp)
movb %al, %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xb58b
movl 0x14(%rsp), %eax
movq 0x60(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xb58b
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
jmp 0xb593
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb595
jmp 0xb597
jmp 0xb9e0
movq 0x60(%rsp), %rax
cmpl $0x2, (%rax)
jne 0xb747
movq 0x60(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0xb652
movq 0x30(%rsp), %rax
imulq $0x3, 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
imulq $0x3, 0x28(%rsp), %rcx
movb 0x1(%rax,%rcx), %cl
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
imulq $0x3, 0x28(%rsp), %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xb645
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
movq 0x60(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xb645
movq 0x48(%rsp), %rax
movzbl (%rax), %eax
movq 0x60(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jne 0xb645
movq 0x40(%rsp), %rax
movzbl (%rax), %eax
movq 0x60(%rsp), %rcx
cmpl 0x24(%rcx), %eax
jne 0xb645
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
jmp 0xb64d
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb742
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movb 0x4(%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xb738
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq 0x30(%rsp), %rcx
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x60(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0xb738
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl 0x2(%rax,%rcx), %eax
shll $0x8, %eax
movq 0x30(%rsp), %rcx
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x3(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x60(%rsp), %rcx
cmpl 0x20(%rcx), %eax
jne 0xb738
movq 0x30(%rsp), %rax
imulq $0x6, 0x28(%rsp), %rcx
movzbl 0x4(%rax,%rcx), %eax
shll $0x8, %eax
movq 0x30(%rsp), %rcx
imulq $0x6, 0x28(%rsp), %rdx
movzbl 0x5(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x60(%rsp), %rcx
cmpl 0x24(%rcx), %eax
jne 0xb738
movq 0x38(%rsp), %rax
movb $0x0, (%rax)
jmp 0xb740
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb742
jmp 0xb9de
movq 0x60(%rsp), %rax
cmpl $0x3, (%rax)
jne 0xb859
movq 0x60(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0xb774
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x10(%rsp)
jmp 0xb7a7
movq 0x28(%rsp), %rax
movq 0x60(%rsp), %rcx
movl 0x4(%rcx), %ecx
imulq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rsi
movq 0x60(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x15f70
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x60(%rsp), %rcx
cmpq 0x10(%rcx), %rax
jb 0xb7d8
movq 0x40(%rsp), %rax
movb $0x0, (%rax)
movq 0x48(%rsp), %rax
movb $0x0, (%rax)
movq 0x50(%rsp), %rax
movb $0x0, (%rax)
movq 0x38(%rsp), %rax
movb $-0x1, (%rax)
jmp 0xb854
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq 0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0xb9dc
movq 0x60(%rsp), %rax
cmpl $0x4, (%rax)
jne 0xb8f5
movq 0x60(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0xb8b1
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq %rcx
movb 0x1(%rax,%rcx), %cl
movq 0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0xb8f0
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb (%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0xb9da
movq 0x60(%rsp), %rax
cmpl $0x6, (%rax)
jne 0xb9d8
movq 0x60(%rsp), %rax
cmpl $0x8, 0x4(%rax)
jne 0xb973
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb 0x1(%rax,%rcx), %cl
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
movb 0x3(%rax,%rcx), %cl
movq 0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0xb9d6
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb (%rax,%rcx), %cl
movq 0x50(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x2(%rax,%rcx), %cl
movq 0x48(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x4(%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movb %cl, (%rax)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x3, %rcx
movb 0x6(%rax,%rcx), %cl
movq 0x38(%rsp), %rax
movb %cl, (%rax)
jmp 0xb9d8
jmp 0xb9da
jmp 0xb9dc
jmp 0xb9de
jmp 0xb9e0
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)