// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_heap_write_func(void*, unsigned long, void const*, unsigned long)
static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
{
    mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
    mz_zip_internal_state *pState = pZip->m_pState;
    mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);

    if (!n)
        return 0;

    /* An allocation this big is likely to just fail on 32-bit systems, so don't even go there. */
    if ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))
    {
        mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE);
        return 0;
    }

    if (new_size > pState->m_mem_capacity)
    {
        void *pNew_block;
        size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity);

        while (new_capacity < new_size)
            new_capacity *= 2;

        if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity)))
        {
            mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
            return 0;
        }

        pState->m_pMem = pNew_block;
        pState->m_mem_capacity = new_capacity;
    }
    memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n);
    pState->m_mem_size = (size_t)new_size;
    return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jbe 0x12c3f
movq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x12c4e
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x12c6a
movq $0x0, -0x18(%rbp)
jmp 0x12d79
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x90(%rcx), %rax
jbe 0x12d46
movq -0x48(%rbp), %rcx
movl $0x40, %eax
cmpq 0x90(%rcx), %rax
jbe 0x12c9c
movl $0x40, %eax
movq %rax, -0x70(%rbp)
jmp 0x12cab
movq -0x48(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x12cca
movq -0x60(%rbp), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x12cb3
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0x48(%rbp), %rcx
movq 0x80(%rcx), %rsi
movq -0x60(%rbp), %rcx
movl $0x1, %edx
callq *%rax
movq %rax, %rcx
movq %rcx, -0x58(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x12d28
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x10, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x12d1e
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq $0x0, -0x18(%rbp)
jmp 0x12d79
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x48(%rbp), %rax
movq 0x80(%rax), %rdi
addq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x3280
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)