// File: /workspace/github_cpp_makefile_star2_O3/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 0x95d4
movq %rdx, %r12
movq %rdi, %rbx
testq %rdx, %rdx
je 0x95ca
cmpq $0x0, 0x68(%rbx)
je 0x95ca
cmpq $0x0, 0x48(%rbx)
je 0x95ca
movl %r8d, %r15d
movq %rcx, %r13
leaq -0x518(%rbp), %rdx
movq %rbx, %rdi
callq 0x9351
testl %eax, %eax
je 0x95d4
cmpl $0x0, -0x4cc(%rbp)
movl $0x1, %r14d
jne 0x95d4
cmpq $0x0, -0x4f0(%rbp)
je 0x95d4
testb $0x61, -0x504(%rbp)
je 0x95e9
movl $0x5, 0x1c(%rbx)
jmp 0x95d1
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 0x9608
movzwl -0x502(%rbp), %eax
andl $-0x9, %eax
testw %ax, %ax
je 0x9608
movl $0x4, 0x1c(%rbx)
jmp 0x95d1
movq -0x4d8(%rbp), %r14
movq 0x60(%rbx), %rdi
leaq -0xc0(%rbp), %rdx
movl $0x1e, %ecx
movq %r14, %rsi
callq *0x48(%rbx)
cmpq $0x1e, %rax
jne 0x966b
cmpl $0x4034b50, -0xc0(%rbp) # imm = 0x4034B50
jne 0x965f
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 0x9677
movl $0x9, 0x1c(%rbx)
jmp 0x95d1
movl $0x14, 0x1c(%rbx)
jmp 0x95d1
addq %rax, %r14
addq $0x1e, %r14
movq 0x68(%rbx), %rax
movq 0x80(%rax), %rsi
testq %rsi, %rsi
je 0x969d
addq %r14, %rsi
xorl %edx, %edx
movq %rcx, -0x70(%rbp)
movq %rcx, -0x60(%rbp)
jmp 0x96d7
movl $0x10000, %edx          # imm = 0x10000
cmpq %rdx, %rcx
cmovbq %rcx, %rdx
movq 0x40(%rbx), %rdi
movl $0x1, %esi
movq %rdx, -0x70(%rbp)
callq *0x28(%rbx)
testq %rax, %rax
je 0x99c7
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 0x98be
cmpw $0x0, -0x502(%rbp)
je 0x98be
movq %rdx, %r14
movl $0x0, -0x3010(%rbp)
movq 0x40(%rbx), %rdi
movl $0x1, %esi
movl $0x8000, %edx           # imm = 0x8000
callq *0x28(%rbx)
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x99b7
movq $0x0, -0x40(%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, -0x38(%rbp)
jne 0x97b1
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x976f
xorl %r14d, %r14d
jmp 0x97b1
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, -0x50(%rbp)
movq %r14, %rcx
callq *0x48(%rbx)
cmpq %r14, %rax
jne 0x9a80
addq %r14, -0x58(%rbp)
movq -0x50(%rbp), %r9
subq %r14, %r9
xorl %esi, %esi
movq -0x30(%rbp), %rdx
movq -0x68(%rbp), %r8
movq -0x48(%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, -0x50(%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 0x441a
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rcx
testq %rcx, %rcx
je 0x9884
movq %rdi, -0x98(%rbp)
movq %rax, -0xa0(%rbp)
movq %r14, -0x60(%rbp)
movq %r13, %rdi
movq -0x38(%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 0x99dc
movl -0x40(%rbp), %edi
movq -0x68(%rbp), %rsi
callq 0x3715
movq %rax, -0x40(%rbp)
addq -0x78(%rbp), %r14
cmpq -0x4e8(%rbp), %r14
ja 0x99e3
movq %r14, %rcx
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %r9
movq -0x60(%rbp), %r14
movq -0x80(%rbp), %rsi
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rdi
jmp 0x9894
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %r9
movq -0x38(%rbp), %rcx
movq -0x80(%rbp), %rsi
subq %rdi, %r14
addq %rdi, %rsi
leal -0x1(%rax), %edi
cmpl $0x2, %edi
jb 0x973a
xorl %r14d, %r14d
testl %eax, %eax
movq -0x48(%rbp), %r12
movq -0x40(%rbp), %rax
jne 0x9a4f
jmp 0x9a03
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x990e
movq %rsi, %rdx
xorl %r14d, %r14d
movq %r13, %rdi
xorl %esi, %esi
callq *%r12
cmpq -0x4f0(%rbp), %rax
jne 0x99d3
btl $0xa, %r15d
jb 0x99f1
xorl %r12d, %r12d
xorl %edi, %edi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
movq %rax, %r14
callq 0x3715
movq %r14, %rcx
jmp 0x9a10
testq %rdx, %rdx
movq -0x58(%rbp), %rsi
je 0x99fc
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x70(%rbp), %rax
cmpq %rdx, %rax
movq %rdx, -0x50(%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 0x9a39
btl $0xa, %r15d
jb 0x9978
movl -0x40(%rbp), %edi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
callq 0x3715
movq -0x30(%rbp), %rdx
movq %rax, -0x40(%rbp)
jmp 0x997c
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rsi
movq %rsi, -0x38(%rbp)
movq %r13, %rdi
movq %r14, %rcx
callq *%r12
cmpq %r14, %rax
jne 0x9a42
movq -0x58(%rbp), %rsi
addq %r14, %rsi
addq %r14, -0x38(%rbp)
movq -0x50(%rbp), %rdx
subq %r14, %rdx
jne 0x992b
xorl %r12d, %r12d
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
jmp 0x9a03
movl $0x10, 0x1c(%rbx)
movq -0x48(%rbp), %r12
jmp 0x9a4c
movl $0x10, 0x1c(%rbx)
jmp 0x95d1
movl $0x1f, 0x1c(%rbx)
jmp 0x99f7
movl $0x1f, %eax
jmp 0x99e8
movl $0xb, %eax
movq -0x48(%rbp), %r12
movl %eax, 0x1c(%rbx)
jmp 0x9a4c
movl $0x1, %r14d
xorl %r12d, %r12d
jmp 0x9a4f
xorl %r12d, %r12d
xorl %ecx, %ecx
xorl %eax, %eax
movl $0x1, %r14d
btl $0xa, %r15d
jb 0x9a4f
cmpq -0x4e8(%rbp), %rcx
jne 0x9a30
movl $0x1, %r14d
cmpl -0x4f8(%rbp), %eax
je 0x9a4f
movl $0xb, 0x1c(%rbx)
jmp 0x9a4c
movl $0xd, 0x1c(%rbx)
jmp 0x9a4c
movl $0x14, 0x1c(%rbx)
jmp 0x9a49
movl $0x1f, 0x1c(%rbx)
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
jne 0x9a68
movq 0x40(%rbx), %rdi
movq -0x30(%rbp), %rsi
callq *0x30(%rbx)
testq %r12, %r12
je 0x95d4
movq 0x40(%rbx), %rdi
movq %r12, %rsi
callq *0x30(%rbx)
jmp 0x95d4
movl $0x14, %eax
jmp 0x99e8