// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_IDAT
void /* PRIVATE */
png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
{
   PNG_IDAT;

   png_debug(1, "in png_write_IDAT");

   /* Optimize the CMF field in the zlib stream. */
   /* This hack of the zlib stream is compliant to the stream specification. */
   if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
       png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
   {
      unsigned int z_cmf = data[0];  /* zlib compression method and flags */
      if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
      {
         /* Avoid memory underflows and multiplication overflows.
          *
          * The conditions below are practically always satisfied;
          * however, they still must be checked.
          */
         if (length >= 2 &&
             png_ptr->height < 16384 && png_ptr->width < 16384)
         {
            png_uint_32 uncompressed_idat_size = png_ptr->height *
               ((png_ptr->width *
               png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
            unsigned int z_cinfo = z_cmf >> 4;
            unsigned int half_z_window_size = 1 << (z_cinfo + 7);
            while (uncompressed_idat_size <= half_z_window_size &&
                   half_z_window_size >= 256)
            {
               z_cinfo--;
               half_z_window_size >>= 1;
            }
            z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
            if (data[0] != (png_byte)z_cmf)
            {
               data[0] = (png_byte)z_cmf;
               data[1] &= 0xe0;
               data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
            }
         }
      }
      else
         png_error(png_ptr,
            "Invalid zlib compression method or flags in IDAT");
   }

   png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
   png_ptr->mode |= PNG_HAVE_IDAT;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movb $0x0, 0xc(%rsp)
movl $0x54414449, 0x8(%rsp)  # imm = 0x54414449
testb $0x4, 0x11c(%rdi)
jne 0x8f8a1
cmpb $0x0, 0x450(%rbx)
jne 0x8f8a1
movzbl (%r15), %eax
movl %eax, %ecx
andl $0xf, %ecx
cmpl $0x8, %ecx
setne %cl
movl %eax, %edx
andl $-0x10, %edx
cmpl $0x71, %edx
setae %sil
orb %cl, %sil
jne 0x8f892
cmpq $0x2, %r14
jb 0x8f8a1
movl 0x1c0(%rbx), %r8d
cmpl $0x3fff, %r8d           # imm = 0x3FFF
ja 0x8f8a1
movl 0x1bc(%rbx), %ecx
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x8f8a1
movzbl 0x252(%rbx), %esi
imull %esi, %ecx
movzbl 0x24f(%rbx), %esi
imull %ecx, %esi
addl $0xf, %esi
shrl $0x3, %esi
movl %eax, %ecx
shrl $0x4, %ecx
movl $0x80, %edi
shll %cl, %edi
imull %r8d, %esi
addl $0x8, %edx
shll $0xc, %ecx
orl $0x800, %ecx            # imm = 0x800
cmpl %edi, %esi
ja 0x8f8c5
cmpl $0x100, %edi            # imm = 0x100
jb 0x8f8c5
shrl %edi
addl $-0x10, %edx
addl $0xfffff000, %ecx       # imm = 0xFFFFF000
jmp 0x8f879
leaq 0x151de(%rip), %rsi     # 0xa4a77
movq %rbx, %rdi
callq 0x849c0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x8f1fc
orb $0x4, 0x11c(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl %edx, %esi
andl $0xf8, %esi
cmpl %eax, %esi
je 0x8f8a1
movb %dl, (%r15)
movzbl 0x1(%r15), %esi
andl $-0x20, %esi
leal (%rsi,%rcx), %eax
pushq $0x1f
popq %rdi
xorl %edx, %edx
divl %edi
imull $0x1f, %eax, %eax
movl %esi, %edx
subl %eax, %edx
addl %ecx, %edx
orl %esi, %edx
xorb $0x1f, %dl
movb %dl, 0x1(%r15)
jmp 0x8f8a1