// File: tomfunkhouser[P]gaps/pkgs/png/pngread.c
// Function: png_read_png
void PNGAPI
png_read_png(png_structp png_ptr, png_infop info_ptr,
                           int transforms,
                           voidp params)
{
   int row;

   if (png_ptr == NULL)
      return;

   /* png_read_info() gives us all of the information from the
    * PNG file before the first IDAT (image data chunk).
    */
   png_read_info(png_ptr, info_ptr);
   if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
      png_error(png_ptr, "Image is too high to process with png_read_png()");

   /* -------------- image transformations start here ------------------- */

#ifdef PNG_READ_16_TO_8_SUPPORTED
   /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
    */
   if (transforms & PNG_TRANSFORM_STRIP_16)
      png_set_strip_16(png_ptr);
#endif

#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
   /* Strip alpha bytes from the input data without combining with
    * the background (not recommended).
    */
   if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
      png_set_strip_alpha(png_ptr);
#endif

#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
   /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
    * byte into separate bytes (useful for paletted and grayscale images).
    */
   if (transforms & PNG_TRANSFORM_PACKING)
      png_set_packing(png_ptr);
#endif

#ifdef PNG_READ_PACKSWAP_SUPPORTED
   /* Change the order of packed pixels to least significant bit first
    * (not useful if you are using png_set_packing).
    */
   if (transforms & PNG_TRANSFORM_PACKSWAP)
      png_set_packswap(png_ptr);
#endif

#ifdef PNG_READ_EXPAND_SUPPORTED
   /* Expand paletted colors into true RGB triplets
    * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
    * Expand paletted or RGB images with transparency to full alpha
    * channels so the data will be available as RGBA quartets.
    */
   if (transforms & PNG_TRANSFORM_EXPAND)
      if ((png_ptr->bit_depth < 8) ||
          (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
          (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
         png_set_expand(png_ptr);
#endif

   /* We don't handle background color or gamma transformation or quantizing.
    */

#ifdef PNG_READ_INVERT_SUPPORTED
   /* Invert monochrome files to have 0 as white and 1 as black
    */
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
      png_set_invert_mono(png_ptr);
#endif

#ifdef PNG_READ_SHIFT_SUPPORTED
   /* If you want to shift the pixel values from the range [0,255] or
    * [0,65535] to the original [0,7] or [0,31], or whatever range the
    * colors were originally in:
    */
   if ((transforms & PNG_TRANSFORM_SHIFT)
       && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
   {
      png_color_8p sig_bit;

      png_get_sBIT(png_ptr, info_ptr, &sig_bit);
      png_set_shift(png_ptr, sig_bit);
   }
#endif

#ifdef PNG_READ_BGR_SUPPORTED
   /* Flip the RGB pixels to BGR (or RGBA to BGRA)
    */
   if (transforms & PNG_TRANSFORM_BGR)
      png_set_bgr(png_ptr);
#endif

#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
    */
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
       png_set_swap_alpha(png_ptr);
#endif

#ifdef PNG_READ_SWAP_SUPPORTED
   /* Swap bytes of 16 bit files to least significant byte first
    */
   if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
      png_set_swap(png_ptr);
#endif

/* Added at libpng-1.2.41 */
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
   /* Invert the alpha channel from opacity to transparency
    */
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
       png_set_invert_alpha(png_ptr);
#endif

/* Added at libpng-1.2.41 */
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
   /* Expand grayscale image to RGB
    */
   if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
       png_set_gray_to_rgb(png_ptr);
#endif

   /* We don't handle adding filler bytes */

   /* Optional call to gamma correct and add the background to the palette
    * and update info structure.  REQUIRED if you are expecting libpng to
    * update the palette for you (i.e., you selected such a transform above).
    */
   png_read_update_info(png_ptr, info_ptr);

   /* -------------- image transformations end here ------------------- */

   png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
   if (info_ptr->row_pointers == NULL)
   {
    png_uint_32 iptr;

      info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
         info_ptr->height * png_sizeof(png_bytep));
      for (iptr=0; iptr<info_ptr->height; iptr++)
         info_ptr->row_pointers[iptr] = NULL;

      info_ptr->free_me |= PNG_FREE_ROWS;

      for (row = 0; row < (int)info_ptr->height; row++)
         info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
            png_get_rowbytes(png_ptr, info_ptr));
   }

   png_read_image(png_ptr, info_ptr->row_pointers);
   info_ptr->valid |= PNG_INFO_IDAT;

   /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
   png_read_end(png_ptr, info_ptr);

   transforms = transforms + 0; /* Quiet compiler warnings */
   params = params + 0;

}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq %rcx, 0x28(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x103264
jmp 0x10355c
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x100be0
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
cmpq $0x1fffffff, %rax       # imm = 0x1FFFFFFF
jbe 0x103294
movq 0x40(%rsp), %rdi
leaq 0x3601d(%rip), %rsi     # 0x1392ac
callq 0x113860
movl 0x34(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1032aa
movq 0x40(%rsp), %rdi
callq 0x1062b0
movl 0x34(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1032c0
movq 0x40(%rsp), %rdi
callq 0x1062e0
movl 0x34(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1032d6
movq 0x40(%rsp), %rdi
callq 0x129f00
movl 0x34(%rsp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x103329
movq 0x40(%rsp), %rax
movzbl 0x24f(%rax), %eax
cmpl $0x8, %eax
jl 0x10331d
movq 0x40(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
je 0x10331d
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0xff070
cmpl $0x0, %eax
je 0x103327
movq 0x40(%rsp), %rdi
callq 0x107780
jmp 0x103329
movl 0x34(%rsp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x10333f
movq 0x40(%rsp), %rdi
callq 0x12a160
movl 0x34(%rsp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x103387
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x2, %edx
callq 0xff070
cmpl $0x0, %eax
je 0x103387
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x100260
movq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x129f40
movl 0x34(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x10339f
movq 0x40(%rsp), %rdi
callq 0x129e40
movl 0x34(%rsp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1033b7
movq 0x40(%rsp), %rdi
callq 0x12a100
movl 0x34(%rsp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x1033cf
movq 0x40(%rsp), %rdi
callq 0x129e70
movl 0x34(%rsp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x1033e7
movq 0x40(%rsp), %rdi
callq 0x12a130
movl 0x34(%rsp), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x1033ff
movq 0x40(%rsp), %rdi
callq 0x107880
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1015f0
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0xfba80
movq 0x38(%rsp), %rax
cmpq $0x0, 0x140(%rax)
jne 0x103510
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x1135b0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x140(%rax)
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x103499
movq 0x38(%rsp), %rax
movq 0x140(%rax), %rax
movl 0x14(%rsp), %ecx
movq $0x0, (%rax,%rcx,8)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x103466
movq 0x38(%rsp), %rax
movl 0xe4(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0xe4(%rax)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x38(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x10350e
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xff0b0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x1135b0
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x140(%rax), %rax
movslq 0x24(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1034b5
jmp 0x103510
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x140(%rax), %rsi
callq 0x1022e0
movq 0x38(%rsp), %rax
movl 0x8(%rax), %ecx
orq $0x8000, %rcx           # imm = 0x8000
movl %ecx, 0x8(%rax)
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1023a0
movl 0x34(%rsp), %eax
addl $0x0, %eax
movl %eax, 0x34(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)