// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %r9d, -0x44(%rbp)
movq %r8, %rbx
movl %ecx, %r14d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, -0x90(%rbp)
movl $0x4df78, %edi          # imm = 0x4DF78
callq 0x3330
andq $0x0, (%rbx)
testq %rax, %rax
je 0x77d1
movq %rax, %r13
movl %r14d, %eax
movl %r12d, -0x40(%rbp)
imull %r12d, %eax
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movl $0x1, -0x58(%rbp)
movq %rax, -0x80(%rbp)
incl %eax
movq %r15, -0x78(%rbp)
imull %r15d, %eax
cmpl $0x41, %eax
pushq $0x40
popq %rdi
cmovgel %eax, %edi
addl $0x39, %edi
movq %rdi, -0x68(%rbp)
callq 0x3330
movq %rax, -0x60(%rbp)
testq %rax, %rax
je 0x7730
movl %r14d, -0x3c(%rbp)
movq %r13, -0x38(%rbp)
movq %rbx, -0x88(%rbp)
pushq $0x29
popq %r14
leaq -0x2c(%rbp), %rbx
pushq $0x1
popq %r15
leaq -0x70(%rbp), %r12
movl %r14d, -0x2c(%rbp)
subl $0x1, %r14d
jb 0x75e1
movq %rbx, %rdi
movl %r15d, %esi
movq %r12, %rdx
callq 0x742f
jmp 0x75c7
movl -0x44(%rbp), %ecx
cmpl $0xa, %ecx
pushq $0xa
popq %rax
cmovbl %ecx, %eax
leaq 0xdf0c(%rip), %rdx      # 0x15500
movl $0x1000, %ecx           # imm = 0x1000
orl (%rdx,%rax,4), %ecx
leaq -0x1d4(%rip), %rsi      # 0x742f
leaq -0x70(%rbp), %rdx
movq -0x38(%rbp), %rdi
callq 0x3932
xorl %r14d, %r14d
movq -0x78(%rbp), %rax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
movslq -0x80(%rbp), %r12
leal -0x1(%rax), %ebx
movq -0x38(%rbp), %r13
cmpl %r14d, %r15d
je 0x7670
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x72f1
cmpl $0x0, 0x10(%rbp)
movl %ebx, %eax
cmovel %r14d, %eax
imull -0x80(%rbp), %eax
movslq %eax, %rsi
addq -0x90(%rbp), %rsi
movq %r13, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x72f1
incl %r14d
decl %ebx
jmp 0x762e
pushq $0x4
popq %rcx
movq -0x38(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x72f1
cmpl $0x1, %eax
jne 0x77c0
movq -0x70(%rbp), %rax
addq $-0x29, %rax
movq -0x88(%rbp), %r14
movq %rax, (%r14)
movaps 0xdeab(%rip), %xmm0     # 0x15550
leaq -0xb4(%rbp), %rsi
movaps %xmm0, 0x4(%rsi)
movups 0xdea2(%rip), %xmm0     # 0x15559
movups %xmm0, 0xd(%rsi)
movaps 0xde7e(%rip), %xmm0     # 0x15540
movaps %xmm0, -0xc(%rsi)
movl -0x40(%rbp), %ecx
movb %ch, -0xae(%rbp)
movb %cl, 0x7(%rsi)
movq -0x78(%rbp), %rcx
movb %ch, -0xaa(%rbp)
movb %cl, 0xb(%rsi)
movslq -0x3c(%rbp), %rcx
leaq 0xde42(%rip), %rdx      # 0x1552c
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, -0x9d(%rbp)
movb %al, 0x18(%rsi)
pushq $0x11
popq %rdx
xorl %edi, %edi
callq 0x36e2
pushq $0x1d
popq %rcx
cmpq $0x21, %rcx
je 0x7738
movl %eax, %edx
shrl $0x18, %edx
movb %dl, -0xc0(%rbp,%rcx)
shll $0x8, %eax
incq %rcx
jmp 0x7716
movq %r13, %rdi
jmp 0x77cc
leaq -0x70(%rbp), %rdx
movq 0x10(%rdx), %rax
movups -0xa7(%rbp), %xmm0
movups %xmm0, 0x19(%rax)
movaps -0xc0(%rbp), %xmm0
movaps -0xb0(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0xde02(%rip), %rdi      # 0x15569
pushq $0x10
popq %rsi
callq 0x742f
testl %eax, %eax
je 0x77bc
movq -0x60(%rbp), %rsi
addq $0x25, %rsi
movq (%r14), %rdx
addq $0x4, %rdx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x36e2
cmpq $0x4, %rbx
je 0x77aa
movl %eax, %ecx
movq -0x60(%rbp), %rdx
addq -0x70(%rbp), %rdx
shrl $0x18, %ecx
movb %cl, -0x10(%rbx,%rdx)
incq %rbx
shll $0x8, %eax
jmp 0x778b
addq $0x39, (%r14)
movq %r15, %rdi
callq 0x32d0
movq -0x60(%rbp), %rax
jmp 0x77d3
andq $0x0, (%r14)
movq %r15, %rdi
callq 0x32d0
movq -0x60(%rbp), %rdi
callq 0x32d0
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq