// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
testb $0x1, 0x11c(%rdi)
je 0x99f66
leaq 0x189b1(%rip), %rsi     # 0xb290f
movq %r14, %rdi
callq 0x920b4
cmpl $0xd, %ebp
je 0x99f7a
leaq 0x189af(%rip), %rsi     # 0xb2921
movq %r14, %rdi
callq 0x920b4
movq %rbx, 0x10(%rsp)
orb $0x1, 0x11c(%r14)
leaq 0x3(%rsp), %r15
movl $0xd, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x99b23
movq %r14, %rdi
xorl %esi, %esi
callq 0x99b4f
movzbl (%r15), %r12d
shll $0x18, %r12d
movzbl 0x1(%r15), %r13d
movzbl 0x2(%r15), %ebp
movzbl 0x3(%r15), %r15d
jns 0x99fce
leaq 0x1888a(%rip), %rsi     # 0xb2850
movq %r14, %rdi
callq 0x920b4
shll $0x10, %r13d
orl %r15d, %r13d
shll $0x8, %ebp
orl %r13d, %ebp
orl %r12d, %ebp
movzbl 0x7(%rsp), %r12d
shll $0x18, %r12d
movzbl 0x8(%rsp), %r13d
movzbl 0x9(%rsp), %r15d
movzbl 0xa(%rsp), %ebx
jns 0x9a00a
leaq 0x1884e(%rip), %rsi     # 0xb2850
movq %r14, %rdi
callq 0x920b4
shll $0x10, %r13d
orl %ebx, %r13d
shll $0x8, %r15d
orl %r13d, %r15d
orl %r12d, %r15d
movzbl 0xb(%rsp), %r8d
movzbl 0xc(%rsp), %r9d
movzbl 0xd(%rsp), %r10d
movzbl 0xe(%rsp), %r12d
movzbl 0xf(%rsp), %r11d
movl %ebp, 0x1bc(%r14)
movl %r15d, 0x1c0(%r14)
movb %r8b, 0x24f(%r14)
movb %r11b, 0x24b(%r14)
movb %r9b, 0x24e(%r14)
movb %r12b, 0x410(%r14)
movb %r10b, 0x450(%r14)
cmpq $0x6, %r9
ja 0x9a08c
leaq 0x18729(%rip), %rax     # 0xb27a0
movslq (%rax,%r9,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movb $0x1, 0x252(%r14)
movb $0x1, %al
jmp 0x9a0b7
movb 0x252(%r14), %al
jmp 0x9a0b7
movb $0x3, 0x252(%r14)
movb $0x3, %al
jmp 0x9a0b7
movb $0x2, 0x252(%r14)
movb $0x2, %al
jmp 0x9a0b7
movb $0x4, 0x252(%r14)
movb $0x4, %al
movq 0x10(%rsp), %rsi
mulb %r8b
movb %al, 0x251(%r14)
movl %ebp, %ecx
cmpb $0x8, %al
jb 0x9a0d8
shrb $0x3, %al
movzbl %al, %eax
imulq %rcx, %rax
jmp 0x9a0e7
movzbl %al, %eax
imulq %rcx, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x1d0(%r14)
subq $0x8, %rsp
movq %r14, %rdi
movl %ebp, %edx
movl %r15d, %ecx
pushq %r12
pushq %r10
pushq %r11
callq 0x87d78
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq