// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x40(%rsp), %r13
movl (%r13), %eax
xorl %ebp, %ebp
cmpq $0x6, %rax
ja 0x55fa
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
leaq 0x8cd9(%rip), %rcx      # 0xe0a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4(%r13), %ecx
cmpq $0x10, %rcx
je 0x55c8
cmpl $0x8, %ecx
jne 0x560b
movzbl (%r8,%r9), %eax
movb %al, (%r15)
movb %al, (%r14)
movb %al, (%r12)
cmpl $0x0, 0x18(%r13)
je 0x55f7
cmpl %eax, 0x1c(%r13)
je 0x55f2
jmp 0x55f7
movl 0x4(%r13), %edx
cmpq $0x8, %rdx
jne 0x54db
movzbl (%r8,%r9), %eax
jmp 0x54ed
cmpl $0x8, 0x4(%r13)
jne 0x552e
leaq (%r9,%r9,2), %rax
movb (%r8,%rax), %cl
movb %cl, (%r12)
movb 0x1(%r8,%rax), %cl
movb %cl, (%r14)
movzbl 0x2(%r8,%rax), %eax
movb %al, (%r15)
cmpl $0x0, 0x18(%r13)
je 0x55f7
movzbl (%r12), %ecx
cmpl %ecx, 0x1c(%r13)
jne 0x55f7
movzbl (%r14), %ecx
cmpl %ecx, 0x20(%r13)
jne 0x55f7
cmpl %eax, 0x24(%r13)
je 0x55f2
jmp 0x55f7
cmpl $0x8, 0x4(%r13)
jne 0x5592
movb (%r8,%r9,2), %al
movb %al, (%r15)
movb %al, (%r14)
movb %al, (%r12)
movb 0x1(%r8,%r9,2), %al
jmp 0x55c4
cmpl $0x8, 0x4(%r13)
jne 0x55a7
movb (%r8,%r9,4), %al
movb %al, (%r12)
movb 0x1(%r8,%r9,4), %al
movb %al, (%r14)
movb 0x2(%r8,%r9,4), %al
movb %al, (%r15)
movb 0x3(%r8,%r9,4), %al
jmp 0x55c4
imulq %rdx, %r9
movq %rsp, %rdi
movq %r9, (%rdi)
movq %r8, %rsi
callq 0x9eb8
movl %eax, %ecx
cmpq %rcx, 0x10(%r13)
jbe 0x5526
movq 0x8(%r13), %rcx
shll $0x2, %eax
movb (%rcx,%rax), %cl
movb %cl, (%r12)
movq 0x8(%r13), %rcx
movb 0x1(%rcx,%rax), %cl
movb %cl, (%r14)
movq 0x8(%r13), %rcx
movb 0x2(%rcx,%rax), %cl
movb %cl, (%r15)
movq 0x8(%r13), %rcx
movb 0x3(%rcx,%rax), %al
jmp 0x55c4
pushq $0x2f
popq %rbp
jmp 0x55fa
imulq $0x6, %r9, %rax
movb (%r8,%rax), %cl
movb %cl, (%r12)
movb 0x2(%r8,%rax), %cl
movb %cl, (%r14)
movzbl 0x4(%r8,%rax), %ecx
movb %cl, (%r15)
cmpl $0x0, 0x18(%r13)
je 0x55f7
movzwl (%r8,%rax), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x1c(%r13), %edx
jne 0x55f7
movzwl 0x2(%r8,%rax), %edx
rolw $0x8, %dx
movzwl %dx, %edx
cmpl 0x20(%r13), %edx
jne 0x55f7
shll $0x8, %ecx
movzbl 0x5(%r8,%rax), %eax
orl %ecx, %eax
cmpl 0x24(%r13), %eax
je 0x55f2
jmp 0x55f7
movb (%r8,%r9,4), %al
movb %al, (%r15)
movb %al, (%r14)
movb %al, (%r12)
movb 0x2(%r8,%r9,4), %al
jmp 0x55c4
movb (%r8,%r9,8), %al
movb %al, (%r12)
movb 0x2(%r8,%r9,8), %al
movb %al, (%r14)
movb 0x4(%r8,%r9,8), %al
movb %al, (%r15)
movb 0x6(%r8,%r9,8), %al
movb %al, (%rbx)
jmp 0x55fa
movb (%r8,%r9,2), %al
movb %al, (%r15)
movb %al, (%r14)
movb %al, (%r12)
cmpl $0x0, 0x18(%r13)
je 0x55f7
addq %r9, %r9
movzwl (%r8,%r9), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl 0x1c(%r13), %eax
jne 0x55f7
movb $0x0, (%rbx)
jmp 0x55fa
movb $-0x1, (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rbp
shll %cl, %ebp
notl %ebp
imulq %rcx, %r9
movq %rsp, %rdi
movq %r9, (%rdi)
movq %r8, %rsi
movq %rcx, %rdx
callq 0x9eb8
movl %eax, %ecx
imull $0xff, %eax, %eax
xorl %edx, %edx
divl %ebp
movb %al, (%r15)
movb %al, (%r14)
movb %al, (%r12)
cmpl $0x0, 0x18(%r13)
je 0x564e
cmpl 0x1c(%r13), %ecx
jne 0x564e
xorl %eax, %eax
jmp 0x5650
movb $-0x1, %al
movb %al, (%rbx)
xorl %ebp, %ebp
jmp 0x55fa