// File: tomfunkhouser[P]gaps/pkgs/png/pngwrite.c
// Function: png_write_info_before_PLTE
void PNGAPI
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
{
   png_debug(1, "in png_write_info_before_PLTE");

   if (png_ptr == NULL || info_ptr == NULL)
      return;
   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
   {
   /* Write PNG signature */
   png_write_sig(png_ptr);
#ifdef PNG_MNG_FEATURES_SUPPORTED
   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
      (png_ptr->mng_features_permitted))
   {
      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
      png_ptr->mng_features_permitted = 0;
   }
#endif
   /* Write IHDR information. */
   png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
      info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
      info_ptr->filter_type,
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
      info_ptr->interlace_type);
#else
      0);
#endif
   /* The rest of these check to see if the valid field has the appropriate
    * flag set, and if it does, writes the chunk.
    */
#ifdef PNG_WRITE_gAMA_SUPPORTED
   if (info_ptr->valid & PNG_INFO_gAMA)
   {
#  ifdef PNG_FLOATING_POINT_SUPPORTED
      png_write_gAMA(png_ptr, info_ptr->gamma);
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
      png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
#  endif
#endif
   }
#endif
#ifdef PNG_WRITE_sRGB_SUPPORTED
   if (info_ptr->valid & PNG_INFO_sRGB)
      png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
#endif
#ifdef PNG_WRITE_iCCP_SUPPORTED
   if (info_ptr->valid & PNG_INFO_iCCP)
      png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
                     info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
#endif
#ifdef PNG_WRITE_sBIT_SUPPORTED
   if (info_ptr->valid & PNG_INFO_sBIT)
      png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
#endif
#ifdef PNG_WRITE_cHRM_SUPPORTED
   if (info_ptr->valid & PNG_INFO_cHRM)
   {
#ifdef PNG_FLOATING_POINT_SUPPORTED
      png_write_cHRM(png_ptr,
         info_ptr->x_white, info_ptr->y_white,
         info_ptr->x_red, info_ptr->y_red,
         info_ptr->x_green, info_ptr->y_green,
         info_ptr->x_blue, info_ptr->y_blue);
#else
#  ifdef PNG_FIXED_POINT_SUPPORTED
      png_write_cHRM_fixed(png_ptr,
         info_ptr->int_x_white, info_ptr->int_y_white,
         info_ptr->int_x_red, info_ptr->int_y_red,
         info_ptr->int_x_green, info_ptr->int_y_green,
         info_ptr->int_x_blue, info_ptr->int_y_blue);
#  endif
#endif
   }
#endif
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
   if (info_ptr->unknown_chunks_num)
   {
      png_unknown_chunk *up;

      png_debug(5, "writing extra chunks");

      for (up = info_ptr->unknown_chunks;
           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
           up++)
      {
         int keep = png_handle_as_unknown(png_ptr, up->name);
         if (keep != PNG_HANDLE_CHUNK_NEVER &&
            up->location && !(up->location & PNG_HAVE_PLTE) &&
            !(up->location & PNG_HAVE_IDAT) &&
            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
         {
            if (up->size == 0)
               png_warning(png_ptr, "Writing zero-length unknown chunk");
            png_write_chunk(png_ptr, up->name, up->data, up->size);
         }
      }
   }
#endif
      png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
   }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x10371e
cmpq $0x0, 0x28(%rsp)
jne 0x103723
jmp 0x103a79
movq 0x30(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x103a79
movq 0x30(%rsp), %rdi
callq 0x12afb0
movq 0x30(%rsp), %rax
movl 0x11c(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x103789
movq 0x30(%rsp), %rax
cmpl $0x0, 0x408(%rax)
je 0x103789
movq 0x30(%rsp), %rdi
leaq 0x35546(%rip), %rsi     # 0x138cbb
callq 0x113940
movq 0x30(%rsp), %rax
movl $0x0, 0x408(%rax)
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movl (%rax), %esi
movq 0x28(%rsp), %rax
movl 0x4(%rax), %edx
movq 0x28(%rsp), %rax
movzbl 0x24(%rax), %ecx
movq 0x28(%rsp), %rax
movzbl 0x25(%rax), %r8d
movq 0x28(%rsp), %rax
movzbl 0x26(%rax), %r9d
movq 0x28(%rsp), %rax
movzbl 0x27(%rax), %r10d
movq 0x28(%rsp), %rax
movzbl 0x28(%rax), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x12b1f0
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x103802
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movss 0x34(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x12bc10
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x103827
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movzbl 0x38(%rax), %esi
callq 0x12bcd0
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x103869
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0xf8(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0x100(%rax), %rcx
movq 0x28(%rsp), %rax
movl 0x108(%rax), %r8d
xorl %edx, %edx
callq 0x12bd30
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x103895
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq $0x58, %rsi
movq 0x28(%rsp), %rax
movzbl 0x25(%rax), %edx
callq 0x12cb70
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x10393b
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rax
movss 0xa0(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq 0x28(%rsp), %rax
movss 0xa4(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq 0x28(%rsp), %rax
movss 0xa8(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
movq 0x28(%rsp), %rax
movss 0xac(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
movq 0x28(%rsp), %rax
movss 0xb0(%rax), %xmm4
cvtss2sd %xmm4, %xmm4
movq 0x28(%rsp), %rax
movss 0xb4(%rax), %xmm5
cvtss2sd %xmm5, %xmm5
movq 0x28(%rsp), %rax
movss 0xb8(%rax), %xmm6
cvtss2sd %xmm6, %xmm6
movq 0x28(%rsp), %rax
movss 0xbc(%rax), %xmm7
cvtss2sd %xmm7, %xmm7
callq 0x12cd50
movq 0x28(%rsp), %rax
cmpq $0x0, 0xf0(%rax)
je 0x103a62
movq 0x28(%rsp), %rax
movq 0xe8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq 0xe8(%rcx), %rcx
movq 0x28(%rsp), %rdx
movq 0xf0(%rdx), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x103a60
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0xfc3e0
movl %eax, 0x1c(%rsp)
cmpl $0x1, 0x1c(%rsp)
je 0x103a4b
movq 0x20(%rsp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x103a4b
movq 0x20(%rsp), %rax
movzbl 0x18(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x103a4b
movq 0x20(%rsp), %rax
movzbl 0x18(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x103a4b
movq 0x20(%rsp), %rax
movzbl 0x3(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x103a0d
cmpl $0x3, 0x1c(%rsp)
je 0x103a0d
movq 0x30(%rsp), %rax
movl 0x120(%rax), %eax
andq $0x10000, %rax          # imm = 0x10000
cmpq $0x0, %rax
je 0x103a4b
movq 0x20(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x103a2a
movq 0x30(%rsp), %rdi
leaq 0x35997(%rip), %rsi     # 0x1393bc
callq 0x113940
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rcx
callq 0x12b040
jmp 0x103a4d
movq 0x20(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
jmp 0x10395f
jmp 0x103a62
movq 0x30(%rsp), %rax
movl 0x11c(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x11c(%rax)
addq $0x38, %rsp
retq
nop