// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2fb8, %rsp           # imm = 0x2FB8
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x8f83
movq %rdi, %rbx
cmpq $0x0, 0x68(%rdi)
je 0x8f7c
movq %rcx, %r15
movq %rdx, %r12
testq %rcx, %rcx
setne %al
testq %rdx, %rdx
sete %cl
testb %al, %cl
jne 0x8f7c
cmpq $0x0, 0x10(%rbp)
setne %al
testq %r9, %r9
sete %cl
testb %al, %cl
jne 0x8f7c
cmpq $0x0, 0x48(%rbx)
je 0x8f7c
movl %r8d, %r13d
movq %r9, -0x48(%rbp)
leaq -0x4d8(%rbp), %rdx
movq %rbx, %rdi
callq 0x92a9
testl %eax, %eax
je 0x8f83
cmpl $0x0, -0x48c(%rbp)
sete %al
movq -0x4b0(%rbp), %rdx
testq %rdx, %rdx
setne %cl
andb %al, %cl
pushq $0x1
popq %rax
cmpb $0x1, %cl
jne 0x921e
testb $0x61, -0x4c4(%rbp)
je 0x8f98
movl $0x5, 0x1c(%rbx)
jmp 0x8f83
movl $0x18, 0x1c(%rbx)
movl %r14d, %eax
addq $0x2fb8, %rsp           # imm = 0x2FB8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0xa, %r13d
jb 0x8fb7
movzwl -0x4c2(%rbp), %eax
andl $-0x9, %eax
testw %ax, %ax
je 0x8fb7
movl $0x4, 0x1c(%rbx)
jmp 0x8f83
btl $0xa, %r13d
jb 0x8fc5
movq -0x4a8(%rbp), %rdx
cmpq %r15, %rdx
jbe 0x8fd3
movl $0x1a, 0x1c(%rbx)
jmp 0x8f83
movq %rdx, -0x30(%rbp)
movq -0x498(%rbp), %r15
movq 0x60(%rbx), %rdi
leaq -0x80(%rbp), %rdx
pushq $0x1e
popq %rcx
movq %r15, %rsi
callq *0x48(%rbx)
cmpq $0x1e, %rax
jne 0x91e1
cmpl $0x4034b50, -0x80(%rbp) # imm = 0x4034B50
jne 0x9024
movzwl -0x66(%rbp), %ecx
movzwl -0x64(%rbp), %eax
addq %rcx, %r15
leaq (%r15,%rax), %rcx
movq -0x4b0(%rbp), %rdx
addq %rdx, %rcx
addq $0x1e, %rcx
cmpq (%rbx), %rcx
jbe 0x9030
movl $0x9, 0x1c(%rbx)
jmp 0x8f83
leaq (%rax,%r15), %rsi
addq $0x1e, %rsi
btl $0xa, %r13d
jb 0x918f
cmpw $0x0, -0x4c2(%rbp)
je 0x918f
andl $0x0, -0x2fd0(%rbp)
movq 0x68(%rbx), %rax
movq 0x80(%rax), %rax
testq %rax, %rax
movq %rsi, -0x50(%rbp)
je 0x91ed
addq %rsi, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq %rdx, -0x40(%rbp)
movq %rdx, %r14
xorl %r13d, %r13d
xorl %r15d, %r15d
movq -0x4a8(%rbp), %rax
subq %r13, %rax
movq %rax, -0x58(%rbp)
testq %r14, %r14
je 0x90a9
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
jmp 0x9105
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
je 0x90c4
xorl %r14d, %r14d
jmp 0x9105
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
movq %rcx, %r14
cmovbq %rax, %r14
movq 0x60(%rbx), %rdi
movq -0x50(%rbp), %r15
movq %r15, %rsi
movq %rcx, -0x30(%rbp)
movq %r14, %rcx
callq *0x48(%rbx)
cmpq %r14, %rax
jne 0x926e
addq %r14, %r15
movq %r15, -0x50(%rbp)
movq -0x30(%rbp), %rcx
subq %r14, %rcx
xorl %r15d, %r15d
movq -0x38(%rbp), %rdx
movq %r14, -0x60(%rbp)
leaq (%rdx,%r15), %rsi
leaq (%r12,%r13), %r8
xorl %eax, %eax
movq %rcx, -0x30(%rbp)
testq %rcx, %rcx
setne %al
leal 0x4(%rax,%rax), %eax
movl %eax, (%rsp)
leaq -0x2fd0(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %r12, %rcx
leaq -0x58(%rbp), %r9
callq 0x53b1
movq -0x60(%rbp), %rcx
subq %rcx, %r14
addq %rcx, %r15
addq -0x58(%rbp), %r13
cmpl $0x1, %eax
je 0x908c
testl %eax, %eax
jne 0x9275
cmpq -0x4a8(%rbp), %r13
jne 0x9226
xorl %r14d, %r14d
xorl %edi, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x36e2
movl -0x4b8(%rbp), %ecx
cmpq %rcx, %rax
jne 0x9265
pushq $0x1
popq %r14
jmp 0x9278
movq 0x60(%rbx), %rdi
movq %r12, %rdx
movq -0x30(%rbp), %r15
movq %r15, %rcx
callq *0x48(%rbx)
cmpq %r15, %rax
jne 0x91e1
btl $0xa, %r13d
jb 0x921b
movq -0x4a8(%rbp), %rdx
xorl %edi, %edi
movq %r12, %rsi
callq 0x36e2
movl -0x4b8(%rbp), %ecx
pushq $0x1
popq %rdx
movl %edx, %r14d
cmpq %rcx, %rax
je 0x8f83
movl $0xe, 0x1c(%rbx)
xorl %r14d, %r14d
jmp 0x8f83
movl $0x14, 0x1c(%rbx)
jmp 0x8f83
cmpq $0x0, -0x48(%rbp)
je 0x922f
xorl %r14d, %r14d
cmpq $0x0, 0x10(%rbp)
je 0x8f83
movq %rdx, -0x30(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x9086
pushq $0x1
popq %rax
movl %eax, %r14d
jmp 0x8f83
movl $0xd, 0x1c(%rbx)
jmp 0x9275
movl $0x10000, %eax          # imm = 0x10000
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq 0x40(%rbx), %rdi
pushq $0x1
popq %rsi
movq %rdx, -0x40(%rbp)
callq *0x28(%rbx)
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x929d
movq -0x4b0(%rbp), %rax
movq %rax, -0x30(%rbp)
xorl %r14d, %r14d
jmp 0x9086
movl $0xe, 0x1c(%rbx)
jmp 0x9278
movl $0xb, 0x1c(%rbx)
xorl %r14d, %r14d
movq 0x68(%rbx), %rax
movq -0x48(%rbp), %rcx
orq 0x80(%rax), %rcx
jne 0x8f83
movq 0x40(%rbx), %rdi
movq -0x38(%rbp), %rsi
callq *0x30(%rbx)
jmp 0x8f83
movl $0x10, 0x1c(%rbx)
jmp 0x8f83