// File: 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
subq $0xd0, %rsp
movq %rdi, -0x90(%rbp)
movl %esi, -0x94(%rbp)
movl %edx, -0x98(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0xfde4
movq -0x90(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0xfdf4
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movl $0x1, %esi
movl $0x2fb0, %edx           # imm = 0x2FB0
callq *%rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0xfe5a
movq -0x90(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x10, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xfe4a
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0x90(%rbp), %rdi
movl -0x94(%rbp), %esi
movq -0xa0(%rbp), %rdx
addq $0x48, %rdx
callq 0xeda0
cmpl $0x0, %eax
jne 0xfeab
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0xa0(%rbp), %rax
movzwl 0x5c(%rax), %eax
andl $0x61, %eax
cmpl $0x0, %eax
je 0xff10
movq -0x90(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x5, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xfee1
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movl -0x98(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xff92
movq -0xa0(%rbp), %rax
movzwl 0x5e(%rax), %eax
cmpl $0x0, %eax
je 0xff92
movq -0xa0(%rbp), %rax
movzwl 0x5e(%rax), %eax
cmpl $0x8, %eax
je 0xff92
movq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x4, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xff63
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0x90(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, (%rax)
movl -0x98(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x4a0(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x4a8(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x4b0(%rax)
movq -0xa0(%rbp), %rax
movq 0x88(%rax), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x90(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x60(%rcx), %rdi
movq -0xa0(%rbp), %rcx
movq 0x40(%rcx), %rsi
movq -0xc8(%rbp), %rdx
movl $0x1e, %ecx
callq *%rax
cmpq $0x1e, %rax
je 0x100c3
movq -0x90(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x14, -0x3c(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x10094
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0xc8(%rbp), %rax
cmpl $0x4034b50, (%rax)      # imm = 0x4034B50
je 0x10124
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x9, -0x4c(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x100f5
movl -0x4c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0xc8(%rbp), %rax
movzwl 0x1a(%rax), %eax
addl $0x1e, %eax
movq -0xc8(%rbp), %rcx
movzwl 0x1c(%rcx), %ecx
addl %ecx, %eax
movslq %eax, %rcx
movq -0xa0(%rbp), %rax
addq 0x40(%rax), %rcx
movq %rcx, 0x40(%rax)
movq -0xa0(%rbp), %rax
movq 0x40(%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x70(%rcx), %rax
movq -0x90(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0x101c5
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x9, -0x5c(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x10196
movl -0x5c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
movq -0x90(%rbp), %rax
movq 0x68(%rax), %rax
cmpq $0x0, 0x80(%rax)
je 0x10241
movq -0x90(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x80(%rax), %rcx
movq -0xa0(%rbp), %rax
addq 0x40(%rax), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x4a0(%rax)
movq -0xa0(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0xa0(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xa0(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x10374
movl -0x98(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x10340
movq -0xa0(%rbp), %rax
cmpw $0x0, 0x5e(%rax)
je 0x10340
movq -0xa0(%rbp), %rax
cmpq $0x10000, 0x70(%rax)    # imm = 0x10000
jae 0x1028c
movq -0xa0(%rbp), %rax
movq 0x70(%rax), %rax
movq %rax, -0xd0(%rbp)
jmp 0x1029a
movl $0x10000, %eax          # imm = 0x10000
movq %rax, -0xd0(%rbp)
jmp 0x1029a
movq -0xd0(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rcx
movq 0x18(%rcx), %rdx
movl $0x1, %esi
callq *%rax
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x4a0(%rax)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x1033e
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x10, -0x6c(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1030f
movl -0x6c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
jmp 0x1034f
movq -0xa0(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0xa0(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0xa0(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x98(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x10473
movq -0xa0(%rbp), %rax
cmpw $0x0, 0x5e(%rax)
je 0x10473
jmp 0x1039c
movq -0xa0(%rbp), %rax
movl $0x0, 0x4b8(%rax)
movq -0x90(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movl $0x1, %esi
movl $0x8000, %edx           # imm = 0x8000
callq *%rax
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x4a8(%rax)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x10471
movq -0x90(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x10, -0x7c(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x1040e
movl -0x7c(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0xa0(%rbp), %rax
cmpq $0x0, 0x4a0(%rax)
je 0x10445
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rcx
movq 0x4a0(%rcx), %rsi
callq *%rax
movq -0x90(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0xa0(%rbp), %rsi
callq *%rax
movq $0x0, -0x88(%rbp)
jmp 0x10481
jmp 0x10473
movq -0xa0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)