// File: tomfunkhouser[P]gaps/pkgs/png/pngset.c
// Function: png_set_tRNS
void PNGAPI
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
   png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
{
   png_debug1(1, "in %s storage function", "tRNS");

   if (png_ptr == NULL || info_ptr == NULL)
      return;

   if (trans_alpha != NULL)
   {
       /* It may not actually be necessary to set png_ptr->trans_alpha here;
        * we do it for backward compatibility with the way the png_handle_tRNS
        * function used to do the allocation.
        */

       png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);

       /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
       png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
           (png_size_t)PNG_MAX_PALETTE_LENGTH);
       if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
          png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
   }

   if (trans_color != NULL)
   {
      int sample_max = (1 << info_ptr->bit_depth);
      if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
          (int)trans_color->gray > sample_max) ||
          (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
          ((int)trans_color->red > sample_max ||
          (int)trans_color->green > sample_max ||
          (int)trans_color->blue > sample_max)))
         png_warning(png_ptr,
            "tRNS chunk has out-of-range samples for bit_depth");
      png_memcpy(&(info_ptr->trans_color), trans_color,
         png_sizeof(png_color_16));
      if (num_trans == 0)
         num_trans = 1;
   }

   info_ptr->num_trans = (png_uint_16)num_trans;
   if (num_trans != 0)
   {
      info_ptr->valid |= PNG_INFO_tRNS;
      info_ptr->free_me |= PNG_FREE_TRNS;
   }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movq %r8, 0x10(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0xfe52c
cmpq $0x0, 0x28(%rsp)
jne 0xfe531
jmp 0xfe690
cmpq $0x0, 0x20(%rsp)
je 0xfe5a1
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x2000, %edx           # imm = 0x2000
xorl %ecx, %ecx
callq 0xfba80
movq 0x30(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x1135b0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x30(%rsp), %rax
movq %rcx, 0x2d8(%rax)
cmpl $0x0, 0x1c(%rsp)
jle 0xfe59f
cmpl $0x100, 0x1c(%rsp)      # imm = 0x100
jg 0xfe59f
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
movq 0x20(%rsp), %rsi
movslq 0x1c(%rsp), %rdx
callq 0xf3d0
jmp 0xfe5a1
cmpq $0x0, 0x10(%rsp)
je 0xfe654
movq 0x28(%rsp), %rax
movzbl 0x24(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movzbl 0x25(%rax), %eax
cmpl $0x0, %eax
jne 0xfe5de
movq 0x10(%rsp), %rax
movzwl 0x8(%rax), %eax
cmpl 0xc(%rsp), %eax
jg 0xfe619
movq 0x28(%rsp), %rax
movzbl 0x25(%rax), %eax
cmpl $0x2, %eax
jne 0xfe62a
movq 0x10(%rsp), %rax
movzwl 0x2(%rax), %eax
cmpl 0xc(%rsp), %eax
jg 0xfe619
movq 0x10(%rsp), %rax
movzwl 0x4(%rax), %eax
cmpl 0xc(%rsp), %eax
jg 0xfe619
movq 0x10(%rsp), %rax
movzwl 0x6(%rax), %eax
cmpl 0xc(%rsp), %eax
jle 0xfe62a
movq 0x30(%rsp), %rdi
leaq 0x3a951(%rip), %rsi     # 0x138f76
callq 0x113940
movq 0x28(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x68(%rax)
movw 0x8(%rcx), %cx
movw %cx, 0x70(%rax)
cmpl $0x0, 0x1c(%rsp)
jne 0xfe652
movl $0x1, 0x1c(%rsp)
jmp 0xfe654
movl 0x1c(%rsp), %eax
movw %ax, %cx
movq 0x28(%rsp), %rax
movw %cx, 0x22(%rax)
cmpl $0x0, 0x1c(%rsp)
je 0xfe690
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x8(%rax)
movq 0x28(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x2000, %ecx           # imm = 0x2000
movl %ecx, 0xe4(%rax)
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)