// File: drummyfish[P]flowchart/src/lodepng.cpp
// Function: getPixelColorRGBA8(unsigned char*, unsigned char*, unsigned char*, unsigned char*, unsigned char const*, unsigned long, LodePNGColorMode const*)
static unsigned 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) return 47; /*index out of palette*/
    *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];
    }
  }

  return 0; /*no error*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x6f2c
movq 0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x6e27
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x6e1b
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movq 0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x6e1b
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x6e22
movq -0x28(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x6f27
movq 0x10(%rbp), %rax
cmpl $0x10, 0x4(%rax)
jne 0x6e9d
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x6e91
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rdx
shlq %rdx
movzbl 0x1(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x6e91
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x6e98
movq -0x28(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x6f25
movq 0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rsi
movq 0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq -0x48(%rbp), %rdi
callq 0x10710
movl %eax, -0x4c(%rbp)
imull $0xff, -0x4c(%rbp), %eax
xorl %edx, %edx
divl -0x3c(%rbp)
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x6f1c
movl -0x4c(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x6f1c
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x6f23
movq -0x28(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x6f25
jmp 0x6f27
jmp 0x72e1
movq 0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x70a8
movq 0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x6fce
movq -0x30(%rbp), %rax
imulq $0x3, -0x38(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
imulq $0x3, -0x38(%rbp), %rcx
movb 0x1(%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
imulq $0x3, -0x38(%rbp), %rcx
movb 0x2(%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x6fc2
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movq 0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x6fc2
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movq 0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x6fc2
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movq 0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jne 0x6fc2
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x6fc9
movq -0x28(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x70a3
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movb 0x2(%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movb 0x4(%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x709a
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
imulq $0x6, -0x38(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x709a
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movzbl 0x2(%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
imulq $0x6, -0x38(%rbp), %rdx
movzbl 0x3(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x709a
movq -0x30(%rbp), %rax
imulq $0x6, -0x38(%rbp), %rcx
movzbl 0x4(%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
imulq $0x6, -0x38(%rbp), %rdx
movzbl 0x5(%rcx,%rdx), %ecx
addl %ecx, %eax
movq 0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jne 0x709a
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x70a1
movq -0x28(%rbp), %rax
movb $-0x1, (%rax)
jmp 0x70a3
jmp 0x72df
movq 0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x718a
movq 0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x70d0
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x50(%rbp)
jmp 0x70fc
movq -0x38(%rbp), %rax
movq 0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rsi
movq 0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
leaq -0x58(%rbp), %rdi
callq 0x10710
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x7115
movl $0x2f, -0x4(%rbp)
jmp 0x72e8
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x50(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x50(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x50(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x50(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
jmp 0x72dd
movq 0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x7210
movq 0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x71d4
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
movb (%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
movb 0x1(%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
jmp 0x720b
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb (%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb 0x2(%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
jmp 0x72db
movq 0x10(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x72d9
movq 0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x7280
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb (%rax,%rcx), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb 0x1(%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb 0x2(%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x2, %rcx
movb 0x3(%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
jmp 0x72d7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x3, %rcx
movb (%rax,%rcx), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x3, %rcx
movb 0x2(%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x3, %rcx
movb 0x4(%rax,%rcx), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x3, %rcx
movb 0x6(%rax,%rcx), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
jmp 0x72d9
jmp 0x72db
jmp 0x72dd
jmp 0x72df
jmp 0x72e1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)