// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
movq %rcx, %r10
movq 0x30(%rsp), %rbx
movl (%rbx), %ecx
xorl %eax, %eax
cmpq $0x6, %rcx
ja 0x6e42
movq %rdx, %r11
leaq 0xb523(%rip), %rdx      # 0x12084
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x4(%rbx), %eax
cmpq $0x10, %rax
je 0x6d4a
cmpl $0x8, %eax
jne 0x6d7c
movzbl (%r8,%r9), %eax
movb %al, (%r11)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%rbx)
je 0x6e3b
cmpl %eax, 0x1c(%rbx)
je 0x6e37
jmp 0x6e3b
movl 0x4(%rbx), %eax
cmpq $0x8, %rax
jne 0x6c57
movzbl (%r8,%r9), %edx
jmp 0x6ddc
cmpl $0x8, 0x4(%rbx)
jne 0x6caa
leaq (%r9,%r9,2), %rax
movb (%r8,%rax), %cl
movb %cl, (%rdi)
movb 0x1(%r8,%rax), %cl
movb %cl, (%rsi)
movzbl 0x2(%r8,%rax), %eax
movb %al, (%r11)
cmpl $0x0, 0x18(%rbx)
je 0x6e3b
movzbl (%rdi), %ecx
cmpl %ecx, 0x1c(%rbx)
jne 0x6e3b
movzbl (%rsi), %ecx
cmpl %ecx, 0x20(%rbx)
jne 0x6e3b
cmpl %eax, 0x24(%rbx)
je 0x6e37
jmp 0x6e3b
cmpl $0x8, 0x4(%rbx)
jne 0x6d16
movb (%r8,%r9,2), %al
movb %al, (%r11)
movb %al, (%rsi)
movb %al, (%rdi)
movb 0x1(%r8,%r9,2), %al
jmp 0x6e3d
cmpl $0x8, 0x4(%rbx)
jne 0x6d2b
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, (%r11)
movb 0x3(%r8,%r9,4), %al
jmp 0x6e3d
testq %rax, %rax
je 0x6dda
imulq %rax, %r9
xorl %edx, %edx
movq %rax, %r14
movq %r9, %rcx
shrq $0x3, %rcx
movzbl (%r8,%rcx), %ecx
movl %r9d, %ebp
notb %bpl
movzbl %bpl, %ebp
andl $0x7, %ebp
xorl %r15d, %r15d
btl %ebp, %ecx
setb %r15b
incq %r9
leaq -0x1(%r14), %rcx
shll %cl, %r15d
addl %r15d, %edx
addq $-0x2, %r14
cmpq %rax, %r14
movq %rcx, %r14
jb 0x6c69
jmp 0x6ddc
addq %r9, %r9
leaq (%r9,%r9,2), %rax
movb (%r8,%rax), %cl
movb %cl, (%rdi)
movb 0x2(%r8,%rax), %cl
movb %cl, (%rsi)
movb 0x4(%r8,%rax), %cl
movb %cl, (%r11)
cmpl $0x0, 0x18(%rbx)
je 0x6e3b
movzwl (%r8,%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
cmpl 0x1c(%rbx), %ecx
jne 0x6e3b
movzwl 0x2(%r8,%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
cmpl 0x20(%rbx), %ecx
jne 0x6e3b
movzwl 0x4(%r8,%rax), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl 0x24(%rbx), %eax
je 0x6e37
jmp 0x6e3b
movb (%r8,%r9,4), %al
movb %al, (%r11)
movb %al, (%rsi)
movb %al, (%rdi)
movb 0x2(%r8,%r9,4), %al
jmp 0x6e3d
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, (%r11)
movb 0x6(%r8,%r9,8), %al
jmp 0x6e3d
movb (%r8,%r9,2), %al
movb %al, (%r11)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%rbx)
je 0x6e3b
addq %r9, %r9
movzwl (%r8,%r9), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl 0x1c(%rbx), %eax
je 0x6e37
jmp 0x6e3b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %eax, %ecx
shll %cl, %ebp
notl %ebp
testq %rax, %rax
je 0x6e14
imulq %rax, %r9
xorl %r14d, %r14d
movq %rax, %rdx
movq %r9, %rcx
shrq $0x3, %rcx
movzbl (%r8,%rcx), %ecx
movl %r9d, %r15d
notb %r15b
movzbl %r15b, %r15d
andl $0x7, %r15d
xorl %r12d, %r12d
btl %r15d, %ecx
setb %r12b
incq %r9
leaq -0x1(%rdx), %rcx
shll %cl, %r12d
addl %r12d, %r14d
addq $-0x2, %rdx
cmpq %rax, %rdx
movq %rcx, %rdx
jb 0x6d9a
jmp 0x6e17
xorl %edx, %edx
movl %edx, %ecx
movl $0x2f, %eax
cmpq %rcx, 0x10(%rbx)
jbe 0x6e42
movq 0x8(%rbx), %rax
shll $0x2, %edx
movb (%rax,%rdx), %al
movb %al, (%rdi)
movq 0x8(%rbx), %rax
movb 0x1(%rax,%rdx), %al
movb %al, (%rsi)
movq 0x8(%rbx), %rax
movb 0x2(%rax,%rdx), %al
movb %al, (%r11)
movq 0x8(%rbx), %rax
movb 0x3(%rax,%rdx), %al
jmp 0x6e3d
xorl %r14d, %r14d
movl %r14d, %eax
shll $0x8, %eax
subl %r14d, %eax
xorl %edx, %edx
divl %ebp
movb %al, (%r11)
movb %al, (%rsi)
movb %al, (%rdi)
cmpl $0x0, 0x18(%rbx)
je 0x6e3b
cmpl 0x1c(%rbx), %r14d
jne 0x6e3b
xorl %eax, %eax
jmp 0x6e3d
movb $-0x1, %al
movb %al, (%r10)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq