// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_IHDR
void /* PRIVATE */
png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_byte buf[13];
   png_uint_32 width, height;
   int bit_depth, color_type, compression_type, filter_type;
   int interlace_type;

   png_debug(1, "in png_handle_IHDR");

   if (png_ptr->mode & PNG_HAVE_IHDR)
      png_error(png_ptr, "Out of place IHDR");

   /* Check the length */
   if (length != 13)
      png_error(png_ptr, "Invalid IHDR chunk");

   png_ptr->mode |= PNG_HAVE_IHDR;

   png_crc_read(png_ptr, buf, 13);
   png_crc_finish(png_ptr, 0);

   width = png_get_uint_31(png_ptr, buf);
   height = png_get_uint_31(png_ptr, buf + 4);
   bit_depth = buf[8];
   color_type = buf[9];
   compression_type = buf[10];
   filter_type = buf[11];
   interlace_type = buf[12];

   /* Set internal variables */
   png_ptr->width = width;
   png_ptr->height = height;
   png_ptr->bit_depth = (png_byte)bit_depth;
   png_ptr->interlaced = (png_byte)interlace_type;
   png_ptr->color_type = (png_byte)color_type;
#ifdef PNG_MNG_FEATURES_SUPPORTED
   png_ptr->filter_type = (png_byte)filter_type;
#endif
   png_ptr->compression_type = (png_byte)compression_type;

   /* Find number of channels */
   switch (png_ptr->color_type)
   {
      case PNG_COLOR_TYPE_GRAY:
      case PNG_COLOR_TYPE_PALETTE:
         png_ptr->channels = 1;
         break;

      case PNG_COLOR_TYPE_RGB:
         png_ptr->channels = 3;
         break;

      case PNG_COLOR_TYPE_GRAY_ALPHA:
         png_ptr->channels = 2;
         break;

      case PNG_COLOR_TYPE_RGB_ALPHA:
         png_ptr->channels = 4;
         break;
   }

   /* Set up other useful info */
   png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
   png_ptr->channels);
   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
   png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
   png_debug1(3, "channels = %d", png_ptr->channels);
   png_debug1(3, "rowbytes = %lu", png_ptr->rowbytes);
   png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
      color_type, interlace_type, compression_type, filter_type);
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movl %edx, 0x64(%rsp)
movq 0x70(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x123316
movq 0x70(%rsp), %rdi
leaq 0x1bf0e(%rip), %rsi     # 0x13f21f
callq 0x113860
cmpl $0xd, 0x64(%rsp)
je 0x12332e
movq 0x70(%rsp), %rdi
leaq 0x1bf08(%rip), %rsi     # 0x13f231
callq 0x113860
movq 0x70(%rsp), %rax
movl 0x11c(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x11c(%rax)
movq 0x70(%rsp), %rdi
leaq 0x57(%rsp), %rsi
movq %rsi, 0x28(%rsp)
movl $0xd, %edx
callq 0x122b40
movq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
movq 0x28(%rsp), %rsi
movq 0x70(%rsp), %rdi
callq 0x122900
movl %eax, 0x50(%rsp)
movq 0x70(%rsp), %rdi
leaq 0x5b(%rsp), %rsi
callq 0x122900
movl %eax, 0x4c(%rsp)
movzbl 0x5f(%rsp), %eax
movl %eax, 0x48(%rsp)
movzbl 0x60(%rsp), %eax
movl %eax, 0x44(%rsp)
movzbl 0x61(%rsp), %eax
movl %eax, 0x40(%rsp)
movzbl 0x62(%rsp), %eax
movl %eax, 0x3c(%rsp)
movzbl 0x63(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x50(%rsp), %ecx
movq 0x70(%rsp), %rax
movl %ecx, 0x1bc(%rax)
movl 0x4c(%rsp), %ecx
movq 0x70(%rsp), %rax
movl %ecx, 0x1c0(%rax)
movb 0x48(%rsp), %cl
movq 0x70(%rsp), %rax
movb %cl, 0x24f(%rax)
movb 0x38(%rsp), %cl
movq 0x70(%rsp), %rax
movb %cl, 0x24b(%rax)
movb 0x44(%rsp), %cl
movq 0x70(%rsp), %rax
movb %cl, 0x24e(%rax)
movb 0x3c(%rsp), %cl
movq 0x70(%rsp), %rax
movb %cl, 0x410(%rax)
movb 0x40(%rsp), %cl
movq 0x70(%rsp), %rax
movb %cl, 0x450(%rax)
movq 0x70(%rsp), %rax
movzbl 0x24e(%rax), %eax
movq %rax, 0x30(%rsp)
subq $0x6, %rax
ja 0x123485
movq 0x30(%rsp), %rax
leaq 0x1bbca(%rip), %rcx     # 0x13f010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x70(%rsp), %rax
movb $0x1, 0x252(%rax)
jmp 0x123485
movq 0x70(%rsp), %rax
movb $0x3, 0x252(%rax)
jmp 0x123485
movq 0x70(%rsp), %rax
movb $0x2, 0x252(%rax)
jmp 0x123485
movq 0x70(%rsp), %rax
movb $0x4, 0x252(%rax)
movq 0x70(%rsp), %rax
movzbl 0x24f(%rax), %eax
movq 0x70(%rsp), %rcx
movzbl 0x252(%rcx), %ecx
imull %ecx, %eax
movb %al, %cl
movq 0x70(%rsp), %rax
movb %cl, 0x251(%rax)
movq 0x70(%rsp), %rax
movzbl 0x251(%rax), %eax
cmpl $0x8, %eax
jl 0x1234e4
movq 0x70(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0x70(%rsp), %rcx
movzbl 0x251(%rcx), %ecx
shrq $0x3, %rcx
imulq %rcx, %rax
movq %rax, 0x20(%rsp)
jmp 0x12350c
movq 0x70(%rsp), %rax
movl 0x1bc(%rax), %eax
movq 0x70(%rsp), %rcx
movzbl 0x251(%rcx), %ecx
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x1d0(%rax)
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x50(%rsp), %edx
movl 0x4c(%rsp), %ecx
movl 0x48(%rsp), %r8d
movl 0x44(%rsp), %r9d
movl 0x38(%rsp), %r11d
movl 0x40(%rsp), %r10d
movl 0x3c(%rsp), %eax
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0xfd370
addq $0x78, %rsp
retq
nop