// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_tRNS
void /* PRIVATE */
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_byte readbuf[PNG_MAX_PALETTE_LENGTH];

   png_debug(1, "in png_handle_tRNS");

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before tRNS");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid tRNS after IDAT");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
   {
      png_warning(png_ptr, "Duplicate tRNS chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

   if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
   {
      png_byte buf[2];

      if (length != 2)
      {
         png_warning(png_ptr, "Incorrect tRNS chunk length");
         png_crc_finish(png_ptr, length);
         return;
      }

      png_crc_read(png_ptr, buf, 2);
      png_ptr->num_trans = 1;
      png_ptr->trans_color.gray = png_get_uint_16(buf);
   }
   else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
   {
      png_byte buf[6];

      if (length != 6)
      {
         png_warning(png_ptr, "Incorrect tRNS chunk length");
         png_crc_finish(png_ptr, length);
         return;
      }
      png_crc_read(png_ptr, buf, (png_size_t)length);
      png_ptr->num_trans = 1;
      png_ptr->trans_color.red = png_get_uint_16(buf);
      png_ptr->trans_color.green = png_get_uint_16(buf + 2);
      png_ptr->trans_color.blue = png_get_uint_16(buf + 4);
   }
   else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
   {
      if (!(png_ptr->mode & PNG_HAVE_PLTE))
      {
         /* Should be an error, but we can cope with it. */
         png_warning(png_ptr, "Missing PLTE before tRNS");
      }
      if (length > (png_uint_32)png_ptr->num_palette ||
          length > PNG_MAX_PALETTE_LENGTH)
      {
         png_warning(png_ptr, "Incorrect tRNS chunk length");
         png_crc_finish(png_ptr, length);
         return;
      }
      if (length == 0)
      {
         png_warning(png_ptr, "Zero length tRNS chunk");
         png_crc_finish(png_ptr, length);
         return;
      }
      png_crc_read(png_ptr, readbuf, (png_size_t)length);
      png_ptr->num_trans = (png_uint_16)length;
   }
   else
   {
      png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
      png_crc_finish(png_ptr, length);
      return;
   }

   if (png_crc_finish(png_ptr, 0))
   {
      png_ptr->num_trans = 0;
      return;
   }

   png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
      &(png_ptr->trans_color));
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movl %edx, 0x114(%rsp)
movq 0x120(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x12518d
movq 0x120(%rsp), %rdi
leaq 0x1a698(%rip), %rsi     # 0x13f81b
callq 0x113860
jmp 0x12521f
movq 0x120(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1251d0
movq 0x120(%rsp), %rdi
leaq 0x1a682(%rip), %rsi     # 0x13f834
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
cmpq $0x0, 0x118(%rsp)
je 0x12521b
movq 0x118(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x12521b
movq 0x120(%rsp), %rdi
leaq 0x1a64f(%rip), %rsi     # 0x13f84c
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
jmp 0x12521d
jmp 0x12521f
movq 0x120(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x0, %eax
jne 0x1252bc
cmpl $0x2, 0x114(%rsp)
je 0x12526e
movq 0x120(%rsp), %rdi
leaq 0x1a611(%rip), %rsi     # 0x13f861
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
movq 0x120(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x2, %edx
callq 0x122b40
movq 0x120(%rsp), %rax
movw $0x1, 0x242(%rax)
movzbl 0xe(%rsp), %eax
shll $0x8, %eax
movzbl 0xf(%rsp), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x120(%rsp), %rax
movw %cx, 0x2e8(%rax)
jmp 0x1254d0
movq 0x120(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x2, %eax
jne 0x12539f
cmpl $0x6, 0x114(%rsp)
je 0x12530b
movq 0x120(%rsp), %rdi
leaq 0x1a574(%rip), %rsi     # 0x13f861
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
movq 0x120(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl 0x114(%rsp), %eax
movl %eax, %edx
callq 0x122b40
movq 0x120(%rsp), %rax
movw $0x1, 0x242(%rax)
movzbl 0x8(%rsp), %eax
shll $0x8, %eax
movzbl 0x9(%rsp), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x120(%rsp), %rax
movw %cx, 0x2e2(%rax)
movzbl 0xa(%rsp), %eax
shll $0x8, %eax
movzbl 0xb(%rsp), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x120(%rsp), %rax
movw %cx, 0x2e4(%rax)
movzbl 0xc(%rsp), %eax
shll $0x8, %eax
movzbl 0xd(%rsp), %ecx
addl %ecx, %eax
movw %ax, %cx
movq 0x120(%rsp), %rax
movw %cx, 0x2e6(%rax)
jmp 0x1254ce
movq 0x120(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x1254a2
movq 0x120(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x1253e1
movq 0x120(%rsp), %rdi
leaq 0x1a4a1(%rip), %rsi     # 0x13f87d
callq 0x113940
movl 0x114(%rsp), %eax
movq 0x120(%rsp), %rcx
movzwl 0x240(%rcx), %ecx
cmpl %ecx, %eax
ja 0x125408
cmpl $0x100, 0x114(%rsp) # imm = 0x100
jbe 0x125435
movq 0x120(%rsp), %rdi
leaq 0x1a44a(%rip), %rsi     # 0x13f861
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
cmpl $0x0, 0x114(%rsp)
jne 0x12546c
movq 0x120(%rsp), %rdi
leaq 0x1a448(%rip), %rsi     # 0x13f896
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
movq 0x120(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl 0x114(%rsp), %eax
movl %eax, %edx
callq 0x122b40
movl 0x114(%rsp), %eax
movw %ax, %cx
movq 0x120(%rsp), %rax
movw %cx, 0x242(%rax)
jmp 0x1254cc
movq 0x120(%rsp), %rdi
leaq 0x1a3fc(%rip), %rsi     # 0x13f8ad
callq 0x113940
movq 0x120(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x122b90
jmp 0x12552f
jmp 0x1254ce
jmp 0x1254d0
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x1254f7
movq 0x120(%rsp), %rax
movw $0x0, 0x242(%rax)
jmp 0x12552f
movq 0x120(%rsp), %rdi
movq 0x118(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq 0x120(%rsp), %rax
movzwl 0x242(%rax), %ecx
movq 0x120(%rsp), %r8
addq $0x2e0, %r8             # imm = 0x2E0
callq 0xfe500
addq $0x128, %rsp            # imm = 0x128
retq
nopw (%rax,%rax)