// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
andl $0x0, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movl 0x11c(%rdi), %eax
testb $0x1, %al
jne 0x8bfff
leaq 0x177f3(%rip), %rsi     # 0xa37cc
movq %rbx, %rdi
callq 0x849c0
testq %r14, %r14
je 0x8bff1
testb $0x2, 0x8(%r14)
jne 0x8c07d
cmpb $0x3, 0x24e(%rbx)
jne 0x8c018
pushq $0x3
popq %rdx
jmp 0x8c01f
testb $0x4, %al
jne 0x8c074
testb $0x2, %al
je 0x8bfe1
leaq 0x177ef(%rip), %rsi     # 0xa37fd
movq %rbx, %rdi
callq 0x84a53
jmp 0x8bfe1
movzbl 0x252(%rbx), %edx
cmpl %ebp, %edx
sete %al
cmpl $0x5, %ebp
setb %cl
testb %al, %cl
jne 0x8c037
leaq 0x177f5(%rip), %rsi     # 0xa382a
jmp 0x8c084
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x8b6d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
testl %eax, %eax
jne 0x8c0d9
testb $0x2, 0x24e(%rbx)
movb 0xc(%rsp), %al
jne 0x8c09e
leaq 0xd(%rsp), %rcx
movb %al, 0x2cb(%rbx)
movl %eax, %esi
movl %eax, %edi
jmp 0x8c0ab
leaq 0x1776a(%rip), %rsi     # 0xa37e5
jmp 0x8c084
leaq 0x17791(%rip), %rsi     # 0xa3815
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %ebp, %esi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x8b703
leaq 0xf(%rsp), %rcx
movb -0x2(%rcx), %sil
movb -0x1(%rcx), %dil
movb (%rcx), %cl
leaq 0x2c8(%rbx), %rdx
movb %al, 0x2c8(%rbx)
movb %sil, 0x2c9(%rbx)
movb %dil, 0x2ca(%rbx)
movb %cl, 0x2cc(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7b4a1
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq