// File: /workspace/github_cpp_makefile_star2_O1/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 0x9ba23
leaq 0x174f2(%rip), %rsi     # 0xb2eb7
movq %rbx, %rdi
callq 0x92dd0
movzbl 0x24e(%rbx), %eax
cmpl $0x3, %eax
je 0x9baa1
cmpl $0x2, %eax
je 0x9ba4b
testl %eax, %eax
jne 0x9baea
cmpl $0x2, %ebp
jne 0x9bb39
movq %rsp, %r15
movl $0x2, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a4db
movw $0x1, 0x242(%rbx)
movzwl (%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2e8(%rbx)
jmp 0x9bb52
testb $0x4, %al
jne 0x9ba3f
testq %r14, %r14
je 0x9b9cd
testb $0x10, 0x8(%r14)
je 0x9b9cd
leaq 0x174ae(%rip), %rsi     # 0xb2ee8
jmp 0x9bb1a
leaq 0x1748a(%rip), %rsi     # 0xb2ed0
jmp 0x9bb1a
cmpl $0x6, %ebp
jne 0x9baf3
movq %rsp, %r15
movl $0x6, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a4db
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 0x9bb0c
testb $0x2, 0x11c(%rbx)
jne 0x9bab9
leaq 0x17468(%rip), %rsi     # 0xb2f19
movq %rbx, %rdi
callq 0x92e6e
cmpl $0x100, %ebp            # imm = 0x100
ja 0x9bb13
movzwl 0x240(%rbx), %eax
cmpl %ebp, %eax
jb 0x9bb13
testl %ebp, %ebp
je 0x9bb9a
movl %ebp, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x9a4db
movw %bp, 0x242(%rbx)
jmp 0x9bb57
leaq 0x17458(%rip), %rsi     # 0xb2f49
jmp 0x9bb1a
leaq 0x17403(%rip), %rsi     # 0xb2efd
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x9a507
cmpl $0x6, %ebp
je 0x9bb57
jmp 0x9bb8c
leaq 0x173e3(%rip), %rsi     # 0xb2efd
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %ebp, %esi
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x9a507
leaq 0x173bd(%rip), %rsi     # 0xb2efd
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x9a507
cmpl $0x2, %ebp
jne 0x9bb8c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9a507
testl %eax, %eax
je 0x9bb70
movw $0x0, 0x242(%rbx)
jmp 0x9bb8c
movzwl 0x242(%rbx), %ecx
leaq 0x2e0(%rbx), %r8
movq %rsp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x89477
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17391(%rip), %rsi     # 0xb2f32
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x9bb27