// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_bKGD
void /* PRIVATE */
png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
{
   PNG_bKGD;
   png_byte buf[6];

   png_debug(1, "in png_write_bKGD");

   if (color_type == PNG_COLOR_TYPE_PALETTE)
   {
      if (
#ifdef PNG_MNG_FEATURES_SUPPORTED
          (png_ptr->num_palette ||
          (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
#endif
         back->index >= png_ptr->num_palette)
      {
         png_warning(png_ptr, "Invalid background palette index");
         return;
      }
      buf[0] = back->index;
      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
   }
   else if (color_type & PNG_COLOR_MASK_COLOR)
   {
      png_save_uint_16(buf, back->red);
      png_save_uint_16(buf + 2, back->green);
      png_save_uint_16(buf + 4, back->blue);
      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
      {
         png_warning(png_ptr,
           "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
         return;
      }
      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
   }
   else
   {
      if (back->gray >= (1 << png_ptr->bit_depth))
      {
         png_warning(png_ptr,
           "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
         return;
      }
      png_save_uint_16(buf, back->gray);
      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
   }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movl 0x12664(%rip), %eax     # 0x13f91c
movl %eax, 0xf(%rsp)
movb 0x1265e(%rip), %al      # 0x13f920
movb %al, 0x13(%rsp)
cmpl $0x3, 0x14(%rsp)
jne 0x12d348
movq 0x20(%rsp), %rax
movzwl 0x240(%rax), %eax
cmpl $0x0, %eax
jne 0x12d2f1
movq 0x20(%rsp), %rax
movl 0x408(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x12d31f
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movq 0x20(%rsp), %rcx
movzwl 0x240(%rcx), %ecx
cmpl %ecx, %eax
jl 0x12d31f
movq 0x20(%rsp), %rdi
leaq 0x13655(%rip), %rsi     # 0x14096a
callq 0x113940
jmp 0x12d453
movq 0x18(%rsp), %rax
movb (%rax), %al
movb %al, 0x9(%rsp)
movq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rsi
leaq 0x9(%rsp), %rdx
movl $0x1, %ecx
callq 0x12b040
jmp 0x12d453
movl 0x14(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12d3f0
leaq 0x9(%rsp), %rdi
movq 0x18(%rsp), %rax
movzwl 0x2(%rax), %esi
callq 0x12af70
leaq 0x9(%rsp), %rdi
addq $0x2, %rdi
movq 0x18(%rsp), %rax
movzwl 0x4(%rax), %esi
callq 0x12af70
leaq 0x9(%rsp), %rdi
addq $0x4, %rdi
movq 0x18(%rsp), %rax
movzwl 0x6(%rax), %esi
callq 0x12af70
movq 0x20(%rsp), %rax
movzbl 0x24f(%rax), %eax
cmpl $0x8, %eax
jne 0x12d3d5
movzbl 0x9(%rsp), %eax
movzbl 0xb(%rsp), %ecx
orl %ecx, %eax
movzbl 0xd(%rsp), %ecx
orl %ecx, %eax
cmpl $0x0, %eax
je 0x12d3d5
movq 0x20(%rsp), %rdi
leaq 0x135bd(%rip), %rsi     # 0x14098b
callq 0x113940
jmp 0x12d453
movq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rsi
leaq 0x9(%rsp), %rdx
movl $0x6, %ecx
callq 0x12b040
jmp 0x12d451
movq 0x18(%rsp), %rax
movzwl 0x8(%rax), %eax
movq 0x20(%rsp), %rcx
movzbl 0x24f(%rcx), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jl 0x12d425
movq 0x20(%rsp), %rdi
leaq 0x135ad(%rip), %rsi     # 0x1409cb
callq 0x113940
jmp 0x12d453
leaq 0x9(%rsp), %rdi
movq 0x18(%rsp), %rax
movzwl 0x8(%rax), %esi
callq 0x12af70
movq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rsi
leaq 0x9(%rsp), %rdx
movl $0x2, %ecx
callq 0x12b040
jmp 0x12d453
addq $0x28, %rsp
retq
nopl (%rax,%rax)