// File: /workspace/github_cpp_makefile_star2_O2/jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_zip_reader_extract_iter_read
size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size)
{
    size_t copied_to_caller = 0;

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

    if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))
    {
        /* The file is stored or the caller has requested the compressed data, calc amount to return. */
        copied_to_caller = (size_t)MZ_MIN((mz_uint64)buf_size, pState->comp_remaining );

        /* Zip is in memory....or requires reading from a file? */
        if (pState->pZip->m_pState->m_pMem)
        {
            /* Copy data to caller's buffer */
            memcpy( pvBuf, pState->pRead_buf, copied_to_caller );
            pState->pRead_buf = ((mz_uint8*)pState->pRead_buf) + copied_to_caller;
        }
        else
        {
            /* Read directly into caller's buffer */
            if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pvBuf, copied_to_caller) != copied_to_caller)
            {
                /* Failed to read all that was asked for, flag failure and alert user */
                mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED);
                pState->status = TINFL_STATUS_FAILED;
                copied_to_caller = 0;
            }
        }

#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
        /* Compute CRC if not returning compressed data only */
        if (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
            pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, (const mz_uint8 *)pvBuf, copied_to_caller);
#endif

        /* Advance offsets, dec counters */
        pState->cur_file_ofs += copied_to_caller;
        pState->out_buf_ofs += copied_to_caller;
        pState->comp_remaining -= copied_to_caller;
    }
    else
    {
        do
        {
            /* Calc ptr to write buffer - given current output pos and block size */
            mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pState->pWrite_buf + (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));

            /* Calc max output size - given current output pos and block size */
            size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));

            if (!pState->out_blk_remain)
            {
                /* Read more data from file if none available (and reading from file) */
                if ((!pState->read_buf_avail) && (!pState->pZip->m_pState->m_pMem))
                {
                    /* Calc read size */
                    pState->read_buf_avail = MZ_MIN(pState->read_buf_size, pState->comp_remaining);
                    if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pState->pRead_buf, (size_t)pState->read_buf_avail) != pState->read_buf_avail)
                    {
                        mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED);
                        pState->status = TINFL_STATUS_FAILED;
                        break;
                    }

                    /* Advance offsets, dec counters */
                    pState->cur_file_ofs += pState->read_buf_avail;
                    pState->comp_remaining -= pState->read_buf_avail;
                    pState->read_buf_ofs = 0;
                }

                /* Perform decompression */
                in_buf_size = (size_t)pState->read_buf_avail;
                pState->status = tinfl_decompress(&pState->inflator, (const mz_uint8 *)pState->pRead_buf + pState->read_buf_ofs, &in_buf_size, (mz_uint8 *)pState->pWrite_buf, pWrite_buf_cur, &out_buf_size, pState->comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
                pState->read_buf_avail -= in_buf_size;
                pState->read_buf_ofs += in_buf_size;

                /* Update current output block size remaining */
                pState->out_blk_remain = out_buf_size;
            }

            if (pState->out_blk_remain)
            {
                /* Calc amount to return. */
                size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain );

                /* Copy data to caller's buffer */
                memcpy( (uint8_t*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy );

#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
                /* Perform CRC */
                pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, pWrite_buf_cur, to_copy);
