// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl $0x4df80, %edi          # imm = 0x4DF80
callq 0x10e0
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
imull -0x1c(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x30(%rbp)
jne 0x8dc3
movq $0x0, -0x8(%rbp)
jmp 0x914f
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1090
movl $0x1, -0x38(%rbp)
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
imull -0x18(%rbp), %ecx
movl $0x40, %eax
cmpl %ecx, %eax
jle 0x8dfa
movl $0x40, %eax
movl %eax, -0x94(%rbp)
jmp 0x8e0a
movl -0x58(%rbp), %eax
addl $0x1, %eax
imull -0x18(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
addl $0x39, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x10e0
movq %rax, %rcx
movq %rcx, -0x40(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x8e46
movq -0x30(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0x914f
movl $0x29, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x8e70
leaq -0x60(%rbp), %rdi
movl $0x1, %esi
leaq -0x50(%rbp), %rdx
callq 0x8bd0
movl -0x60(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x8e4d
movq -0x30(%rbp), %rdi
leaq -0x2ab(%rip), %rsi      # 0x8bd0
leaq -0x50(%rbp), %rdx
movl $0x1080, %ecx           # imm = 0x1080
callq 0x1ff0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x8ed6
movq -0x30(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x89d0
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x5c(%rbp), %eax
imull -0x58(%rbp), %eax
cltq
addq %rax, %rsi
movslq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq 0x89d0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8e90
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x4, %ecx
movq %rdx, %rsi
callq 0x89d0
cmpl $0x1, %eax
je 0x8f0f
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0x914f
movq -0x50(%rbp), %rcx
subq $0x29, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movb $-0x77, -0x90(%rbp)
movb $0x50, -0x8f(%rbp)
movb $0x4e, -0x8e(%rbp)
movb $0x47, -0x8d(%rbp)
movb $0xd, -0x8c(%rbp)
movb $0xa, -0x8b(%rbp)
movb $0x1a, -0x8a(%rbp)
movb $0xa, -0x89(%rbp)
movb $0x0, -0x88(%rbp)
movb $0x0, -0x87(%rbp)
movb $0x0, -0x86(%rbp)
movb $0xd, -0x85(%rbp)
movb $0x49, -0x84(%rbp)
movb $0x48, -0x83(%rbp)
movb $0x44, -0x82(%rbp)
movb $0x52, -0x81(%rbp)
movb $0x0, -0x80(%rbp)
movb $0x0, -0x7f(%rbp)
movl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x7e(%rbp)
movl -0x14(%rbp), %eax
movb %al, -0x7d(%rbp)
movb $0x0, -0x7c(%rbp)
movb $0x0, -0x7b(%rbp)
movl -0x18(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x7a(%rbp)
movl -0x18(%rbp), %eax
movb %al, -0x79(%rbp)
movb $0x8, -0x78(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3571(%rip), %rax      # 0xc53c
movb (%rax,%rcx), %al
movb %al, -0x77(%rbp)
movb $0x0, -0x76(%rbp)
movb $0x0, -0x75(%rbp)
movb $0x0, -0x74(%rbp)
movb $0x0, -0x73(%rbp)
movb $0x0, -0x72(%rbp)
movb $0x0, -0x71(%rbp)
movb $0x0, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
shrq $0x18, %rax
movb %al, -0x6f(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
shrq $0x10, %rax
movb %al, -0x6e(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
shrq $0x8, %rax
movb %al, -0x6d(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movb %al, -0x6c(%rbp)
movb $0x49, -0x6b(%rbp)
movb $0x44, -0x6a(%rbp)
movb $0x41, -0x69(%rbp)
movb $0x54, -0x68(%rbp)
leaq -0x90(%rbp), %rsi
addq $0xc, %rsi
xorl %eax, %eax
movl %eax, %edi
movl $0x11, %edx
callq 0x1c20
movl %eax, -0x64(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x4, -0x54(%rbp)
jge 0x907e
movl -0x64(%rbp), %eax
shrl $0x18, %eax
movb %al, %cl
movslq -0x54(%rbp), %rax
movb %cl, -0x73(%rbp,%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x64(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x64(%rbp)
jmp 0x9054
movq -0x40(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x29, %edx
callq 0x10d0
leaq 0x34a8(%rip), %rdi      # 0xc542
movl $0x10, %esi
leaq -0x50(%rbp), %rdx
callq 0x8bd0
cmpl $0x0, %eax
jne 0x90d4
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
jmp 0x914f
movq -0x40(%rbp), %rsi
addq $0x29, %rsi
addq $-0x4, %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
addq $0x4, %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0x1c20
movl %eax, -0x64(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x4, -0x54(%rbp)
jge 0x9130
movl -0x64(%rbp), %eax
shrl $0x18, %eax
movb %al, %dl
movq -0x40(%rbp), %rax
addq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movb %dl, -0x10(%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x64(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x64(%rbp)
jmp 0x90fe
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x39, %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)