// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_extract_to_mem_no_alloc
mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
{
    int status = TINFL_STATUS_DONE;
    mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
    mz_zip_archive_file_stat file_stat;
    void *pRead_buf;
    mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
    mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
    tinfl_decompressor inflator;

    if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);

    if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
        return MZ_FALSE;

    /* A directory or zero length file */
    if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
        return MZ_TRUE;

    /* Encryption and patch files are not supported. */
    if (file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG))
        return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);

    /* This function only supports decompressing stored and deflate. */
    if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
        return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);

    /* Ensure supplied output buffer is large enough. */
    needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
    if (buf_size < needed_size)
        return mz_zip_set_error(pZip, MZ_ZIP_BUF_TOO_SMALL);

    /* Read and parse the local directory entry. */
    cur_file_ofs = file_stat.m_local_header_ofs;
    if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
        return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);

    if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);

    cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
    if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
        return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);

    if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
    {
        /* The file is stored or the caller has requested the compressed data. */
        if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size)
            return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);

#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
        if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) == 0)
        {
            if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
                return mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED);
        }
#endif

        return MZ_TRUE;
    }

    /* Decompress the file either directly from memory or from a file input buffer. */
    tinfl_init(&inflator);

    if (pZip->m_pState->m_pMem)
    {
        /* Read directly from the archive in memory. */
        pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
        read_buf_size = read_buf_avail = file_stat.m_comp_size;
        comp_remaining = 0;
    }
    else if (pUser_read_buf)
    {
        /* Use a user provided read buffer. */
        if (!user_read_buf_size)
            return MZ_FALSE;
        pRead_buf = (mz_uint8 *)pUser_read_buf;
        read_buf_size = user_read_buf_size;
        read_buf_avail = 0;
        comp_remaining = file_stat.m_comp_size;
    }
    else
    {
        /* Temporarily allocate a read buffer. */
        read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
        if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
            return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);

        if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
            return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);

        read_buf_avail = 0;
        comp_remaining = file_stat.m_comp_size;
    }

    do
    {
        /* The size_t cast here should be OK because we've verified that the output buffer is >= file_stat.m_uncomp_size above */
        size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs);
        if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
        {
            read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
            if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
            {
                status = TINFL_STATUS_FAILED;
                mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
                break;
            }
            cur_file_ofs += read_buf_avail;
            comp_remaining -= read_buf_avail;
            read_buf_ofs = 0;
        }
        in_buf_size = (size_t)read_buf_avail;
        status = tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0));
        read_buf_avail -= in_buf_size;
        read_buf_ofs += in_buf_size;
        out_buf_ofs += out_buf_size;
    } while (status == TINFL_STATUS_NEEDS_MORE_INPUT);

    if (status == TINFL_STATUS_DONE)
    {
        /* Make sure the entire file was decompressed, and check its CRC. */
        if (out_buf_ofs != file_stat.m_uncomp_size)
        {
            mz_zip_set_error(pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE);
            status = TINFL_STATUS_FAILED;
        }
#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
        else if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
        {
            mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED);
            status = TINFL_STATUS_FAILED;
        }
#endif
    }

    if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf))
        pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);

    return status == TINFL_STATUS_DONE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30f0, %rsp           # imm = 0x30F0
movq 0x10(%rbp), %rax
movq %rdi, -0xd8(%rbp)
movl %esi, -0xdc(%rbp)
movq %rdx, -0xe8(%rbp)
movq %rcx, -0xf0(%rbp)
movl %r8d, -0xf4(%rbp)
movq %r9, -0x100(%rbp)
movl $0x0, -0x104(%rbp)
movq $0x0, -0x128(%rbp)
movq $0x0, -0x138(%rbp)
leaq -0x5c0(%rbp), %rax
movq %rax, -0x5c8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0xe541
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0xe541
cmpq $0x0, -0xf0(%rbp)
je 0xe522
cmpq $0x0, -0xe8(%rbp)
je 0xe541
cmpq $0x0, 0x10(%rbp)
je 0xe533
cmpq $0x0, -0x100(%rbp)
je 0xe541
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xe573
movq -0xd8(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x18, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xe564
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq -0xd8(%rbp), %rdi
movl -0xdc(%rbp), %esi
leaq -0x598(%rbp), %rdx
callq 0xeda0
cmpl $0x0, %eax
jne 0xe5a0
movl $0x0, -0xd0(%rbp)
jmp 0xed89
cmpl $0x0, -0x54c(%rbp)
jne 0xe5b3
cmpq $0x0, -0x570(%rbp)
jne 0xe5c2
movl $0x1, -0xd0(%rbp)
jmp 0xed89
movzwl -0x584(%rbp), %eax
andl $0x61, %eax
cmpl $0x0, %eax
je 0xe603
movq -0xd8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x5, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xe5f4
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movl -0xf4(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xe65d
movzwl -0x582(%rbp), %eax
cmpl $0x0, %eax
je 0xe65d
movzwl -0x582(%rbp), %eax
cmpl $0x8, %eax
je 0xe65d
movq -0xd8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x4, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xe64e
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movl -0xf4(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xe67d
movq -0x570(%rbp), %rax
movq %rax, -0x30d8(%rbp)
jmp 0xe68b
movq -0x568(%rbp), %rax
movq %rax, -0x30d8(%rbp)
movq -0x30d8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xf0(%rbp), %rax
cmpq -0x110(%rbp), %rax
jae 0xe6db
movq -0xd8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x1a, -0x3c(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xe6cc
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq -0x558(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0xd8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0xd8(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0x118(%rbp), %rsi
movq -0x5c8(%rbp), %rdx
movl $0x1e, %ecx
callq *%rax
cmpq $0x1e, %rax
je 0xe74c
movq -0xd8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x14, -0x4c(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xe73d
movl -0x4c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq -0x5c8(%rbp), %rax
cmpl $0x4034b50, (%rax)      # imm = 0x4034B50
je 0xe78d
movq -0xd8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x9, -0x5c(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0xe77e
movl -0x5c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq -0x5c8(%rbp), %rax
movzwl 0x1a(%rax), %eax
addl $0x1e, %eax
movq -0x5c8(%rbp), %rcx
movzwl 0x1c(%rcx), %ecx
addl %ecx, %eax
cltq
addq -0x118(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
addq -0x570(%rbp), %rax
movq -0xd8(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0xe804
movq -0xd8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x9, -0x6c(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe7f5
movl -0x6c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movl -0xf4(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xe822
cmpw $0x0, -0x582(%rbp)
jne 0xe90e
movq -0xd8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0xd8(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0x118(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq -0x110(%rbp), %rcx
callq *%rax
cmpq -0x110(%rbp), %rax
je 0xe88a
movq -0xd8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x14, -0x7c(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0xe87b
movl -0x7c(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movl -0xf4(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xe8ff
movq -0xe8(%rbp), %rsi
movq -0x568(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0x3910
movl -0x578(%rbp), %ecx
cmpq %rcx, %rax
je 0xe8fd
movq -0xd8(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0xe, -0x8c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0xe8ee
movl -0x8c(%rbp), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
jmp 0xe8ff
movl $0x1, -0xd0(%rbp)
jmp 0xed89
jmp 0xe910
movl $0x0, -0x30c0(%rbp)
movq -0xd8(%rbp), %rax
movq 0x68(%rax), %rax
cmpq $0x0, 0x80(%rax)
je 0xe974
movq -0xd8(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x80(%rax), %rax
addq -0x118(%rbp), %rax
movq %rax, -0x5a0(%rbp)
movq -0x570(%rbp), %rax
movq %rax, -0x140(%rbp)
movq %rax, -0x130(%rbp)
movq $0x0, -0x120(%rbp)
jmp 0xea95
cmpq $0x0, -0x100(%rbp)
je 0xe9cb
cmpq $0x0, 0x10(%rbp)
jne 0xe994
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq -0x100(%rbp), %rax
movq %rax, -0x5a0(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
movq $0x0, -0x140(%rbp)
movq -0x570(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0xea93
cmpq $0x10000, -0x570(%rbp) # imm = 0x10000
jae 0xe9e8
movq -0x570(%rbp), %rax
movq %rax, -0x30e0(%rbp)
jmp 0xe9f6
movl $0x10000, %eax          # imm = 0x10000
movq %rax, -0x30e0(%rbp)
jmp 0xe9f6
movq -0x30e0(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0xd8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0xd8(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0x130(%rbp), %rdx
movl $0x1, %esi
callq *%rax
movq %rax, %rcx
movq %rcx, -0x5a0(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0xea7a
movq -0xd8(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x10, -0x9c(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0xea6b
movl -0x9c(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0x0, -0xd0(%rbp)
jmp 0xed89
movq $0x0, -0x140(%rbp)
movq -0x570(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0xea95
jmp 0xea97
movq -0x568(%rbp), %rax
subq -0x128(%rbp), %rax
movq %rax, -0x30d0(%rbp)
cmpq $0x0, -0x140(%rbp)
jne 0xebbe
movq -0xd8(%rbp), %rax
movq 0x68(%rax), %rax
cmpq $0x0, 0x80(%rax)
jne 0xebbe
movq -0x130(%rbp), %rax
cmpq -0x120(%rbp), %rax
jae 0xeaf3
movq -0x130(%rbp), %rax
movq %rax, -0x30e8(%rbp)
jmp 0xeb01
movq -0x120(%rbp), %rax
movq %rax, -0x30e8(%rbp)
movq -0x30e8(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0xd8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0xd8(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0x118(%rbp), %rsi
movq -0x5a0(%rbp), %rdx
movq -0x140(%rbp), %rcx
callq *%rax
cmpq -0x140(%rbp), %rax
je 0xeb86
movl $0xffffffff, -0x104(%rbp) # imm = 0xFFFFFFFF
movq -0xd8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0xb, -0xac(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0xeb81
movl -0xac(%rbp), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0xec79
movq -0x140(%rbp), %rax
addq -0x118(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x140(%rbp), %rcx
movq -0x120(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x120(%rbp)
movq $0x0, -0x138(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x30c8(%rbp)
movq -0x5a0(%rbp), %rsi
addq -0x138(%rbp), %rsi
movq -0xe8(%rbp), %rcx
movq -0xe8(%rbp), %r8
addq -0x128(%rbp), %r8
movq -0x120(%rbp), %rdi
xorl %eax, %eax
movl $0x2, %edx
cmpq $0x0, %rdi
cmovnel %edx, %eax
orl $0x4, %eax
leaq -0x30c0(%rbp), %rdi
leaq -0x30c8(%rbp), %rdx
leaq -0x30d0(%rbp), %r9
movl %eax, (%rsp)
callq 0x5060
movl %eax, -0x104(%rbp)
movq -0x30c8(%rbp), %rcx
movq -0x140(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x140(%rbp)
movq -0x30c8(%rbp), %rax
addq -0x138(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x30d0(%rbp), %rax
addq -0x128(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpl $0x1, -0x104(%rbp)
je 0xea97
cmpl $0x0, -0x104(%rbp)
jne 0xed36
movq -0x128(%rbp), %rax
cmpq -0x568(%rbp), %rax
je 0xecd4
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0xd, -0xbc(%rbp)
cmpq $0x0, -0xb8(%rbp)
je 0xecc8
movl -0xbc(%rbp), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0xffffffff, -0x104(%rbp) # imm = 0xFFFFFFFF
jmp 0xed34
movq -0xe8(%rbp), %rsi
movq -0x568(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0x3910
movl -0x578(%rbp), %ecx
cmpq %rcx, %rax
je 0xed32
movq -0xd8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl $0xe, -0xcc(%rbp)
cmpq $0x0, -0xc8(%rbp)
je 0xed28
movl -0xcc(%rbp), %ecx
movq -0xc8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl $0xffffffff, -0x104(%rbp) # imm = 0xFFFFFFFF
jmp 0xed34
jmp 0xed36
movq -0xd8(%rbp), %rax
movq 0x68(%rax), %rax
cmpq $0x0, 0x80(%rax)
jne 0xed74
cmpq $0x0, -0x100(%rbp)
jne 0xed74
movq -0xd8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0xd8(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0x5a0(%rbp), %rsi
callq *%rax
cmpl $0x0, -0x104(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
addq $0x30f0, %rsp           # imm = 0x30F0
popq %rbp
retq
nopl (%rax,%rax)