// File: /workspace/github_cpp_makefile_star2_O3/jimmiebergmann[P]fbx-file/miniz.c
// Function: tdefl_write_image_to_png_file_in_memory_ex
void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip)
{
    /* Using a local copy of this array here in case MINIZ_NO_ZLIB_APIS was defined. */
    static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
    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, s_tdefl_png_num_probes[MZ_MIN(10, level)] | 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 + (flip ? (h - 1 - y) : 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;
    {
        static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
        mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d,
                                0x0a, 0x1a, 0x0a, 0x00, 0x00,
                                0x00, 0x0d, 0x49, 0x48, 0x44,
                                0x52, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x08,
                                0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x49, 0x44, 0x41,
                                0x54 };
        pnghdr[18] = (mz_uint8)(w >> 8);
        pnghdr[19] = (mz_uint8)w;
        pnghdr[22] = (mz_uint8)(h >> 8);
        pnghdr[23] = (mz_uint8)h;
        pnghdr[25] = chans[num_chans];
        pnghdr[33] = (mz_uint8)(*pLen_out >> 24);
        pnghdr[34] = (mz_uint8)(*pLen_out >> 16);
        pnghdr[35] = (mz_uint8)(*pLen_out >> 8);
        pnghdr[36] = (mz_uint8)*pLen_out;
        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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, -0x40(%rbp)
movq %r8, %rbx
movl %ecx, -0x2c(%rbp)
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r13
movl $0x4df78, %edi          # imm = 0x4DF78
callq 0x3320
movq $0x0, (%rbx)
testq %rax, %rax
je 0x7aad
movq %rax, %r14
movq %r13, -0x70(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %r13d
movl %r15d, -0x3c(%rbp)
imull %r15d, %r13d
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movl $0x1, -0x48(%rbp)
leal 0x1(%r13), %eax
movq %r12, -0x38(%rbp)
imull %r12d, %eax
cmpl $0x41, %eax
movl $0x40, %edi
cmovgel %eax, %edi
addl $0x39, %edi
movq %rdi, -0x58(%rbp)
callq 0x3320
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x7a90
movq %rbx, -0x68(%rbp)
leaq -0x30(%rbp), %r15
movl $0x29, (%r15)
movl $0x28, %r12d
leaq -0x60(%rbp), %rbx
movq %r15, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x7721
movl %r12d, -0x30(%rbp)
addl $-0x1, %r12d
jb 0x78b8
movl -0x40(%rbp), %ecx
cmpl $0xa, %ecx
movl $0xa, %eax
cmovbl %ecx, %eax
leaq 0xec19(%rip), %rdx      # 0x16500
movl $0x1000, %ecx           # imm = 0x1000
orl (%rdx,%rax,4), %ecx
leaq -0x1d5(%rip), %rsi      # 0x7721
leaq -0x60(%rbp), %rdx
movq %r14, %rdi
callq 0x3982
cmpl $0x0, -0x38(%rbp)
jle 0x7952
movslq %r13d, %r12
movq -0x38(%rbp), %rax
leal -0x1(%rax), %ebx
xorl %r15d, %r15d
movl $0x1, %edx
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
xorl %ecx, %ecx
callq 0x75de
cmpl $0x0, 0x10(%rbp)
movl %ebx, %eax
cmovel %r15d, %eax
imull %r13d, %eax
movslq %eax, %rsi
addq -0x70(%rbp), %rsi
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x75de
incl %r15d
addl $-0x1, %ebx
jb 0x7915
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x4, %ecx
callq 0x75de
cmpl $0x1, %eax
jne 0x7a9c
movq -0x60(%rbp), %rax
addq $-0x29, %rax
movq -0x68(%rbp), %r15
movq %rax, (%r15)
movaps 0xebce(%rip), %xmm0     # 0x16550
leaq -0x94(%rbp), %rsi
movaps %xmm0, 0x4(%rsi)
movups 0xebc5(%rip), %xmm0     # 0x16559
movups %xmm0, 0xd(%rsi)
movaps 0xeba1(%rip), %xmm0     # 0x16540
movaps %xmm0, -0xc(%rsi)
movl -0x3c(%rbp), %ecx
movb %ch, -0x8e(%rbp)
movb %cl, 0x7(%rsi)
movq -0x38(%rbp), %rcx
movb %ch, -0x8a(%rbp)
movb %cl, 0xb(%rsi)
movslq -0x2c(%rbp), %rcx
leaq 0xeb65(%rip), %rdx      # 0x1652c
movb (%rcx,%rdx), %cl
movb %cl, 0xd(%rsi)
movl %eax, %ecx
shrl $0x18, %ecx
movb %cl, 0x15(%rsi)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x16(%rsi)
movb %ah, -0x7d(%rbp)
movb %al, 0x18(%rsi)
movl $0x11, %edx
xorl %edi, %edi
callq 0x3715
movl $0x1d, %ecx
movl %eax, %edx
shrl $0x18, %edx
movb %dl, -0xa0(%rbp,%rcx)
shll $0x8, %eax
incq %rcx
cmpq $0x21, %rcx
jne 0x79f4
leaq -0x60(%rbp), %rdx
movq 0x10(%rdx), %rax
movups -0x87(%rbp), %xmm0
movups %xmm0, 0x19(%rax)
movaps -0xa0(%rbp), %xmm0
movaps -0x90(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0xeb2e(%rip), %rdi      # 0x16569
movl $0x10, %esi
callq 0x7721
testl %eax, %eax
je 0x7a95
movq -0x50(%rbp), %rsi
addq $0x25, %rsi
movq (%r15), %rdx
addq $0x4, %rdx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x3715
movl %eax, %ecx
shrl $0x18, %ecx
movq -0x50(%rbp), %rdx
addq -0x60(%rbp), %rdx
movb %cl, -0x10(%rbx,%rdx)
incq %rbx
shll $0x8, %eax
cmpq $0x4, %rbx
jne 0x7a61
addq $0x39, (%r15)
movq %r14, %rdi
callq 0x32d0
movq -0x50(%rbp), %rax
jmp 0x7aaf
movq %r14, %rdi
jmp 0x7aa8
movq $0x0, (%r15)
movq %r14, %rdi
callq 0x32d0
movq -0x50(%rbp), %rdi
callq 0x32d0
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq