// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_sBIT
void /* PRIVATE */
png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
{
   PNG_sBIT;
   png_byte buf[4];
   png_size_t size;

   png_debug(1, "in png_write_sBIT");

   /* Make sure we don't depend upon the order of PNG_COLOR_8 */
   if (color_type & PNG_COLOR_MASK_COLOR)
   {
      png_byte maxbits;

      maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
                png_ptr->usr_bit_depth);
      if (sbit->red == 0 || sbit->red > maxbits ||
          sbit->green == 0 || sbit->green > maxbits ||
          sbit->blue == 0 || sbit->blue > maxbits)
      {
         png_warning(png_ptr, "Invalid sBIT depth specified");
         return;
      }
      buf[0] = sbit->red;
      buf[1] = sbit->green;
      buf[2] = sbit->blue;
      size = 3;
   }
   else
   {
      if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
      {
         png_warning(png_ptr, "Invalid sBIT depth specified");
         return;
      }
      buf[0] = sbit->gray;
      size = 1;
   }

   if (color_type & PNG_COLOR_MASK_ALPHA)
   {
      if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
      {
         png_warning(png_ptr, "Invalid sBIT depth specified");
         return;
      }
      buf[size++] = sbit->alpha;
   }

   png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movl 0x128b8(%rip), %eax     # 0x13f440
movl %eax, 0x1f(%rsp)
movb 0x128b2(%rip), %al      # 0x13f444
movb %al, 0x23(%rsp)
movl 0x24(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12cc72
cmpl $0x3, 0x24(%rsp)
jne 0x12cbb8
movl $0x8, %eax
movl %eax, 0x8(%rsp)
jmp 0x12cbc8
movq 0x30(%rsp), %rax
movzbl 0x250(%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movb %al, 0xf(%rsp)
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x12cc2e
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
movzbl 0xf(%rsp), %ecx
cmpl %ecx, %eax
jg 0x12cc2e
movq 0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x12cc2e
movq 0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
movzbl 0xf(%rsp), %ecx
cmpl %ecx, %eax
jg 0x12cc2e
movq 0x28(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x12cc2e
movq 0x28(%rsp), %rax
movzbl 0x2(%rax), %eax
movzbl 0xf(%rsp), %ecx
cmpl %ecx, %eax
jle 0x12cc44
movq 0x30(%rsp), %rdi
leaq 0x13c3d(%rip), %rsi     # 0x140877
callq 0x113940
jmp 0x12cd40
movq 0x28(%rsp), %rax
movb (%rax), %al
movb %al, 0x1b(%rsp)
movq 0x28(%rsp), %rax
movb 0x1(%rax), %al
movb %al, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movb 0x2(%rax), %al
movb %al, 0x1d(%rsp)
movq $0x3, 0x10(%rsp)
jmp 0x12ccc4
movq 0x28(%rsp), %rax
movzbl 0x3(%rax), %eax
cmpl $0x0, %eax
je 0x12cc99
movq 0x28(%rsp), %rax
movzbl 0x3(%rax), %eax
movq 0x30(%rsp), %rcx
movzbl 0x250(%rcx), %ecx
cmpl %ecx, %eax
jle 0x12ccaf
movq 0x30(%rsp), %rdi
leaq 0x13bd2(%rip), %rsi     # 0x140877
callq 0x113940
jmp 0x12cd40
movq 0x28(%rsp), %rax
movb 0x3(%rax), %al
movb %al, 0x1b(%rsp)
movq $0x1, 0x10(%rsp)
movl 0x24(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12cd27
movq 0x28(%rsp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x12ccf7
movq 0x28(%rsp), %rax
movzbl 0x4(%rax), %eax
movq 0x30(%rsp), %rcx
movzbl 0x250(%rcx), %ecx
cmpl %ecx, %eax
jle 0x12cd0a
movq 0x30(%rsp), %rdi
leaq 0x13b74(%rip), %rsi     # 0x140877
callq 0x113940
jmp 0x12cd40
movq 0x28(%rsp), %rax
movb 0x4(%rax), %cl
movq 0x10(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x10(%rsp)
movb %cl, 0x1b(%rsp,%rax)
movq 0x30(%rsp), %rdi
leaq 0x1f(%rsp), %rsi
leaq 0x1b(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x12b040
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)