// File: /workspace/github_c_makefile_star2_O3/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, %r13d
movl %esi, %r15d
movq %rdi, %r12
movl $0x4df80, %edi          # imm = 0x4DF80
callq 0x10f0
movq $0x0, (%rbx)
testq %rax, %rax
je 0x5fc3
movq %rax, %r14
movl %ebp, 0x8(%rsp)
movl %r15d, 0x4(%rsp)
imull %r15d, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x1, 0x28(%rsp)
leal 0x1(%rbp), %eax
movl %r13d, 0xc(%rsp)
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 0x5fa4
movq %rbx, 0x38(%rsp)
movq %rsp, %r15
movl $0x29, (%r15)
movl $0x28, %ebx
leaq 0x10(%rsp), %r13
movq %r15, %rdi
movl $0x1, %esi
movq %r13, %rdx
callq 0x5c7b
movl %ebx, (%rsp)
addl $-0x1, %ebx
jb 0x5df7
leaq -0x19b(%rip), %rsi      # 0x5c7b
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movl $0x1080, %ecx           # imm = 0x1080
callq 0x1a64
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
jle 0x5e62
movslq %ebp, %r13
movl %ebx, %ebp
movq %rsp, %r15
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5b53
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x5b53
addq %r13, %r12
decq %rbp
jne 0x5e38
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0x5b53
cmpl $0x1, %eax
jne 0x5fb1
movq 0x10(%rsp), %rax
addq $-0x29, %rax
movq 0x38(%rsp), %r12
movq %rax, (%r12)
leaq 0x4c(%rsp), %rsi
movaps 0x2fd3(%rip), %xmm0     # 0x8e70
movaps %xmm0, -0xc(%rsi)
movw %r15w, 0x4(%rsi)
movl 0x4(%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 0x8(%rsp), %rcx
leaq 0x266f(%rip), %rdx      # 0x853c
movb (%rcx,%rdx), %cl
movb %cl, 0xd(%rsi)
movl %eax, %ecx
shrl $0x18, %ecx
movl %r15d, 0xe(%rsi)
movl %r15d, 0x11(%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 0x1874
movl $0x1d, %ecx
movl %eax, %edx
shrl $0x18, %edx
movb %dl, 0x40(%rsp,%rcx)
shll $0x8, %eax
incq %rcx
cmpq $0x21, %rcx
jne 0x5f0a
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 0x25f9(%rip), %rdi      # 0x8542
movl $0x10, %esi
callq 0x5c7b
testl %eax, %eax
je 0x5fa9
movq 0x20(%rsp), %rsi
addq $0x25, %rsi
movq (%r12), %rdx
addq $0x4, %rdx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x1874
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 0x5f71
addq $0x39, (%r12)
movq %r14, %rdi
callq 0x1030
movq 0x20(%rsp), %rax
jmp 0x5fc5
movq %r14, %rdi
jmp 0x5fbe
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