// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_sRGB
void /* PRIVATE */
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   int intent;
   png_byte buf[1];

   png_debug(1, "in png_handle_sRGB");

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before sRGB");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid sRGB 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 sRGB chunk");

   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
   {
      png_warning(png_ptr, "Duplicate sRGB chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

   if (length != 1)
   {
      png_warning(png_ptr, "Incorrect sRGB chunk length");
      png_crc_finish(png_ptr, length);
      return;
   }

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

   intent = buf[0];
   /* Check for bad intent */
   if (intent >= PNG_sRGB_INTENT_LAST)
   {
      png_warning(png_ptr, "Unknown sRGB intent");
      return;
   }

#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
   {
   png_fixed_point igamma;
#ifdef PNG_FIXED_POINT_SUPPORTED
      igamma=info_ptr->int_gamma;
#else
#  ifdef PNG_FLOATING_POINT_SUPPORTED
      igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
#  endif
#endif
      if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
      {
         png_warning(png_ptr,
           "Ignoring incorrect gAMA value when sRGB is also present");
#ifdef PNG_CONSOLE_IO_SUPPORTED
#  ifdef PNG_FIXED_POINT_SUPPORTED
         fprintf(stderr, "incorrect gamma=(%d/100000)\n",
            (int)png_ptr->int_gamma);
#  else
#    ifdef PNG_FLOATING_POINT_SUPPORTED
         fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma);
#    endif
#  endif
#endif
      }
   }
#endif /* PNG_READ_gAMA_SUPPORTED */

#ifdef PNG_READ_cHRM_SUPPORTED
#ifdef PNG_FIXED_POINT_SUPPORTED
   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
      if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270,  1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900,  1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_x_red,   64000L, 1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_y_red,   33000,  1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000,  1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_x_blue,  15000,  1000) ||
          PNG_OUT_OF_RANGE(info_ptr->int_y_blue,   6000,  1000))
         {
            png_warning(png_ptr,
              "Ignoring incorrect cHRM value when sRGB is also present");
         }
#endif /* PNG_FIXED_POINT_SUPPORTED */
#endif /* PNG_READ_cHRM_SUPPORTED */

   png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1243f8
movq 0x20(%rsp), %rdi
leaq 0x1b1a0(%rip), %rsi     # 0x13f591
callq 0x113860
jmp 0x124457
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12442f
movq 0x20(%rsp), %rdi
leaq 0x1b193(%rip), %rsi     # 0x13f5aa
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x124709
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x124453
movq 0x20(%rsp), %rdi
leaq 0x1b174(%rip), %rsi     # 0x13f5c2
callq 0x113940
jmp 0x124455
jmp 0x124457
cmpq $0x0, 0x18(%rsp)
je 0x124495
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x124495
movq 0x20(%rsp), %rdi
leaq 0x1b15d(%rip), %rsi     # 0x13f5da
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x124709
cmpl $0x1, 0x14(%rsp)
je 0x1244c0
movq 0x20(%rsp), %rdi
leaq 0x1b147(%rip), %rsi     # 0x13f5ef
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x124709
movq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x122b40
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x1244ea
jmp 0x124709
movzbl 0xf(%rsp), %eax
movl %eax, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jl 0x124510
movq 0x20(%rsp), %rdi
leaq 0x1b105(%rip), %rsi     # 0x13f60b
callq 0x113940
jmp 0x124709
cmpq $0x0, 0x18(%rsp)
je 0x124587
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x124587
movq 0x18(%rsp), %rax
movl 0x148(%rax), %eax
movl %eax, 0x8(%rsp)
movslq 0x8(%rsp), %rax
cmpq $0xafc8, %rax           # imm = 0xAFC8
jl 0x124551
movslq 0x8(%rsp), %rax
cmpq $0xb3b0, %rax           # imm = 0xB3B0
jle 0x124585
movq 0x20(%rsp), %rdi
leaq 0x1ae83(%rip), %rsi     # 0x13f3e0
callq 0x113940
movq 0x4aa5f(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movl 0x40c(%rax), %edx
leaq 0x1b0a1(%rip), %rsi     # 0x13f61f
movb $0x0, %al
callq 0xf730
jmp 0x124587
cmpq $0x0, 0x18(%rsp)
je 0x1246f6
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1246f6
movq 0x18(%rsp), %rax
cmpl $0x763e, 0x14c(%rax)    # imm = 0x763E
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x7e0e, 0x14c(%rax)    # imm = 0x7E0E
jg 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x7c9c, 0x150(%rax)    # imm = 0x7C9C
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x846c, 0x150(%rax)    # imm = 0x846C
jg 0x1246e3
movq 0x18(%rsp), %rax
movslq 0x154(%rax), %rax
cmpq $0xf618, %rax           # imm = 0xF618
jl 0x1246e3
movq 0x18(%rsp), %rax
movslq 0x154(%rax), %rax
cmpq $0xfde8, %rax           # imm = 0xFDE8
jg 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x7d00, 0x158(%rax)    # imm = 0x7D00
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x84d0, 0x158(%rax)    # imm = 0x84D0
jg 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x7148, 0x15c(%rax)    # imm = 0x7148
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x7918, 0x15c(%rax)    # imm = 0x7918
jg 0x1246e3
movq 0x18(%rsp), %rax
movslq 0x160(%rax), %rax
cmpq $0xe678, %rax           # imm = 0xE678
jl 0x1246e3
movq 0x18(%rsp), %rax
movslq 0x160(%rax), %rax
cmpq $0xee48, %rax           # imm = 0xEE48
jg 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x36b0, 0x164(%rax)    # imm = 0x36B0
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x3e80, 0x164(%rax)    # imm = 0x3E80
jg 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x1388, 0x168(%rax)    # imm = 0x1388
jl 0x1246e3
movq 0x18(%rsp), %rax
cmpl $0x1b58, 0x168(%rax)    # imm = 0x1B58
jle 0x1246f4
movq 0x20(%rsp), %rdi
leaq 0x1ae32(%rip), %rsi     # 0x13f521
callq 0x113940
jmp 0x1246f6
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x10(%rsp), %edx
callq 0xfdb50
addq $0x28, %rsp
retq
nop