// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x11c(%rdi), %eax
testb $0x1, %al
jne 0x8cb86
leaq 0x17091(%rip), %rsi     # 0xa3bbb
movq %rbx, %rdi
callq 0x849c0
movzbl 0x24e(%rbx), %eax
cmpl $0x3, %eax
je 0x8cc1c
cmpl $0x2, %eax
je 0x8cbae
testl %eax, %eax
jne 0x8cc7b
cmpl $0x2, %ebp
jne 0x8cbfe
movq %rsp, %r15
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8b6d7
movw $0x1, 0x242(%rbx)
movzwl (%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2e8(%rbx)
jmp 0x8cc63
testb $0x4, %al
jne 0x8cba2
testq %r14, %r14
je 0x8cb32
testb $0x10, 0x8(%r14)
je 0x8cb32
leaq 0x1704f(%rip), %rsi     # 0xa3bec
jmp 0x8cc8b
leaq 0x1702b(%rip), %rsi     # 0xa3bd4
jmp 0x8cc8b
cmpl $0x6, %ebp
jne 0x8cbfe
movq %rsp, %r15
pushq $0x6
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8b6d7
movw $0x1, 0x242(%rbx)
movzwl (%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2e2(%rbx)
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2e4(%rbx)
movzwl 0x4(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2e6(%rbx)
jmp 0x8cc63
leaq 0x16ffc(%rip), %rsi     # 0xa3c01
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8b703
jmp 0x8ccc6
testb $0x2, 0x11c(%rbx)
jne 0x8cc34
leaq 0x16ff1(%rip), %rsi     # 0xa3c1d
movq %rbx, %rdi
callq 0x84a53
cmpl $0x100, %ebp            # imm = 0x100
ja 0x8cc84
movzwl 0x240(%rbx), %eax
cmpl %ebp, %eax
jb 0x8cc84
testl %ebp, %ebp
je 0x8ccd4
movl %ebp, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x8b6d7
movw %bp, 0x242(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
testl %eax, %eax
je 0x8ccaa
andw $0x0, 0x242(%rbx)
jmp 0x8ccc6
leaq 0x16fcb(%rip), %rsi     # 0xa3c4d
jmp 0x8cc8b
leaq 0x16f76(%rip), %rsi     # 0xa3c01
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %ebp, %esi
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8b703
movzwl 0x242(%rbx), %ecx
leaq 0x2e0(%rbx), %r8
movq %rsp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7b9d2
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16f5b(%rip), %rsi     # 0xa3c36
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x8cc98