// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_PLTE
void /* PRIVATE */
png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
{
   PNG_PLTE;
   png_uint_32 i;
   png_colorp pal_ptr;
   png_byte buf[3];

   png_debug(1, "in png_write_PLTE");

   if ((
#ifdef PNG_MNG_FEATURES_SUPPORTED
        !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
#endif
        num_pal == 0) || num_pal > 256)
   {
     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
     {
        png_error(png_ptr, "Invalid number of colors in palette");
     }
     else
     {
        png_warning(png_ptr, "Invalid number of colors in palette");
        return;
     }
   }

   if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
   {
      png_warning(png_ptr,
        "Ignoring request to write a PLTE chunk in grayscale PNG");
      return;
   }

   png_ptr->num_palette = (png_uint_16)num_pal;
   png_debug1(3, "num_palette = %d", png_ptr->num_palette);

   png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
     (png_uint_32)(num_pal * 3));
#ifdef PNG_POINTER_INDEXING_SUPPORTED
   for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
   {
      buf[0] = pal_ptr->red;
      buf[1] = pal_ptr->green;
      buf[2] = pal_ptr->blue;
      png_write_chunk_data(png_ptr, buf, (png_size_t)3);
   }
#else
   /* This is a little slower but some buggy compilers need to do this
    * instead
    */
   pal_ptr=palette;
   for (i = 0; i < num_pal; i++)
   {
      buf[0] = pal_ptr[i].red;
      buf[1] = pal_ptr[i].green;
      buf[2] = pal_ptr[i].blue;
      png_write_chunk_data(png_ptr, buf, (png_size_t)3);
   }
#endif
   png_write_chunk_end(png_ptr);
   png_ptr->mode |= PNG_HAVE_PLTE;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movl 0x13a10(%rip), %eax     # 0x13f258
movl %eax, 0x1f(%rsp)
movb 0x13a0a(%rip), %al      # 0x13f25c
movb %al, 0x23(%rsp)
movq 0x30(%rsp), %rax
movl 0x408(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x12b870
cmpl $0x0, 0x24(%rsp)
je 0x12b87a
cmpl $0x100, 0x24(%rsp)      # imm = 0x100
jbe 0x12b8b6
movq 0x30(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x12b89e
movq 0x30(%rsp), %rdi
leaq 0x14e70(%rip), %rsi     # 0x140707
callq 0x113860
jmp 0x12b8b4
movq 0x30(%rsp), %rdi
leaq 0x14e5d(%rip), %rsi     # 0x140707
callq 0x113940
jmp 0x12b993
jmp 0x12b8b6
movq 0x30(%rsp), %rax
movzbl 0x24e(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x12b8e0
movq 0x30(%rsp), %rdi
leaq 0x14e55(%rip), %rsi     # 0x14072b
callq 0x113940
jmp 0x12b993
movl 0x24(%rsp), %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x240(%rax)
movq 0x30(%rsp), %rdi
leaq 0x1f(%rsp), %rsi
imull $0x3, 0x24(%rsp), %edx
callq 0x12b0a0
movl $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x24(%rsp), %eax
jae 0x12b975
movq 0x10(%rsp), %rax
movb (%rax), %al
movb %al, 0xd(%rsp)
movq 0x10(%rsp), %rax
movb 0x1(%rax), %al
movb %al, 0xe(%rsp)
movq 0x10(%rsp), %rax
movb 0x2(%rax), %al
movb %al, 0xf(%rsp)
movq 0x30(%rsp), %rdi
leaq 0xd(%rsp), %rsi
movl $0x3, %edx
callq 0x12b140
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %rax
addq $0x3, %rax
movq %rax, 0x10(%rsp)
jmp 0x12b919
movq 0x30(%rsp), %rdi
callq 0x12b1a0
movq 0x30(%rsp), %rax
movl 0x11c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x11c(%rax)
addq $0x38, %rsp
retq
nopl (%rax,%rax)