// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movl %ecx, %ebp
movl %edx, %r15d
movl %esi, %r13d
movq %rdi, %r12
movl $0x4df80, %edi          # imm = 0x4DF80
callq 0x10f0
andq $0x0, (%rbx)
testq %rax, %rax
je 0x596f
movq %rax, %r14
movl %ebp, %eax
movl %r13d, 0xc(%rsp)
imull %r13d, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x1, 0x28(%rsp)
movq %rax, 0x38(%rsp)
incl %eax
movl %r15d, (%rsp)
imull %r15d, %eax
cmpl $0x41, %eax
pushq $0x40
popq %rdi
cmovgel %eax, %edi
addl $0x39, %edi
movq %rdi, 0x18(%rsp)
callq 0x10f0
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x58ce
movl %ebp, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
pushq $0x29
popq %rbx
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rbp
leaq 0x10(%rsp), %r13
movl %ebx, 0x4(%rsp)
subl $0x1, %ebx
jb 0x57bb
movq %r15, %rdi
movl %ebp, %esi
movq %r13, %rdx
callq 0x562d
jmp 0x57a3
leaq -0x195(%rip), %rsi      # 0x562d
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movl $0x1080, %ecx           # imm = 0x1080
callq 0x19cc
movslq 0x38(%rsp), %r13
xorl %ebx, %ebx
movl (%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ebx
leaq 0x4(%rsp), %r15
pushq $0x1
popq %rbp
subq $0x1, %rbx
jb 0x5816
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x550d
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x550d
addq %r13, %r12
jmp 0x57eb
pushq $0x4
popq %rcx
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x550d
cmpl $0x1, %eax
jne 0x595d
movq 0x10(%rsp), %rax
addq $-0x29, %rax
movq 0x30(%rsp), %r15
movq %rax, (%r15)
leaq 0x4c(%rsp), %rsi
movaps 0x25c5(%rip), %xmm0     # 0x7e10
movaps %xmm0, -0xc(%rsi)
andw $0x0, 0x4(%rsi)
movl 0xc(%rsp), %ecx
movb %ch, 0x52(%rsp)
movb %cl, 0x7(%rsi)
andw $0x0, 0x8(%rsi)
movl (%rsp), %ecx
movb %ch, 0x56(%rsp)
movb %cl, 0xb(%rsi)
movb $0x8, 0xc(%rsi)
movslq 0x8(%rsp), %rcx
leaq 0x1cbe(%rip), %rdx      # 0x753c
movb (%rcx,%rdx), %cl
movb %cl, 0xd(%rsi)
andl $0x0, 0xe(%rsi)
movl %eax, %ecx
andl $0x0, 0x11(%rsi)
shrl $0x18, %ecx
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
pushq $0x11
popq %rdx
xorl %edi, %edi
callq 0x17fb
pushq $0x1d
popq %rcx
cmpq $0x21, %rcx
je 0x58d6
movl %eax, %edx
shrl $0x18, %edx
movb %dl, 0x40(%rsp,%rcx)
shll $0x8, %eax
incq %rcx
jmp 0x58b7
movq %r14, %rdi
jmp 0x596a
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 0x1c42(%rip), %rdi      # 0x7542
pushq $0x10
popq %rsi
callq 0x562d
testl %eax, %eax
je 0x5959
movq 0x20(%rsp), %rsi
addq $0x25, %rsi
movq (%r15), %rdx
addq $0x4, %rdx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x17fb
cmpq $0x4, %rbx
je 0x5946
movl %eax, %ecx
movq 0x20(%rsp), %rdx
addq 0x10(%rsp), %rdx
shrl $0x18, %ecx
movb %cl, -0x10(%rbx,%rdx)
incq %rbx
shll $0x8, %eax
jmp 0x5925
addq $0x39, (%r15)
movq %r14, %rdi
callq 0x1030
movq 0x20(%rsp), %rax
jmp 0x5971
andq $0x0, (%r15)
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