// File: /workspace/github_cpp_makefile_star2_O3/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 0x9e007
cmpb $0x0, 0x450(%rbx)
jne 0x9e007
movzbl (%r15), %eax
movl %eax, %ecx
andl $0xf, %ecx
cmpl $0x8, %ecx
setne %cl
movl %eax, %edx
andl $-0x10, %edx
cmpl $0x71, %edx
setae %dl
orb %cl, %dl
jne 0x9dff8
cmpq $0x2, %r14
jb 0x9e007
movl 0x1c0(%rbx), %edi
cmpl $0x3fff, %edi           # imm = 0x3FFF
ja 0x9e007
movl 0x1bc(%rbx), %ecx
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x9e007
movzbl 0x252(%rbx), %edx
imull %edx, %ecx
movzbl 0x24f(%rbx), %edx
imull %ecx, %edx
addl $0xf, %edx
shrl $0x3, %edx
movl %eax, %ecx
shrl $0x4, %ecx
movl $0x80, %esi
shll %cl, %esi
imull %edi, %edx
cmpl %esi, %edx
seta %dil
cmpl $0x100, %esi            # imm = 0x100
setb %r8b
orb %dil, %r8b
jne 0x9dfb3
movl %esi, %edi
decl %ecx
shrl %edi
cmpl %edi, %edx
ja 0x9dfb3
cmpl $0x1ff, %esi            # imm = 0x1FF
movl %edi, %esi
ja 0x9dfa1
shll $0x4, %ecx
orl $0x8, %ecx
movzbl %cl, %edx
cmpl %eax, %edx
je 0x9e007
movb %cl, (%r15)
movzbl 0x1(%r15), %eax
andl $-0x20, %eax
shll $0x8, %ecx
orl %eax, %ecx
imulq $0x8421085, %rcx, %rdx  # imm = 0x8421085
shrq $0x20, %rdx
subl %edx, %ecx
shrl %ecx
addl %edx, %ecx
shrl $0x4, %ecx
movl %ecx, %edx
shll $0x5, %edx
subl %edx, %ecx
addl %eax, %ecx
orl %eax, %ecx
xorb $0x1f, %cl
movb %cl, 0x1(%r15)
jmp 0x9e007
leaq 0x15dc8(%rip), %rsi     # 0xb3dc7
movq %rbx, %rdi
callq 0x920b4
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x9d8bd
orb $0x4, 0x11c(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq