// File: drummyfish[P]flowchart/src/lodepng.cpp
// Function: rgba16ToPixel(unsigned char*, unsigned long, LodePNGColorMode const*, unsigned short, unsigned short, unsigned short, unsigned short)
static unsigned rgba16ToPixel(unsigned char* out, size_t i,
                              const LodePNGColorMode* mode,
                              unsigned short r, unsigned short g, unsigned short b, unsigned short a)
{
  if(mode->bitdepth != 16) return 85; /*must be 16 for this function*/
  if(mode->colortype == LCT_GREY)
  {
    unsigned short grey = r; /*((unsigned)r + g + b) / 3*/;
    out[i * 2 + 0] = (grey >> 8) & 255;
    out[i * 2 + 1] = grey & 255;
  }
  else if(mode->colortype == LCT_RGB)
  {
    out[i * 6 + 0] = (r >> 8) & 255;
    out[i * 6 + 1] = r & 255;
    out[i * 6 + 2] = (g >> 8) & 255;
    out[i * 6 + 3] = g & 255;
    out[i * 6 + 4] = (b >> 8) & 255;
    out[i * 6 + 5] = b & 255;
  }
  else if(mode->colortype == LCT_GREY_ALPHA)
  {
    unsigned short grey = r; /*((unsigned)r + g + b) / 3*/;
    out[i * 4 + 0] = (grey >> 8) & 255;
    out[i * 4 + 1] = grey & 255;
    out[i * 4 + 2] = (a >> 8) & 255;
    out[i * 4 + 3] = a & 255;
  }
  else if(mode->colortype == LCT_RGBA)
  {
    out[i * 8 + 0] = (r >> 8) & 255;
    out[i * 8 + 1] = r & 255;
    out[i * 8 + 2] = (g >> 8) & 255;
    out[i * 8 + 3] = g & 255;
    out[i * 8 + 4] = (b >> 8) & 255;
    out[i * 8 + 5] = b & 255;
    out[i * 8 + 6] = (a >> 8) & 255;
    out[i * 8 + 7] = a & 255;
  }

  return 0; /*no error*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %r8d, -0x48(%rbp)
movl %ecx, %eax
movl -0x48(%rbp), %ecx
movl %eax, -0x44(%rbp)
movq %rdx, %rax
movl -0x44(%rbp), %edx
movq %rax, -0x40(%rbp)
movq %rsi, %rax
movq -0x40(%rbp), %rsi
movq %rax, -0x38(%rbp)
movq %rdi, %r8
movq -0x38(%rbp), %rdi
movw %r9w, %ax
movw 0x10(%rbp), %r9w
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movw %dx, -0x22(%rbp)
movw %cx, -0x24(%rbp)
movw %ax, -0x26(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
je 0x6b13
movl $0x55, -0x4(%rbp)
jmp 0x6d8d
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x6b5f
movw -0x22(%rbp), %ax
movw %ax, -0x28(%rbp)
movzwl -0x28(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq %rcx
movb %dl, (%rax,%rcx)
movzwl -0x28(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq %rcx
movb %dl, 0x1(%rax,%rcx)
jmp 0x6d86
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x6c09
movzwl -0x22(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movzwl -0x22(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x24(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl -0x24(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, 0x3(%rax,%rcx)
movzwl -0x26(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx)
movzwl -0x26(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
imulq $0x6, -0x18(%rbp), %rcx
movb %dl, 0x5(%rax,%rcx)
jmp 0x6d84
movq -0x20(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x6c90
movw -0x22(%rbp), %ax
movw %ax, -0x2a(%rbp)
movzwl -0x2a(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x2a(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl 0x10(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl 0x10(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x2, %rcx
movb %dl, 0x3(%rax,%rcx)
jmp 0x6d82
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x6d80
movzwl -0x22(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x22(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x24(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl -0x24(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x3(%rax,%rcx)
movzwl -0x26(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x4(%rax,%rcx)
movzwl -0x26(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x5(%rax,%rcx)
movzwl 0x10(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x6(%rax,%rcx)
movzwl 0x10(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x3, %rcx
movb %dl, 0x7(%rax,%rcx)
jmp 0x6d82
jmp 0x6d84
jmp 0x6d86
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)