// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_add_mem_to_archive_file_in_place_v2
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr)
{
    mz_bool status, created_new_archive = MZ_FALSE;
    mz_zip_archive zip_archive;
    struct MZ_FILE_STAT_STRUCT file_stat;
    mz_zip_error actual_err = MZ_ZIP_NO_ERROR;

    mz_zip_zero_struct(&zip_archive);
    if ((int)level_and_flags < 0)
        level_and_flags = MZ_DEFAULT_LEVEL;

    if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > MZ_UBER_COMPRESSION))
    {
        if (pErr)
            *pErr = MZ_ZIP_INVALID_PARAMETER;
        return MZ_FALSE;
    }

    if (!mz_zip_writer_validate_archive_name(pArchive_name))
    {
        if (pErr)
            *pErr = MZ_ZIP_INVALID_FILENAME;
        return MZ_FALSE;
    }

    /* Important: The regular non-64 bit version of stat() can fail here if the file is very large, which could cause the archive to be overwritten. */
    /* So be sure to compile with _LARGEFILE64_SOURCE 1 */
    if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0)
    {
        /* Create a new archive. */
        if (!mz_zip_writer_init_file_v2(&zip_archive, pZip_filename, 0, level_and_flags))
        {
            if (pErr)
                *pErr = zip_archive.m_last_error;
            return MZ_FALSE;
        }

        created_new_archive = MZ_TRUE;
    }
    else
    {
        /* Append to an existing archive. */
        if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0))
        {
            if (pErr)
                *pErr = zip_archive.m_last_error;
            return MZ_FALSE;
        }

        if (!mz_zip_writer_init_from_reader_v2(&zip_archive, pZip_filename, level_and_flags))
        {
            if (pErr)
                *pErr = zip_archive.m_last_error;

            mz_zip_reader_end_internal(&zip_archive, MZ_FALSE);

            return MZ_FALSE;
        }
    }

    status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
    actual_err = zip_archive.m_last_error;

    /* Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) */
    if (!mz_zip_writer_finalize_archive(&zip_archive))
    {
        if (!actual_err)
            actual_err = zip_archive.m_last_error;

        status = MZ_FALSE;
    }

    if (!mz_zip_writer_end_internal(&zip_archive, status))
    {
        if (!actual_err)
            actual_err = zip_archive.m_last_error;

        status = MZ_FALSE;
    }

    if ((!status) && (created_new_archive))
    {
        /* It's a new archive and something went wrong, so just delete it. */
        int ignoredStatus = MZ_DELETE_FILE(pZip_filename);
        (void)ignoredStatus;
    }

    if (pErr)
        *pErr = actual_err;

    return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movw %r9w, %ax
movq 0x18(%rbp), %r9
movl 0x10(%rbp), %r9d
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movw %ax, -0x32(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x144(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xbba0
cmpl $0x0, 0x10(%rbp)
jge 0x1c699
movl $0x6, 0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1c6ce
cmpq $0x0, -0x18(%rbp)
je 0x1c6ce
cmpq $0x0, -0x28(%rbp)
je 0x1c6b5
cmpq $0x0, -0x20(%rbp)
je 0x1c6ce
cmpw $0x0, -0x32(%rbp)
je 0x1c6c3
cmpq $0x0, -0x30(%rbp)
je 0x1c6ce
movl 0x10(%rbp), %eax
andl $0xf, %eax
cmpl $0xa, %eax
jbe 0x1c6eb
cmpq $0x0, 0x18(%rbp)
je 0x1c6df
movq 0x18(%rbp), %rax
movl $0x18, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1c8e0
movq -0x18(%rbp), %rdi
callq 0x15220
cmpl $0x0, %eax
jne 0x1c716
cmpq $0x0, 0x18(%rbp)
je 0x1c70a
movq 0x18(%rbp), %rax
movl $0x19, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1c8e0
movq -0x10(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3530
cmpl $0x0, %eax
je 0x1c772
movq -0x10(%rbp), %rsi
movl 0x10(%rbp), %ecx
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x13020
cmpl $0x0, %eax
jne 0x1c766
cmpq $0x0, 0x18(%rbp)
je 0x1c75a
movl -0x94(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1c8e0
movl $0x1, -0x3c(%rbp)
jmp 0x1c7fe
movq -0x10(%rbp), %rsi
movl 0x10(%rbp), %edx
orl $0x800, %edx            # imm = 0x800
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0xd2e0
cmpl $0x0, %eax
jne 0x1c7b7
cmpq $0x0, 0x18(%rbp)
je 0x1c7ab
movl -0x94(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1c8e0
movq -0x10(%rbp), %rsi
movl 0x10(%rbp), %edx
leaq -0xb0(%rbp), %rdi
callq 0x133d0
cmpl $0x0, %eax
jne 0x1c7fc
cmpq $0x0, 0x18(%rbp)
je 0x1c7e2
movl -0x94(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0xbbf0
movl $0x0, -0x4(%rbp)
jmp 0x1c8e0
jmp 0x1c7fe
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movw -0x32(%rbp), %r9w
movl 0x10(%rbp), %eax
leaq -0xb0(%rbp), %rdi
xorl %r10d, %r10d
xorl %r10d, %r10d
movzwl %r9w, %r9d
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x13910
movl %eax, -0x38(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x144(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1b5d0
cmpl $0x0, %eax
jne 0x1c87c
cmpl $0x0, -0x144(%rbp)
jne 0x1c875
movl -0x94(%rbp), %eax
movl %eax, -0x144(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0x12d90
cmpl $0x0, %eax
jne 0x1c8ac
cmpl $0x0, -0x144(%rbp)
jne 0x1c8a5
movl -0x94(%rbp), %eax
movl %eax, -0x144(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x1c8c7
cmpl $0x0, -0x3c(%rbp)
je 0x1c8c7
movq -0x10(%rbp), %rdi
callq 0x3590
movl %eax, -0x148(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x1c8da
movl -0x144(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)