// File: /workspace/github_cpp_makefile_star2_O2/jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_extract_to_callback
mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
{
    int status = TINFL_STATUS_DONE;
    mz_uint file_crc32 = MZ_CRC32_INIT;
    mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
    mz_zip_archive_file_stat file_stat;
    void *pRead_buf = NULL;
    void *pWrite_buf = NULL;
    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;

    if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!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);

    /* Read and do some minimal validation of the local directory entry (this doesn't crack the zip64 stuff, which we already have from the central dir) */
    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);

    /* Decompress the file either directly from memory or from a file input buffer. */
    if (pZip->m_pState->m_pMem)
    {
        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
    {
        read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
        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;
    }

    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_pState->m_pMem)
        {
            if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX))
                return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);

            if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
            {
                mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
                status = TINFL_STATUS_FAILED;
            }
            else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
            {
#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
                file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size);
#endif
            }

            cur_file_ofs += file_stat.m_comp_size;
            out_buf_ofs += file_stat.m_comp_size;
            comp_remaining = 0;
        }
        else
        {
            while (comp_remaining)
            {
                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)
                {
                    mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
                    status = TINFL_STATUS_FAILED;
                    break;
                }

#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
                if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
                {
                    file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)read_buf_avail);
                }
#endif

                if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
                {
                    mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
                    status = TINFL_STATUS_FAILED;
                    break;
                }

                cur_file_ofs += read_buf_avail;
                out_buf_ofs += read_buf_avail;
                comp_remaining -= read_buf_avail;
            }
        }
    }
    else
    {
        tinfl_decompressor inflator;
        tinfl_init(&inflator);

        if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
        {
            mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
            status = TINFL_STATUS_FAILED;
        }
        else
        {
            do
            {
                mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
                size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
                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)
                    {
                        mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
                        status = TINFL_STATUS_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, (const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
                read_buf_avail -= in_buf_size;
                read_buf_ofs += in_buf_size;

                if (out_buf_size)
                {
                    if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
                    {
                        mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
                        status = TINFL_STATUS_FAILED;
                        break;
                    }

#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
                    file_crc32 = (mz_uint32)mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size);
#endif
                    if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size)
                    {
                        mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
                        status = TINFL_STATUS_FAILED;
                        break;
                    }
                }
            } while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT));
        }
    }

    if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
    {
        /* 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 (file_crc32 != file_stat.m_crc32)
        {
            mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
            status = TINFL_STATUS_FAILED;
        }
#endif
    }

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

    if (pWrite_buf)
        pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf);

    return status == TINFL_STATUS_DONE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2ff8, %rsp           # imm = 0x2FF8
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x950e
movq %rdx, %r12
movq %rdi, %rbx
testq %rdx, %rdx
je 0x9504
cmpq $0x0, 0x68(%rbx)
je 0x9504
cmpq $0x0, 0x48(%rbx)
je 0x9504
movl %r8d, %r15d
movq %rcx, %r13
leaq -0x518(%rbp), %rdx
movq %rbx, %rdi
callq 0x92a9
testl %eax, %eax
je 0x950e
cmpl $0x0, -0x4cc(%rbp)
pushq $0x1
popq %r14
jne 0x950e
cmpq $0x0, -0x4f0(%rbp)
je 0x950e
testb $0x61, -0x504(%rbp)
je 0x9523
movl $0x5, 0x1c(%rbx)
jmp 0x950b
movl $0x18, 0x1c(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x2ff8, %rsp           # imm = 0x2FF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0xa, %r15d
jb 0x9542
movzwl -0x502(%rbp), %eax
andl $-0x9, %eax
testw %ax, %ax
je 0x9542
movl $0x4, 0x1c(%rbx)
jmp 0x950b
movq -0x4d8(%rbp), %r14
movq 0x60(%rbx), %rdi
leaq -0xc0(%rbp), %rdx
pushq $0x1e
popq %rcx
movq %r14, %rsi
callq *0x48(%rbx)
cmpq $0x1e, %rax
jne 0x95a3
cmpl $0x4034b50, -0xc0(%rbp) # imm = 0x4034B50
jne 0x9597
movzwl -0xa6(%rbp), %ecx
movzwl -0xa4(%rbp), %eax
addq %rcx, %r14
leaq (%r14,%rax), %rdx
movq -0x4f0(%rbp), %rcx
addq %rcx, %rdx
addq $0x1e, %rdx
cmpq (%rbx), %rdx
jbe 0x95af
movl $0x9, 0x1c(%rbx)
jmp 0x950b
movl $0x14, 0x1c(%rbx)
jmp 0x950b
addq %rax, %r14
addq $0x1e, %r14
movq 0x68(%rbx), %rax
movq 0x80(%rax), %rsi
testq %rsi, %rsi
je 0x95d5
addq %r14, %rsi
xorl %edx, %edx
movq %rcx, -0x70(%rbp)
movq %rcx, -0x60(%rbp)
jmp 0x960d
movl $0x10000, %edx          # imm = 0x10000
cmpq %rdx, %rcx
cmovbq %rcx, %rdx
movq 0x40(%rbx), %rdi
pushq $0x1
popq %rsi
movq %rdx, -0x70(%rbp)
callq *0x28(%rbx)
testq %rax, %rax
je 0x98e5
movq %rax, %rsi
movq -0x4f0(%rbp), %rcx
movq $0x0, -0x60(%rbp)
movq %rcx, %rdx
movq %r14, -0x58(%rbp)
btl $0xa, %r15d
movq %rsi, -0x30(%rbp)
jb 0x97eb
cmpw $0x0, -0x502(%rbp)
je 0x97eb
movq %rdx, %r14
andl $0x0, -0x3010(%rbp)
movq 0x40(%rbx), %rdi
pushq $0x1
popq %rsi
movl $0x8000, %edx           # imm = 0x8000
callq *0x28(%rbx)
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x98dc
movq $0x0, -0x38(%rbp)
xorl %esi, %esi
xorl %ecx, %ecx
movq %r14, %r9
movq -0x60(%rbp), %r14
movq -0x30(%rbp), %rdx
movl %ecx, %r8d
andl $0x7fff, %r8d           # imm = 0x7FFF
movl $0x8000, %eax           # imm = 0x8000
subq %r8, %rax
movq %rax, -0x88(%rbp)
testq %r14, %r14
movq %rcx, -0x48(%rbp)
jne 0x96e2
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x96a0
xorl %r14d, %r14d
jmp 0x96e2
movq %r8, -0x68(%rbp)
movq -0x70(%rbp), %rax
cmpq %r9, %rax
movq %r9, %r14
cmovbq %rax, %r14
movq 0x60(%rbx), %rdi
movq -0x58(%rbp), %rsi
movq %r9, -0x40(%rbp)
movq %r14, %rcx
callq *0x48(%rbx)
cmpq %r14, %rax
jne 0x9991
addq %r14, -0x58(%rbp)
movq -0x40(%rbp), %r9
subq %r14, %r9
xorl %esi, %esi
movq -0x30(%rbp), %rdx
movq -0x68(%rbp), %r8
movq -0x50(%rbp), %rcx
addq %rcx, %r8
movq %r8, -0x68(%rbp)
movq %r14, -0x90(%rbp)
movq %rsi, -0x80(%rbp)
addq %rdx, %rsi
xorl %eax, %eax
movq %r9, -0x40(%rbp)
testq %r9, %r9
setne %al
addl %eax, %eax
movl %eax, (%rsp)
leaq -0x3010(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq -0x88(%rbp), %r9
callq 0x53b1
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rcx
testq %rcx, %rcx
je 0x97b5
movq %rdi, -0x98(%rbp)
movq %rax, -0xa0(%rbp)
movq %r14, -0x60(%rbp)
movq %r13, %rdi
movq -0x48(%rbp), %r14
movq %r14, %rsi
movq -0x68(%rbp), %rdx
movq %rcx, -0x78(%rbp)
movq -0x78(%rbp), %rcx
callq *%r12
movq -0x78(%rbp), %rdx
cmpq %rdx, %rax
jne 0x98fa
movl -0x38(%rbp), %edi
movq -0x68(%rbp), %rsi
callq 0x36e2
movq %rax, -0x38(%rbp)
addq -0x78(%rbp), %r14
cmpq -0x4e8(%rbp), %r14
ja 0x98fe
movq %r14, %rcx
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %r9
movq -0x60(%rbp), %r14
movq -0x80(%rbp), %rsi
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rdi
jmp 0x97c5
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %r9
movq -0x48(%rbp), %rcx
movq -0x80(%rbp), %rsi
subq %rdi, %r14
addq %rdi, %rsi
leal -0x1(%rax), %edi
cmpl $0x2, %edi
jb 0x966b
xorl %r14d, %r14d
testl %eax, %eax
movq -0x50(%rbp), %r12
jne 0x9957
jmp 0x9916
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x9840
xorl %r14d, %r14d
movq %r13, %rdi
xorl %esi, %esi
movq -0x30(%rbp), %rdx
callq *%r12
cmpq -0x4f0(%rbp), %rax
jne 0x98f1
btl $0xa, %r15d
jb 0x990a
xorl %r12d, %r12d
xorl %edi, %edi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
movq %rax, %r14
callq 0x36e2
movq %r14, %rcx
movq %rax, -0x38(%rbp)
jmp 0x991d
movq $0x0, -0x38(%rbp)
xorl %ecx, %ecx
movq -0x58(%rbp), %rsi
testq %rdx, %rdx
je 0x9913
movq %rcx, -0x48(%rbp)
movq -0x70(%rbp), %rax
cmpq %rdx, %rax
movq %rdx, -0x40(%rbp)
movq %rdx, %r14
cmovbq %rax, %r14
movq 0x60(%rbx), %rdi
movq %rsi, -0x58(%rbp)
movq -0x30(%rbp), %rdx
movq %r14, %rcx
callq *0x48(%rbx)
cmpq %r14, %rax
jne 0x9941
btl $0xa, %r15d
jb 0x98a8
movl -0x38(%rbp), %edi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
callq 0x36e2
movq -0x30(%rbp), %rdx
movq %rax, -0x38(%rbp)
jmp 0x98ac
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rsi
movq %r13, %rdi
movq %r14, %rcx
callq *%r12
cmpq %r14, %rax
jne 0x994a
movq -0x58(%rbp), %rsi
addq %r14, %rsi
movq -0x48(%rbp), %rcx
addq %r14, %rcx
movq -0x40(%rbp), %rdx
subq %r14, %rdx
jmp 0x984e
movl $0x10, 0x1c(%rbx)
jmp 0x9951
movl $0x10, 0x1c(%rbx)
jmp 0x950b
movl $0x1f, 0x1c(%rbx)
jmp 0x990e
pushq $0x1f
jmp 0x9900
pushq $0xb
popq %rax
movq -0x50(%rbp), %r12
movl %eax, 0x1c(%rbx)
jmp 0x9954
pushq $0x1
popq %r14
xorl %r12d, %r12d
jmp 0x9957
xorl %r12d, %r12d
btl $0xa, %r15d
jb 0x9932
cmpq -0x4e8(%rbp), %rcx
jne 0x9938
movq -0x38(%rbp), %rax
cmpl -0x4f8(%rbp), %eax
jne 0x9988
pushq $0x1
popq %r14
jmp 0x9957
movl $0xd, 0x1c(%rbx)
jmp 0x9954
movl $0x14, 0x1c(%rbx)
jmp 0x9951
movl $0x1f, 0x1c(%rbx)
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
jne 0x9970
movq 0x40(%rbx), %rdi
movq -0x30(%rbp), %rsi
callq *0x30(%rbx)
testq %r12, %r12
je 0x950e
movq 0x40(%rbx), %rdi
movq %r12, %rsi
callq *0x30(%rbx)
jmp 0x950e
movl $0xb, 0x1c(%rbx)
jmp 0x9954
movq -0x50(%rbp), %r12
pushq $0x14
popq %rax
jmp 0x9905