// File: /workspace/github_cpp_makefile_star2_O2/jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_extract_iter_new
mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
{
    mz_zip_reader_extract_iter_state *pState;
    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;

    /* Argument sanity check */
    if ((!pZip) || (!pZip->m_pState))
        return NULL;

    /* Allocate an iterator status structure */
    pState = (mz_zip_reader_extract_iter_state*)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_reader_extract_iter_state));
    if (!pState)
    {
        mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
        return NULL;
    }

    /* Fetch file details */
    if (!mz_zip_reader_file_stat(pZip, file_index, &pState->file_stat))
    {
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    /* Encryption and patch files are not supported. */
    if (pState->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))
    {
        mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    /* This function only supports decompressing stored and deflate. */
    if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (pState->file_stat.m_method != 0) && (pState->file_stat.m_method != MZ_DEFLATED))
    {
        mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    /* Init state - save args */
    pState->pZip = pZip;
    pState->flags = flags;

    /* Init state - reset variables to defaults */
    pState->status = TINFL_STATUS_DONE;
#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
    pState->file_crc32 = MZ_CRC32_INIT;
#endif
    pState->read_buf_ofs = 0;
    pState->out_buf_ofs = 0;
    pState->pRead_buf = NULL;
    pState->pWrite_buf = NULL;
    pState->out_blk_remain = 0;

    /* Read and parse the local directory entry. */
    pState->cur_file_ofs = pState->file_stat.m_local_header_ofs;
    if (pZip->m_pRead(pZip->m_pIO_opaque, pState->cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
    {
        mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
    {
        mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    pState->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 ((pState->cur_file_ofs + pState->file_stat.m_comp_size) > pZip->m_archive_size)
    {
        mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
        pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
        return NULL;
    }

    /* Decompress the file either directly from memory or from a file input buffer. */
    if (pZip->m_pState->m_pMem)
    {
        pState->pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + pState->cur_file_ofs;
        pState->read_buf_size = pState->read_buf_avail = pState->file_stat.m_comp_size;
        pState->comp_remaining = pState->file_stat.m_comp_size;
    }
    else
    {
        if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
        {
            /* Decompression required, therefore intermediate read buffer required */
            pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
            if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)pState->read_buf_size)))
            {
                mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
                pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
                return NULL;
            }
        }
        else
        {
            /* Decompression not required - we will be reading directly into user buffer, no temp buf required */
            pState->read_buf_size = 0;
        }
        pState->read_buf_avail = 0;
        pState->comp_remaining = pState->file_stat.m_comp_size;
    }

    if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
    {
        /* Decompression required, init decompressor */
        tinfl_init( &pState->inflator );

        /* Allocate write buffer */
        if (NULL == (pState->pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
        {
            mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
            if (pState->pRead_buf)
                pZip->m_pFree(pZip->m_pAlloc_opaque, pState->pRead_buf);
            pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
            return NULL;
        }
    }

    return pState;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
testq %rdi, %rdi
je 0x9a66
movq %rdi, %r14
cmpq $0x0, 0x68(%rdi)
je 0x9a66
movl %edx, %r15d
movl %esi, %r12d
movq 0x40(%r14), %rdi
pushq $0x1
popq %rsi
movl $0x2fb0, %edx           # imm = 0x2FB0
callq *0x28(%r14)
testq %rax, %rax
je 0x9a5e
movq %rax, %rbx
leaq 0x48(%rax), %rdx
movq %r14, %rdi
movl %r12d, %esi
callq 0x92a9
testl %eax, %eax
je 0x9a51
testb $0x61, 0x5c(%rbx)
je 0x9a78
movl $0x5, 0x1c(%r14)
movq 0x40(%r14), %rdi
movq %rbx, %rsi
callq *0x30(%r14)
jmp 0x9a66
movl $0x10, 0x1c(%r14)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
btl $0xa, %r15d
jb 0x9a8d
movzwl 0x5e(%rbx), %eax
testw $0xfff7, %ax            # imm = 0xFFF7
jne 0x9b27
movq %r14, (%rbx)
movl %r15d, 0x8(%rbx)
andq $0x0, 0xc(%rbx)
andq $0x0, 0x20(%rbx)
andq $0x0, 0x38(%rbx)
xorps %xmm0, %xmm0
andq $0x0, 0x4b0(%rbx)
movups %xmm0, 0x4a0(%rbx)
movq 0x88(%rbx), %rsi
movq %rsi, 0x40(%rbx)
movq 0x60(%r14), %rdi
leaq -0x40(%rbp), %rdx
pushq $0x1e
popq %rcx
callq *0x48(%r14)
cmpq $0x1e, %rax
jne 0x9b1a
cmpl $0x4034b50, -0x40(%rbp) # imm = 0x4034B50
jne 0x9b0d
movzwl -0x26(%rbp), %eax
movzwl -0x24(%rbp), %ecx
addq %rax, %rcx
movq 0x40(%rbx), %rdx
movq 0x70(%rbx), %rax
leaq (%rcx,%rdx), %rsi
addq %rdx, %rcx
addq $0x1e, %rcx
movq %rcx, 0x40(%rbx)
leaq (%rax,%rsi), %rdx
addq $0x1e, %rdx
cmpq (%r14), %rdx
jbe 0x9b34
movl $0x9, 0x1c(%r14)
jmp 0x9a51
movl $0x14, 0x1c(%r14)
jmp 0x9a51
movl $0x4, 0x1c(%r14)
jmp 0x9a51
movq 0x68(%r14), %rdx
movq 0x80(%rdx), %rdx
testq %rdx, %rdx
je 0x9b5a
addq %rcx, %rdx
movq %rdx, 0x4a0(%rbx)
movq %rax, 0x28(%rbx)
pushq $0x18
popq %rcx
movq %rax, %rdx
jmp 0x9b9f
btl $0xa, %r15d
jb 0x9b95
cmpw $0x0, 0x5e(%rbx)
je 0x9b95
movl $0x10000, %edx          # imm = 0x10000
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, 0x18(%rbx)
movq 0x40(%r14), %rdi
pushq $0x1
popq %rsi
callq *0x28(%r14)
movq %rax, 0x4a0(%rbx)
testq %rax, %rax
je 0x9c0e
movq 0x70(%rbx), %rax
jmp 0x9b9a
andq $0x0, 0x18(%rbx)
pushq $0x28
popq %rcx
xorl %edx, %edx
btl $0xa, %r15d
movq %rdx, (%rbx,%rcx)
movq %rax, 0x30(%rbx)
jb 0x9a68
cmpw $0x0, 0x5e(%rbx)
je 0x9a68
andl $0x0, 0x4b8(%rbx)
movq 0x40(%r14), %rdi
pushq $0x1
popq %rsi
movl $0x8000, %edx           # imm = 0x8000
callq *0x28(%r14)
movq %rax, 0x4a8(%rbx)
testq %rax, %rax
jne 0x9a68
movq %rbx, %rax
addq $0x4a0, %rax            # imm = 0x4A0
movl $0x10, 0x1c(%r14)
movq (%rax), %rsi
testq %rsi, %rsi
je 0x9a51
movq 0x40(%r14), %rdi
callq *0x30(%r14)
jmp 0x9a51
movl $0x10, 0x1c(%r14)
jmp 0x9a51