// File: tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_gAMA
void /* PRIVATE */
png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_fixed_point igamma;
#ifdef PNG_FLOATING_POINT_SUPPORTED
   float file_gamma;
#endif
   png_byte buf[4];

   png_debug(1, "in png_handle_gAMA");

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

   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
#ifdef PNG_READ_sRGB_SUPPORTED
      && !(info_ptr->valid & PNG_INFO_sRGB)
#endif
      )
   {
      png_warning(png_ptr, "Duplicate gAMA chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

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

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

   igamma = (png_fixed_point)png_get_uint_32(buf);
   /* Check for zero gamma */
   if (igamma == 0)
      {
         png_warning(png_ptr,
           "Ignoring gAMA chunk with gamma=0");
         return;
      }

#ifdef PNG_READ_sRGB_SUPPORTED
   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
      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
         fprintf(stderr, "gamma = (%d/100000)", (int)igamma);
#endif
         return;
      }
#endif /* PNG_READ_sRGB_SUPPORTED */

#ifdef PNG_FLOATING_POINT_SUPPORTED
   file_gamma = (float)igamma / (float)100000.0;
#  ifdef PNG_READ_GAMMA_SUPPORTED
     png_ptr->gamma = file_gamma;
#  endif
     png_set_gAMA(png_ptr, info_ptr, file_gamma);
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
   png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
#endif
}

// 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 0x123948
movq 0x20(%rsp), %rdi
leaq 0x1ba04(%rip), %rsi     # 0x13f345
callq 0x113860
jmp 0x1239a7
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12397f
movq 0x20(%rsp), %rdi
leaq 0x1b9f7(%rip), %rsi     # 0x13f35e
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123b4a
movq 0x20(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1239a3
movq 0x20(%rsp), %rdi
leaq 0x1b9d8(%rip), %rsi     # 0x13f376
callq 0x113940
jmp 0x1239a5
jmp 0x1239a7
cmpq $0x0, 0x18(%rsp)
je 0x1239f5
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1239f5
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x1239f5
movq 0x20(%rsp), %rdi
leaq 0x1b9b1(%rip), %rsi     # 0x13f38e
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123b4a
cmpl $0x4, 0x14(%rsp)
je 0x123a20
movq 0x20(%rsp), %rdi
leaq 0x1b99b(%rip), %rsi     # 0x13f3a3
callq 0x113940
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x122b90
jmp 0x123b4a
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x122b40
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x122b90
cmpl $0x0, %eax
je 0x123a4a
jmp 0x123b4a
movzbl 0x8(%rsp), %eax
shll $0x18, %eax
movzbl 0x9(%rsp), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movzbl 0xa(%rsp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movzbl 0xb(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x10(%rsp)
cmpl $0x0, 0x10(%rsp)
jne 0x123a8e
movq 0x20(%rsp), %rdi
leaq 0x1b93b(%rip), %rsi     # 0x13f3bf
callq 0x113940
jmp 0x123b4a
cmpq $0x0, 0x18(%rsp)
je 0x123af3
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x123af3
movslq 0x10(%rsp), %rax
cmpq $0xafc8, %rax           # imm = 0xAFC8
jl 0x123ac2
movslq 0x10(%rsp), %rax
cmpq $0xb3b0, %rax           # imm = 0xB3B0
jle 0x123af1
movq 0x20(%rsp), %rdi
leaq 0x1b912(%rip), %rsi     # 0x13f3e0
callq 0x113940
movq 0x4b4ee(%rip), %rax     # 0x16efc8
movq (%rax), %rdi
movl 0x10(%rsp), %edx
leaq 0x1b930(%rip), %rsi     # 0x13f418
movb $0x0, %al
callq 0xf730
jmp 0x123b4a
jmp 0x123af3
cvtsi2ssl 0x10(%rsp), %xmm0
movss 0x1b65b(%rip), %xmm1    # 0x13f15c
divss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
movq 0x20(%rsp), %rax
movss %xmm0, 0x28c(%rax)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movss 0xc(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0xfd080
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x10(%rsp), %edx
callq 0xfd160
addq $0x28, %rsp
retq
nop