// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2fc8, %rsp           # imm = 0x2FC8
xorl %r15d, %r15d
testq %rdi, %rdi
je 0x9031
movq %rdi, %rbx
cmpq $0x0, 0x68(%rdi)
je 0x9022
movq %rcx, %r14
movq %rdx, %r12
testq %rcx, %rcx
setne %al
testq %rdx, %rdx
sete %cl
testb %al, %cl
jne 0x9022
cmpq $0x0, 0x10(%rbp)
setne %al
testq %r9, %r9
sete %cl
testb %al, %cl
jne 0x9022
cmpq $0x0, 0x48(%rbx)
je 0x9022
movl %r8d, %r13d
movq %r9, -0x50(%rbp)
leaq -0x4e8(%rbp), %rdx
movq %rbx, %rdi
callq 0x9372
testl %eax, %eax
je 0x9031
cmpl $0x0, -0x49c(%rbp)
sete %al
movq -0x4c0(%rbp), %rdx
testq %rdx, %rdx
setne %cl
andb %al, %cl
movl $0x1, %r15d
cmpb $0x1, %cl
jne 0x9031
testb $0x61, -0x4d4(%rbp)
je 0x9046
movl $0x5, 0x1c(%rbx)
jmp 0x902e
testq %rbx, %rbx
je 0x9031
movl $0x18, 0x1c(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x2fc8, %rsp           # imm = 0x2FC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0xa, %r13d
jb 0x9065
movzwl -0x4d2(%rbp), %eax
andl $-0x9, %eax
testw %ax, %ax
je 0x9065
movl $0x4, 0x1c(%rbx)
jmp 0x902e
btl $0xa, %r13d
jb 0x9073
movq -0x4b8(%rbp), %rdx
cmpq %r14, %rdx
jbe 0x9081
movl $0x1a, 0x1c(%rbx)
jmp 0x902e
movq %rdx, -0x40(%rbp)
movq -0x4a8(%rbp), %r14
movq 0x60(%rbx), %rdi
leaq -0x90(%rbp), %rdx
movl $0x1e, %ecx
movq %r14, %rsi
callq *0x48(%rbx)
cmpq $0x1e, %rax
jne 0x9291
cmpl $0x4034b50, -0x90(%rbp) # imm = 0x4034B50
jne 0x90de
movzwl -0x76(%rbp), %ecx
movzwl -0x74(%rbp), %eax
addq %rcx, %r14
leaq (%r14,%rax), %rcx
movq -0x4c0(%rbp), %rdx
movq %rdx, -0x38(%rbp)
addq %rdx, %rcx
addq $0x1e, %rcx
cmpq (%rbx), %rcx
jbe 0x90ea
movl $0x9, 0x1c(%rbx)
jmp 0x902e
leaq (%rax,%r14), %rsi
addq $0x1e, %rsi
btl $0xa, %r13d
jb 0x9244
cmpw $0x0, -0x4d2(%rbp)
je 0x9244
movl $0x0, -0x2fe0(%rbp)
movq 0x68(%rbx), %rax
movq 0x80(%rax), %rax
testq %rax, %rax
movq %rsi, -0x58(%rbp)
je 0x9300
addq %rsi, %rax
movq %rax, -0x30(%rbp)
xorl %ecx, %ecx
movq -0x38(%rbp), %r15
xorl %r14d, %r14d
movq $0x0, -0x48(%rbp)
movq -0x4b8(%rbp), %rax
subq %r14, %rax
movq %rax, -0x68(%rbp)
testq %r15, %r15
jne 0x9169
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x91d8
xorl %r15d, %r15d
movq -0x30(%rbp), %rax
movq %r15, -0x70(%rbp)
movq -0x48(%rbp), %r13
leaq (%rax,%r13), %rsi
leaq (%r12,%r14), %r8
xorl %eax, %eax
movq %rcx, -0x40(%rbp)
testq %rcx, %rcx
setne %al
leal 0x4(,%rax,2), %eax
movl %eax, (%rsp)
leaq -0x2fe0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
movq %r12, %rcx
leaq -0x68(%rbp), %r9
callq 0x4425
movq -0x70(%rbp), %rcx
subq %rcx, %r15
addq %rcx, %r13
movq %r13, -0x48(%rbp)
addq -0x68(%rbp), %r14
movb $0x1, %cl
testb %cl, %cl
movq -0x40(%rbp), %rcx
je 0x929d
cmpl $0x1, %eax
je 0x9145
jmp 0x929d
movq %r14, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
movq %rcx, %r15
cmovbq %rax, %r15
movq 0x60(%rbx), %rdi
movq -0x58(%rbp), %rsi
movq %rsi, %r13
movq %rcx, %r14
movq -0x30(%rbp), %rdx
movq %r15, %rcx
callq *0x48(%rbx)
cmpq %r15, %rax
jne 0x9229
addq %r15, %r13
movq %r13, -0x58(%rbp)
subq %r15, %r14
movq $0x0, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %r14, %rcx
movq -0x60(%rbp), %r14
jmp 0x916d
movq %r14, -0x40(%rbp)
movl $0xb, 0x1c(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq -0x60(%rbp), %r14
jmp 0x91be
movq 0x60(%rbx), %rdi
movq %r12, %rdx
movq -0x40(%rbp), %r14
movq %r14, %rcx
callq *0x48(%rbx)
cmpq %r14, %rax
jne 0x9291
btl $0xa, %r13d
jb 0x9031
movq -0x4b8(%rbp), %rdx
xorl %edi, %edi
movq %r12, %rsi
callq 0x3715
movl -0x4c8(%rbp), %ecx
cmpq %rcx, %rax
je 0x9031
movl $0xe, 0x1c(%rbx)
jmp 0x902e
movl $0x14, 0x1c(%rbx)
jmp 0x902e
xorl %r15d, %r15d
testl %eax, %eax
jne 0x92db
movq -0x4b8(%rbp), %rdx
movl $0xd, %ecx
cmpq %rdx, %r14
jne 0x92d5
xorl %edi, %edi
movq %r12, %rsi
callq 0x3715
movl -0x4c8(%rbp), %edx
movl $0xe, %ecx
movl $0x1, %r15d
cmpq %rdx, %rax
je 0x92db
movl %ecx, 0x1c(%rbx)
xorl %r15d, %r15d
movq 0x68(%rbx), %rax
movq -0x50(%rbp), %rcx
orq 0x80(%rax), %rcx
jne 0x9031
movq 0x40(%rbx), %rdi
movq -0x30(%rbp), %rsi
callq *0x30(%rbx)
jmp 0x9031
cmpq $0x0, -0x50(%rbp)
je 0x932e
xorl %r15d, %r15d
cmpq $0x0, 0x10(%rbp)
je 0x9031
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x913a
movl $0x10000, %eax          # imm = 0x10000
movq -0x38(%rbp), %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq 0x40(%rbx), %rdi
movl $0x1, %esi
movq %rdx, -0x38(%rbp)
callq *0x28(%rbx)
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x9366
movq -0x4c0(%rbp), %rcx
xorl %r15d, %r15d
jmp 0x913a
movl $0x10, 0x1c(%rbx)
jmp 0x902e