// File: tomfunkhouser[P]gaps/pkgs/png/pngwrite.c
// Function: png_write_png
void PNGAPI
png_write_png(png_structp png_ptr, png_infop info_ptr,
              int transforms, voidp params)
{
   if (png_ptr == NULL || info_ptr == NULL)
      return;

   /* Write the file header information. */
   png_write_info(png_ptr, info_ptr);

   /* ------ these transformations don't touch the info structure ------- */

#ifdef PNG_WRITE_INVERT_SUPPORTED
   /* Invert monochrome pixels */
   if (transforms & PNG_TRANSFORM_INVERT_MONO)
      png_set_invert_mono(png_ptr);
#endif

#ifdef PNG_WRITE_SHIFT_SUPPORTED
   /* Shift the pixels up to a legal bit depth and fill in
    * as appropriate to correctly scale the image.
    */
   if ((transforms & PNG_TRANSFORM_SHIFT)
               && (info_ptr->valid & PNG_INFO_sBIT))
      png_set_shift(png_ptr, &info_ptr->sig_bit);
#endif

#ifdef PNG_WRITE_PACK_SUPPORTED
   /* Pack pixels into bytes */
   if (transforms & PNG_TRANSFORM_PACKING)
       png_set_packing(png_ptr);
#endif

#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
   /* Swap location of alpha bytes from ARGB to RGBA */
   if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
      png_set_swap_alpha(png_ptr);
#endif

#ifdef PNG_WRITE_FILLER_SUPPORTED
   /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
      png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
   else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
      png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#endif

#ifdef PNG_WRITE_BGR_SUPPORTED
   /* Flip BGR pixels to RGB */
   if (transforms & PNG_TRANSFORM_BGR)
      png_set_bgr(png_ptr);
#endif

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

#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
   /* Swap bits of 1, 2, 4 bit packed pixel formats */
   if (transforms & PNG_TRANSFORM_PACKSWAP)
      png_set_packswap(png_ptr);
#endif

#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
   /* Invert the alpha channel from opacity to transparency */
   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
      png_set_invert_alpha(png_ptr);
#endif

   /* ----------------------- end of transformations ------------------- */

   /* Write the bits */
   if (info_ptr->valid & PNG_INFO_IDAT)
       png_write_image(png_ptr, info_ptr->row_pointers);

   /* It is REQUIRED to call this to finish writing the rest of the file */
   png_write_end(png_ptr, info_ptr);

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

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movq %rcx, 0x8(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x105eb7
cmpq $0x0, 0x18(%rsp)
jne 0x105ebc
jmp 0x106029
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x103a80
movl 0x14(%rsp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x105ee1
movq 0x20(%rsp), %rdi
callq 0x12a160
movl 0x14(%rsp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x105f10
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x105f10
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
addq $0x58, %rsi
callq 0x129f40
movl 0x14(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x105f26
movq 0x20(%rsp), %rdi
callq 0x129eb0
movl 0x14(%rsp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x105f3e
movq 0x20(%rsp), %rdi
callq 0x12a100
movl 0x14(%rsp), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x105f5f
movq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x129fe0
jmp 0x105f7d
movl 0x14(%rsp), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x105f7b
movq 0x20(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x129fe0
jmp 0x105f7d
movl 0x14(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x105f95
movq 0x20(%rsp), %rdi
callq 0x129e40
movl 0x14(%rsp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x105fad
movq 0x20(%rsp), %rdi
callq 0x129e70
movl 0x14(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x105fc3
movq 0x20(%rsp), %rdi
callq 0x129f00
movl 0x14(%rsp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x105fdb
movq 0x20(%rsp), %rdi
callq 0x12a130
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
andq $0x8000, %rax           # imm = 0x8000
cmpq $0x0, %rax
je 0x106005
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x140(%rax), %rsi
callq 0x1052a0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x1040f0
movl 0x14(%rsp), %eax
addl $0x0, %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x28, %rsp
retq
nop