// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_hIST
void /* PRIVATE */
png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   unsigned int num, i;
   png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];

   png_debug(1, "in png_handle_hIST");

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

   num = length / 2 ;
   if (num != (unsigned int) png_ptr->num_palette || num >
      (unsigned int) PNG_MAX_PALETTE_LENGTH)
   {
      png_warning(png_ptr, "Incorrect hIST chunk length");
      png_crc_finish(png_ptr, length);
      return;
   }

   for (i = 0; i < num; i++)
   {
      png_byte buf[2];

      png_crc_read(png_ptr, buf, 2);
      readbuf[i] = png_get_uint_16(buf);
   }

   if (png_crc_finish(png_ptr, 0))
      return;

   png_set_hIST(png_ptr, info_ptr, readbuf);
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x230(%rsp)
movq %rsi, 0x228(%rsp)
movl %edx, 0x224(%rsp)
movq 0x230(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1258ed
movq 0x230(%rsp), %rdi
leaq 0x1a090(%rip), %rsi     # 0x13f973
callq 0x113860
jmp 0x1259c4
movq 0x230(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x125930
movq 0x230(%rsp), %rdi
leaq 0x1a07a(%rip), %rsi     # 0x13f98c
callq 0x113940
movq 0x230(%rsp), %rdi
movl 0x224(%rsp), %esi
callq 0x122b90
jmp 0x125abb
movq 0x230(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x125973
movq 0x230(%rsp), %rdi
leaq 0x1a04f(%rip), %rsi     # 0x13f9a4
callq 0x113940
movq 0x230(%rsp), %rdi
movl 0x224(%rsp), %esi
callq 0x122b90
jmp 0x125abb
cmpq $0x0, 0x228(%rsp)
je 0x1259be
movq 0x228(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1259be
movq 0x230(%rsp), %rdi
leaq 0x1a01d(%rip), %rsi     # 0x13f9bd
callq 0x113940
movq 0x230(%rsp), %rdi
movl 0x224(%rsp), %esi
callq 0x122b90
jmp 0x125abb
jmp 0x1259c0
jmp 0x1259c2
jmp 0x1259c4
movl 0x224(%rsp), %eax
shrl %eax
movl %eax, 0x220(%rsp)
movl 0x220(%rsp), %eax
movq 0x230(%rsp), %rcx
movzwl 0x240(%rcx), %ecx
cmpl %ecx, %eax
jne 0x1259fb
cmpl $0x100, 0x220(%rsp) # imm = 0x100
jbe 0x125a28
movq 0x230(%rsp), %rdi
leaq 0x19fc8(%rip), %rsi     # 0x13f9d2
callq 0x113940
movq 0x230(%rsp), %rdi
movl 0x224(%rsp), %esi
callq 0x122b90
jmp 0x125abb
movl $0x0, 0x21c(%rsp)
movl 0x21c(%rsp), %eax
cmpl 0x220(%rsp), %eax
jae 0x125a8b
movq 0x230(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x2, %edx
callq 0x122b40
movzbl 0xe(%rsp), %eax
shll $0x8, %eax
movzbl 0xf(%rsp), %ecx
addl %ecx, %eax
movw %ax, %cx
movl 0x21c(%rsp), %eax
movw %cx, 0x10(%rsp,%rax,2)
movl 0x21c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x21c(%rsp)
jmp 0x125a33
movq 0x230(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x125aa1
jmp 0x125abb
movq 0x230(%rsp), %rdi
movq 0x228(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0xfd230
addq $0x238, %rsp            # imm = 0x238
retq
nopw %cs:(%rax,%rax)