// File: /workspace/github_c_makefile_star2_O1/wkoszek[P]mini_gzip/miniz.c
// Function: tdefl_write_image_to_png_file_in_memory
void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
{
  tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); tdefl_output_buffer out_buf; int i, bpl = w * num_chans, y, z; mz_uint32 c; *pLen_out = 0;
  if (!pComp) return NULL;
  MZ_CLEAR_OBJ(out_buf); out_buf.m_expandable = MZ_TRUE; out_buf.m_capacity = 57+MZ_MAX(64, (1+bpl)*h); if (NULL == (out_buf.m_pBuf = (mz_uint8*)MZ_MALLOC(out_buf.m_capacity))) { MZ_FREE(pComp); return NULL; }
  // write dummy header
  for (z = 41; z; --z) tdefl_output_buffer_putter(&z, 1, &out_buf);
  // compress image data
  tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, TDEFL_DEFAULT_MAX_PROBES | TDEFL_WRITE_ZLIB_HEADER);
  for (y = 0; y < h; ++y) { tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, (mz_uint8*)pImage + y * bpl, bpl, TDEFL_NO_FLUSH); }
  if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) { MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; }
  // write real header
  *pLen_out = out_buf.m_size-41;
  {
    mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
      0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8,"\0\0\04\02\06"[num_chans],0,0,0,0,0,0,0,
      (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54};
    c=(mz_uint32)mz_crc32(MZ_CRC32_INIT,pnghdr+12,17); for (i=0; i<4; ++i, c<<=8) ((mz_uint8*)(pnghdr+29))[i]=(mz_uint8)(c>>24);
    memcpy(out_buf.m_pBuf, pnghdr, 41);
  }
  // write footer (IDAT CRC-32, followed by IEND chunk)
  if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) { *pLen_out = 0; MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; }
  c = (mz_uint32)mz_crc32(MZ_CRC32_INIT,out_buf.m_pBuf+41-4, *pLen_out+4); for (i=0; i<4; ++i, c<<=8) (out_buf.m_pBuf+out_buf.m_size-16)[i] = (mz_uint8)(c >> 24);
  // compute final size of file, grab compressed data buffer and return
  *pLen_out += 57; MZ_FREE(pComp); return out_buf.m_pBuf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %r15
movl %ecx, %ebp
movl %edx, %r13d
movl %esi, %ebx
movq %rdi, %r12
movl $0x4df80, %edi          # imm = 0x4DF80
callq 0x10f0
movq $0x0, (%r15)
testq %rax, %rax
je 0x5e33
movq %rax, %r14
movl %ebp, 0xc(%rsp)
movl %ebx, 0x8(%rsp)
imull %ebx, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x1, 0x28(%rsp)
leal 0x1(%rbp), %eax
imull %r13d, %eax
cmpl $0x41, %eax
movl $0x40, %edi
cmovgel %eax, %edi
addl $0x39, %edi
movq %rdi, 0x18(%rsp)
callq 0x10f0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x5e14
movl %r13d, %ebx
movq %r15, 0x38(%rsp)
leaq 0x4(%rsp), %r15
movl $0x29, (%r15)
leaq 0x10(%rsp), %r13
movq %r15, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x5afd
decl 0x4(%rsp)
jne 0x5c6b
leaq -0x18b(%rip), %rsi      # 0x5afd
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movl $0x1080, %ecx           # imm = 0x1080
callq 0x1a6e
testl %ebx, %ebx
jle 0x5cd2
movslq %ebp, %r13
movl %ebx, %ebp
leaq 0x4(%rsp), %r15
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x59d5
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x59d5
addq %r13, %r12
decq %rbp
jne 0x5ca8
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0x59d5
cmpl $0x1, %eax
jne 0x5e21
movq 0x10(%rsp), %rax
addq $-0x29, %rax
movq 0x38(%rsp), %r12
movq %rax, (%r12)
movaps 0x30f8(%rip), %xmm0     # 0x8e00
leaq 0x4c(%rsp), %rsi
movaps %xmm0, -0xc(%rsi)
movw %r15w, 0x4(%rsi)
movl 0x8(%rsp), %ecx
movb %ch, 0x52(%rsp)
movb %cl, 0x7(%rsi)
movw %r15w, 0x8(%rsi)
movb %bh, 0x56(%rsp)
movb %bl, 0xb(%rsi)
movb $0x8, 0xc(%rsi)
movslq 0xc(%rsp), %rcx
leaq 0x27ff(%rip), %rdx      # 0x853c
movb (%rcx,%rdx), %cl
movb %cl, 0xd(%rsi)
movl %eax, %ecx
shrl $0x18, %ecx
movl %r15d, 0x11(%rsi)
movl %r15d, 0xe(%rsi)
movb %cl, 0x15(%rsi)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x16(%rsi)
movb %ah, 0x63(%rsp)
movb %al, 0x18(%rsi)
movl $0x54414449, 0x19(%rsi) # imm = 0x54414449
movl $0x11, %edx
xorl %edi, %edi
callq 0x1880
movl $0x1d, %ecx
movl %eax, %edx
shrl $0x18, %edx
movb %dl, 0x40(%rsp,%rcx)
shll $0x8, %eax
incq %rcx
cmpq $0x21, %rcx
jne 0x5d7a
leaq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rax
movups 0x59(%rsp), %xmm0
movups %xmm0, 0x19(%rax)
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0x2789(%rip), %rdi      # 0x8542
movl $0x10, %esi
callq 0x5afd
testl %eax, %eax
je 0x5e19
movq 0x20(%rsp), %rsi
addq $0x25, %rsi
movq (%r12), %rdx
addq $0x4, %rdx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x1880
movl %eax, %ecx
shrl $0x18, %ecx
movq 0x20(%rsp), %rdx
addq 0x10(%rsp), %rdx
movb %cl, -0x10(%rbx,%rdx)
incq %rbx
shll $0x8, %eax
cmpq $0x4, %rbx
jne 0x5de1
addq $0x39, (%r12)
movq %r14, %rdi
callq 0x1030
movq 0x20(%rsp), %rax
jmp 0x5e35
movq %r14, %rdi
jmp 0x5e2e
movq $0x0, (%r12)
movq %r14, %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq