// File: /workspace/github_cpp_makefile_star2_O1/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 0x9fd4
movq %rdi, %rbx
movq (%rdi), %rax
testq %rax, %rax
je 0x9fd4
movq %rdx, %r15
movq %rsi, %r14
movq 0x68(%rax), %rcx
testq %rcx, %rcx
sete %dl
testq %rsi, %rsi
sete %sil
orb %dl, %sil
jne 0x9fd4
testb $0x4, 0x9(%rbx)
jne 0x9fe9
cmpw $0x0, 0x5e(%rbx)
je 0x9fe9
movq %r14, -0x48(%rbp)
leaq 0x4b8(%rbx), %rax
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
movq 0x38(%rbx), %r13
andl $0x7fff, %r13d          # imm = 0x7FFF
movl $0x8000, %eax           # imm = 0x8000
subq %r13, %rax
addq 0x4a8(%rbx), %r13
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x4b0(%rbx)
jne 0x9f2a
cmpq $0x0, 0x28(%rbx)
jne 0x9ed3
movq (%rbx), %rax
movq 0x68(%rax), %rcx
cmpq $0x0, 0x80(%rcx)
jne 0x9ed3
movq 0x18(%rbx), %rdx
movq 0x30(%rbx), %rcx
cmpq %rcx, %rdx
cmovbq %rdx, %rcx
movq %rcx, 0x28(%rbx)
movq 0x60(%rax), %rdi
movq 0x40(%rbx), %rsi
movq 0x4a0(%rbx), %rdx
callq *0x48(%rax)
movq 0x28(%rbx), %rcx
cmpq %rcx, %rax
jne 0x9fba
addq %rcx, 0x40(%rbx)
subq %rcx, 0x30(%rbx)
movq $0x0, 0x20(%rbx)
movq 0x28(%rbx), %rax
movq %rax, -0x38(%rbp)
movq 0x4a0(%rbx), %rsi
movq 0x4a8(%rbx), %rcx
addq 0x20(%rbx), %rsi
xorl %eax, %eax
cmpq $0x0, 0x30(%rbx)
setne %al
addl %eax, %eax
movl %eax, (%rsp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rdx
movq %r13, %r8
leaq -0x30(%rbp), %r9
callq 0x4425
movl %eax, 0xc(%rbx)
movq -0x38(%rbp), %rax
subq %rax, 0x28(%rbx)
addq %rax, 0x20(%rbx)
movq -0x30(%rbp), %rax
movq %rax, 0x4b0(%rbx)
movq 0x4b0(%rbx), %rax
testq %rax, %rax
je 0x9f87
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 0x31e0
movl 0x10(%rbx), %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x3715
movl %eax, 0x10(%rbx)
subq %r14, 0x4b0(%rbx)
movq 0x38(%rbx), %rax
addq %r14, %rax
movq %rax, 0x38(%rbx)
cmpq 0x78(%rbx), %rax
setbe %al
ja 0x9f8b
addq %r14, %r12
jmp 0x9fa1
movb $0x1, %al
jmp 0x9fa1
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x9f9a
movl $0xb, 0x1c(%rcx)
movl $0xffffffff, 0xc(%rbx)  # imm = 0xFFFFFFFF
testb %al, %al
je 0x9fd7
cmpq %r15, %r12
jae 0x9fd7
movl 0xc(%rbx), %eax
decl %eax
cmpl $0x2, %eax
jb 0x9e4d
jmp 0x9fd7
movq (%rbx), %rax
testq %rax, %rax
je 0x9fc9
movl $0x14, 0x1c(%rax)
movl $0xffffffff, 0xc(%rbx)  # imm = 0xFFFFFFFF
xorl %eax, %eax
jmp 0x9fa1
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 0xa019
movq 0x4a0(%rbx), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x31e0
addq %r15, 0x4a0(%rbx)
jmp 0xa048
movq 0x60(%rax), %rdi
movq 0x40(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq *0x48(%rax)
cmpq %r15, %rax
je 0xa048
movq (%rbx), %rax
testq %rax, %rax
je 0xa03e
movl $0x14, 0x1c(%rax)
movl $0xffffffff, 0xc(%rbx)  # imm = 0xFFFFFFFF
xorl %r15d, %r15d
testb $0x4, 0x9(%rbx)
jne 0xa05f
movl 0x10(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3715
movl %eax, 0x10(%rbx)
addq %r15, 0x40(%rbx)
addq %r15, 0x38(%rbx)
subq %r15, 0x30(%rbx)
movq %r15, %r12
jmp 0x9fd7