// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: rgba16ToPixel(unsigned char*, unsigned long, LodePNGColorMode const*, unsigned short, unsigned short, unsigned short, unsigned short)
static void rgba16ToPixel(unsigned char* out, size_t i,
                         const LodePNGColorMode* mode,
                         unsigned short r, unsigned short g, unsigned short b, unsigned short a) {
  if(mode->colortype == LCT_GREY) {
    unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/
    out[i * 2 + 0] = (gray >> 8) & 255;
    out[i * 2 + 1] = gray & 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 gray = r; /*((unsigned)r + g + b) / 3u;*/
    out[i * 4 + 0] = (gray >> 8) & 255;
    out[i * 4 + 1] = gray & 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;
  }
}

// Assembly:
movl %r8d, -0x40(%rsp)
movl %ecx, %eax
movl -0x40(%rsp), %ecx
movl %eax, -0x3c(%rsp)
movq %rdx, %rax
movl -0x3c(%rsp), %edx
movq %rax, -0x38(%rsp)
movq %rsi, %rax
movq -0x38(%rsp), %rsi
movq %rax, -0x30(%rsp)
movq %rdi, %r8
movq -0x30(%rsp), %rdi
movw %r9w, %ax
movw 0x8(%rsp), %r9w
movq %r8, -0x8(%rsp)
movq %rdi, -0x10(%rsp)
movq %rsi, -0x18(%rsp)
movw %dx, -0x1a(%rsp)
movw %cx, -0x1c(%rsp)
movw %ax, -0x1e(%rsp)
movq -0x18(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x14184d
movw -0x1a(%rsp), %ax
movw %ax, -0x20(%rsp)
movzwl -0x20(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq %rcx
movb %dl, (%rax,%rcx)
movzwl -0x20(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq %rcx
movb %dl, 0x1(%rax,%rcx)
jmp 0x141ab3
movq -0x18(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x14190a
movzwl -0x1a(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, (%rax,%rcx)
movzwl -0x1a(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x1c(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl -0x1c(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, 0x3(%rax,%rcx)
movzwl -0x1e(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, 0x4(%rax,%rcx)
movzwl -0x1e(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
imulq $0x6, -0x10(%rsp), %rcx
movb %dl, 0x5(%rax,%rcx)
jmp 0x141ab1
movq -0x18(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x1419a4
movw -0x1a(%rsp), %ax
movw %ax, -0x22(%rsp)
movzwl -0x22(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x2, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x22(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x2, %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl 0x8(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x2, %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl 0x8(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x2, %rcx
movb %dl, 0x3(%rax,%rcx)
jmp 0x141aaf
movq -0x18(%rsp), %rax
cmpl $0x6, (%rax)
jne 0x141aad
movzwl -0x1a(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x1a(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x1c(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x2(%rax,%rcx)
movzwl -0x1c(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x3(%rax,%rcx)
movzwl -0x1e(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x4(%rax,%rcx)
movzwl -0x1e(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x5(%rax,%rcx)
movzwl 0x8(%rsp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x6(%rax,%rcx)
movzwl 0x8(%rsp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
shlq $0x3, %rcx
movb %dl, 0x7(%rax,%rcx)
jmp 0x141aaf
jmp 0x141ab1
jmp 0x141ab3
retq
nopw %cs:(%rax,%rax)