#endif

                /* Decrement data consumed from block */
                pState->out_blk_remain -= to_copy;

                /* Inc output offset, while performing sanity check */
                if ((pState->out_buf_ofs += to_copy) > pState->file_stat.m_uncomp_size)
                {
                    mz_zip_set_error(pState->pZip, MZ_ZIP_DECOMPRESSION_FAILED);
                    pState->status = TINFL_STATUS_FAILED;
                    break;
                }

                /* Increment counter of data copied to caller */
                copied_to_caller += to_copy;
            }
        } while ( (copied_to_caller < buf_size) && ((pState->status == TINFL_STATUS_NEEDS_MORE_INPUT) || (pState->status == TINFL_STATUS_HAS_MORE_OUTPUT)) );
    }

    /* Return how many bytes were copied into user buffer */
    return copied_to_caller;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x9e30
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0x9e30
movq %rdx, %r15
movq %rsi, %r14
movq 0x68(%rax), %rcx
testq %rcx, %rcx
sete %dl
testq %rsi, %rsi
sete %sil
orb %dl, %sil
jne 0x9e30
testb $0x4, 0x9(%rbx)
jne 0x9e45
cmpw $0x0, 0x5e(%rbx)
je 0x9e45
movq %r14, -0x48(%rbp)
leaq 0x4b8(%rbx), %rax
movq %rax, -0x40(%rbp)
movq 0x4b0(%rbx), %rax
xorl %r12d, %r12d
movq 0x4a8(%rbx), %rcx
movq 0x38(%rbx), %rdx
andl $0x7fff, %edx           # imm = 0x7FFF
leaq (%rcx,%rdx), %r13
movl $0x8000, %esi           # imm = 0x8000
subq %rdx, %rsi
movq %rsi, -0x30(%rbp)
testq %rax, %rax
jne 0x9dbd
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x9d0c
movq 0x30(%rbx), %r8
jmp 0x9d6e
movq (%rbx), %rax
movq 0x30(%rbx), %r8
movq 0x68(%rax), %rdx
cmpq $0x0, 0x80(%rdx)
je 0x9d25
xorl %eax, %eax
jmp 0x9d6e
movq 0x18(%rbx), %rcx
cmpq %r8, %rcx
cmovbq %rcx, %r8
movq 0x40(%rbx), %rsi
movq %r8, 0x28(%rbx)
movq 0x60(%rax), %rdi
movq 0x4a0(%rbx), %rdx
movq %r8, %rcx
callq *0x48(%rax)
cmpq 0x28(%rbx), %rax
jne 0x9ee4
addq %rax, 0x40(%rbx)
movq 0x30(%rbx), %r8
subq %rax, %r8
movq %r8, 0x30(%rbx)
andq $0x0, 0x20(%rbx)
movq 0x4a8(%rbx), %rcx
movq %rax, -0x38(%rbp)
movq 0x4a0(%rbx), %rsi
addq 0x20(%rbx), %rsi
xorl %eax, %eax
testq %r8, %r8
setne %al
addl %eax, %eax
movl %eax, (%rsp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rdx
movq %r13, %r8
leaq -0x30(%rbp), %r9
callq 0x53b1
movl %eax, 0xc(%rbx)
movq -0x38(%rbp), %rax
subq %rax, 0x28(%rbx)
addq %rax, 0x20(%rbx)
movq -0x30(%rbp), %rax
movq %rax, 0x4b0(%rbx)
testq %rax, %rax
je 0x9e2c
movq %r15, %r14
subq %r12, %r14
cmpq %rax, %r14
cmovaeq %rax, %r14
movq -0x48(%rbp), %rax
leaq (%rax,%r12), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x31f0
movl 0x10(%rbx), %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x36e2
movl %eax, 0x10(%rbx)
movq 0x4b0(%rbx), %rax
subq %r14, %rax
movq %rax, 0x4b0(%rbx)
movq 0x38(%rbx), %rcx
addq %r14, %rcx
movq %rcx, 0x38(%rbx)
cmpq 0x78(%rbx), %rcx
ja 0x9ecc
addq %r14, %r12
cmpq %r15, %r12
jae 0x9e33
movl 0xc(%rbx), %ecx
decl %ecx
cmpl $0x2, %ecx
jb 0x9cd3
jmp 0x9e33
xorl %eax, %eax
jmp 0x9e17
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rbx), %rdx
cmpq %r15, %rdx
cmovbq %rdx, %r15
cmpq $0x0, 0x80(%rcx)
je 0x9e75
movq 0x4a0(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x31f0
addq %r15, 0x4a0(%rbx)
jmp 0x9ea1
movq 0x60(%rax), %rdi
movq 0x40(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq *0x48(%rax)
cmpq %r15, %rax
je 0x9ea1
movq (%rbx), %rax
testq %rax, %rax
je 0x9e9a
movl $0x14, 0x1c(%rax)
orl $-0x1, 0xc(%rbx)
xorl %r15d, %r15d
testb $0x4, 0x9(%rbx)
jne 0x9eb8
movl 0x10(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36e2
movl %eax, 0x10(%rbx)
addq %r15, 0x40(%rbx)
addq %r15, 0x38(%rbx)
subq %r15, 0x30(%rbx)
movq %r15, %r12
jmp 0x9e33
movq (%rbx), %rax
testq %rax, %rax
je 0x9edb
movl $0xb, 0x1c(%rax)
orl $-0x1, 0xc(%rbx)
jmp 0x9e33
movq (%rbx), %rax
testq %rax, %rax
je 0x9edb
movl $0x14, 0x1c(%rax)
jmp 0x9edb