// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_sBIT
void /* PRIVATE */
png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_size_t truelen;
   png_byte buf[4];

   png_debug(1, "in png_handle_sBIT");

   buf[0] = buf[1] = buf[2] = buf[3] = 0;

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before sBIT");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid sBIT after IDAT");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (png_ptr->mode & PNG_HAVE_PLTE)
   {
      /* Should be an error, but we can cope with it */
      png_warning(png_ptr, "Out of place sBIT chunk");
   }
   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
   {
      png_warning(png_ptr, "Duplicate sBIT chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
      truelen = 3;
   else
      truelen = (png_size_t)png_ptr->channels;

   if (length != truelen || length > 4)
   {
      png_warning(png_ptr, "Incorrect sBIT chunk length");
      png_crc_finish(png_ptr, length);
      return;
   }

   png_crc_read(png_ptr, buf, truelen);
   if (png_crc_finish(png_ptr, 0))
      return;

   if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
   {
      png_ptr->sig_bit.red = buf[0];
      png_ptr->sig_bit.green = buf[1];
      png_ptr->sig_bit.blue = buf[2];
      png_ptr->sig_bit.alpha = buf[3];
   }
   else
   {
      png_ptr->sig_bit.gray = buf[0];
      png_ptr->sig_bit.red = buf[0];
      png_ptr->sig_bit.green = buf[0];
      png_ptr->sig_bit.blue = buf[0];
      png_ptr->sig_bit.alpha = buf[1];
   }
   png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movb $0x0, 0x7(%rsp)
movb $0x0, 0x6(%rsp)
movb $0x0, 0x5(%rsp)
movb $0x0, 0x4(%rsp)
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x123b9c
movq 0x20(%rsp), %rdi
leaq 0x1b897(%rip), %rsi     # 0x13f42c
callq 0x113860
jmp 0x123bfb
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x123bd3
movq 0x20(%rsp), %rdi
leaq 0x1b88a(%rip), %rsi     # 0x13f445
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123d7c
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x123bf7
movq 0x20(%rsp), %rdi
leaq 0x1b86b(%rip), %rsi     # 0x13f45d
callq 0x113940
jmp 0x123bf9
jmp 0x123bfb
cmpq $0x0, 0x18(%rsp)
je 0x123c37
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x123c37
movq 0x20(%rsp), %rdi
leaq 0x1b856(%rip), %rsi     # 0x13f475
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123d7c
movq 0x20(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x123c53
movq $0x3, 0x8(%rsp)
jmp 0x123c64
movq 0x20(%rsp), %rax
movzbl 0x252(%rax), %eax
movq %rax, 0x8(%rsp)
movl 0x14(%rsp), %eax
cmpq 0x8(%rsp), %rax
jne 0x123c76
cmpl $0x4, 0x14(%rsp)
jbe 0x123c9a
movq 0x20(%rsp), %rdi
leaq 0x1b808(%rip), %rsi     # 0x13f48a
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123d7c
movq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x122b40
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x123cc4
jmp 0x123d7c
movq 0x20(%rsp), %rax
movzbl 0x24e(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x123d16
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2c8(%rax)
movb 0x5(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2c9(%rax)
movb 0x6(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2ca(%rax)
movb 0x7(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2cc(%rax)
jmp 0x123d61
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2cb(%rax)
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2c8(%rax)
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2c9(%rax)
movb 0x4(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2ca(%rax)
movb 0x5(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x2cc(%rax)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq $0x2c8, %rdx            # imm = 0x2C8
callq 0xfdac0
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)