// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2fe8, %rsp           # imm = 0x2FE8
xorl %r15d, %r15d
testq %rdi, %rdi
je 0x95ff
movq %rdx, %r12
movq %rdi, %rbx
testq %rdx, %rdx
je 0x95f0
cmpq $0x0, 0x68(%rbx)
je 0x95f0
cmpq $0x0, 0x48(%rbx)
je 0x95f0
movl %r8d, %r14d
movq %rcx, %r13
leaq -0x508(%rbp), %rdx
movq %rbx, %rdi
callq 0x9372
testl %eax, %eax
je 0x95ff
cmpl $0x0, -0x4bc(%rbp)
movl $0x1, %r15d
jne 0x95ff
cmpq $0x0, -0x4e0(%rbp)
je 0x95ff
testb $0x61, -0x4f4(%rbp)
je 0x9614
movl $0x5, 0x1c(%rbx)
jmp 0x95fc
testq %rbx, %rbx
je 0x95ff
movl $0x18, 0x1c(%rbx)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x2fe8, %rsp           # imm = 0x2FE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0xa, %r14d
jb 0x9633
movzwl -0x4f2(%rbp), %eax
andl $-0x9, %eax
testw %ax, %ax
je 0x9633
movl $0x4, 0x1c(%rbx)
jmp 0x95fc
movq -0x4c8(%rbp), %r15
movq 0x60(%rbx), %rdi
leaq -0xb0(%rbp), %rdx
movl $0x1e, %ecx
movq %r15, %rsi
callq *0x48(%rbx)
cmpq $0x1e, %rax
jne 0x969a
cmpl $0x4034b50, -0xb0(%rbp) # imm = 0x4034B50
jne 0x968e
movzwl -0x96(%rbp), %ecx
movzwl -0x94(%rbp), %eax
addq %rcx, %r15
leaq (%r15,%rax), %rcx
movq -0x4e0(%rbp), %rdx
movq %rdx, -0x58(%rbp)
addq %rdx, %rcx
addq $0x1e, %rcx
cmpq (%rbx), %rcx
jbe 0x96a6
movl $0x9, 0x1c(%rbx)
jmp 0x95fc
movl $0x14, 0x1c(%rbx)
jmp 0x95fc
addq %rax, %r15
addq $0x1e, %r15
movq 0x68(%rbx), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x96c8
addq %r15, %rdx
xorl %ecx, %ecx
movq -0x58(%rbp), %rax
jmp 0x96fd
movl $0x10000, %eax          # imm = 0x10000
movq -0x58(%rbp), %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq 0x40(%rbx), %rdi
movl $0x1, %esi
movq %rdx, -0x58(%rbp)
callq *0x28(%rbx)
testq %rax, %rax
je 0x9a4b
movq %rax, %rdx
movq -0x4e0(%rbp), %rcx
xorl %eax, %eax
btl $0xa, %r14d
movq %rdx, -0x30(%rbp)
jb 0x9924
cmpw $0x0, -0x4f2(%rbp)
je 0x9924
movq %rax, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movl $0x0, -0x3000(%rbp)
movq 0x40(%rbx), %rdi
movl $0x1, %esi
movl $0x8000, %edx           # imm = 0x8000
callq *0x28(%rbx)
movq %rax, -0x78(%rbp)
testq %rax, %rax
je 0x9a28
movq %r15, -0x68(%rbp)
movq $0x0, -0x40(%rbp)
xorl %ecx, %ecx
xorl %r15d, %r15d
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl %r15d, %r8d
andl $0x7fff, %r8d           # imm = 0x7FFF
movl $0x8000, %eax           # imm = 0x8000
subq %r8, %rax
movq %rax, -0x80(%rbp)
testq %rsi, %rsi
movq %r15, -0x38(%rbp)
jne 0x97e3
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x9798
xorl %esi, %esi
jmp 0x97e3
movq %r8, -0x70(%rbp)
movq %rcx, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq %rdi, %rax
movq %rdi, %rcx
cmovbq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rdi, -0x48(%rbp)
movq 0x60(%rbx), %rdi
movq -0x68(%rbp), %rsi
callq *0x48(%rbx)
movq -0x50(%rbp), %rsi
cmpq %rsi, %rax
jne 0x990b
addq %rsi, -0x68(%rbp)
movq -0x48(%rbp), %rdi
subq %rsi, %rdi
xorl %ecx, %ecx
movq -0x30(%rbp), %rdx
movq -0x70(%rbp), %r8
movq %rsi, -0x50(%rbp)
movq %rcx, %r15
movq -0x78(%rbp), %rcx
addq %rcx, %r8
movq %rsi, -0x88(%rbp)
leaq (%rdx,%r15), %rsi
xorl %eax, %eax
movq %rdi, -0x48(%rbp)
testq %rdi, %rdi
setne %al
addl %eax, %eax
movl %eax, (%rsp)
leaq -0x3000(%rbp), %rdi
leaq -0x88(%rbp), %rdx
movq %r8, -0x70(%rbp)
leaq -0x80(%rbp), %r9
callq 0x4425
movq -0x50(%rbp), %rsi
movq -0x88(%rbp), %rcx
subq %rcx, %rsi
addq %r15, %rcx
movq -0x80(%rbp), %r15
movb $0x1, %r8b
testq %r15, %r15
je 0x98a5
movq %rax, -0x90(%rbp)
movq %rcx, -0x60(%rbp)
movq %rsi, -0x50(%rbp)
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r15, %rcx
callq *%r12
cmpq %r15, %rax
jne 0x98b3
movl -0x40(%rbp), %edi
movq -0x70(%rbp), %rsi
movq %r15, %rdx
callq 0x3715
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq %r15, %rax
cmpq -0x4d8(%rbp), %rax
movq %rax, %r15
jbe 0x98d8
movl $0xb, 0x1c(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq -0x30(%rbp), %rdx
jmp 0x98ca
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %rdi
jmp 0x98f2
movl $0x1f, 0x1c(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rcx
jmp 0x98f2
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rcx
movq -0x90(%rbp), %rax
movb $0x1, %r8b
testb %r8b, %r8b
je 0x9981
leal -0x1(%rax), %r8d
cmpl $0x2, %r8d
jb 0x9767
jmp 0x9981
movl $0x14, 0x1c(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rdi
jmp 0x98d2
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
je 0x998f
movq -0x4e0(%rbp), %rcx
movq %r13, %rdi
xorl %esi, %esi
callq *%r12
movq -0x4e0(%rbp), %rcx
cmpq %rcx, %rax
movq %rcx, -0x38(%rbp)
jne 0x9a57
btl $0xa, %r14d
jb 0x9a6d
xorl %r12d, %r12d
xorl %edi, %edi
movq -0x30(%rbp), %r15
movq %r15, %rsi
movq -0x38(%rbp), %rdx
callq 0x3715
movq %r15, %rdx
movq %rax, -0x40(%rbp)
jmp 0x9a93
movq %r15, -0x38(%rbp)
testl %eax, %eax
setne %al
jmp 0x9a45
testq %rcx, %rcx
je 0x9a80
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq %r15, %rsi
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
movq %rcx, -0x48(%rbp)
movq %rcx, %r15
cmovbq %rax, %r15
movq 0x60(%rbx), %rdi
movq %rsi, -0x68(%rbp)
movq %r15, %rcx
callq *0x48(%rbx)
cmpq %r15, %rax
jne 0x9b0a
btl $0xa, %r14d
jb 0x99f4
movl -0x40(%rbp), %edi
movq -0x30(%rbp), %rsi
movq %r15, %rdx
callq 0x3715
movq -0x30(%rbp), %rdx
movq %rax, -0x40(%rbp)
jmp 0x99f8
movq -0x30(%rbp), %rdx
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movq %rsi, -0x38(%rbp)
movq %r15, %rcx
callq *%r12
cmpq %r15, %rax
jne 0x9a5f
movq -0x68(%rbp), %rsi
addq %r15, %rsi
addq %r15, -0x38(%rbp)
movq -0x48(%rbp), %rcx
subq %r15, %rcx
movq -0x30(%rbp), %rdx
jne 0x99ab
jmp 0x9a90
movl $0x10, 0x1c(%rbx)
movb $0x1, %al
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %r12
jmp 0x9a95
movl $0x10, 0x1c(%rbx)
jmp 0x95fc
movq $0x0, -0x40(%rbp)
movl $0x1f, 0x1c(%rbx)
movb $0x1, %al
xorl %r12d, %r12d
jmp 0x9a7a
movq $0x0, -0x40(%rbp)
xorl %r12d, %r12d
xorl %eax, %eax
movq -0x30(%rbp), %rdx
jmp 0x9a95
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
xorl %r12d, %r12d
xorl %eax, %eax
movl %eax, %ecx
xorb $0x1, %cl
movzbl %cl, %r15d
testb %al, %al
jne 0x9ada
andl $0x400, %r14d           # imm = 0x400
jne 0x9ada
movl $0xd, %eax
movq -0x38(%rbp), %rcx
cmpq -0x4d8(%rbp), %rcx
jne 0x9ad4
movl $0xb, %eax
movl $0x1, %r15d
movq -0x40(%rbp), %rcx
cmpl -0x4e8(%rbp), %ecx
je 0x9ada
movl %eax, 0x1c(%rbx)
xorl %r15d, %r15d
movq 0x68(%rbx), %rax
cmpq $0x0, 0x80(%rax)
jne 0x9af2
movq 0x40(%rbx), %rdi
movq %rdx, %rsi
callq *0x30(%rbx)
testq %r12, %r12
je 0x95ff
movq 0x40(%rbx), %rdi
movq %r12, %rsi
callq *0x30(%rbx)
jmp 0x95ff
movl $0x14, 0x1c(%rbx)
jmp 0x9a66