// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: mz_inflate
int mz_inflate(mz_streamp pStream, int flush)
{
    inflate_state *pState;
    mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
    size_t in_bytes, out_bytes, orig_avail_in;
    tinfl_status status;

    if ((!pStream) || (!pStream->state))
        return MZ_STREAM_ERROR;
    if (flush == MZ_PARTIAL_FLUSH)
        flush = MZ_SYNC_FLUSH;
    if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH))
        return MZ_STREAM_ERROR;

    pState = (inflate_state *)pStream->state;
    if (pState->m_window_bits > 0)
        decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
    orig_avail_in = pStream->avail_in;

    first_call = pState->m_first_call;
    pState->m_first_call = 0;
    if (pState->m_last_status < 0)
        return MZ_DATA_ERROR;

    if (pState->m_has_flushed && (flush != MZ_FINISH))
        return MZ_STREAM_ERROR;
    pState->m_has_flushed |= (flush == MZ_FINISH);

    if ((flush == MZ_FINISH) && (first_call))
    {
        /* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */
        decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
        in_bytes = pStream->avail_in;
        out_bytes = pStream->avail_out;
        status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
        pState->m_last_status = status;
        pStream->next_in += (mz_uint)in_bytes;
        pStream->avail_in -= (mz_uint)in_bytes;
        pStream->total_in += (mz_uint)in_bytes;
        pStream->adler = tinfl_get_adler32(&pState->m_decomp);
        pStream->next_out += (mz_uint)out_bytes;
        pStream->avail_out -= (mz_uint)out_bytes;
        pStream->total_out += (mz_uint)out_bytes;

        if (status < 0)
            return MZ_DATA_ERROR;
        else if (status != TINFL_STATUS_DONE)
        {
            pState->m_last_status = TINFL_STATUS_FAILED;
            return MZ_BUF_ERROR;
        }
        return MZ_STREAM_END;
    }
    /* flush != MZ_FINISH then we must assume there's more input. */
    if (flush != MZ_FINISH)
        decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;

    if (pState->m_dict_avail)
    {
        n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
        memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
        pStream->next_out += n;
        pStream->avail_out -= n;
        pStream->total_out += n;
        pState->m_dict_avail -= n;
        pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
        return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
    }

    for (;;)
    {
        in_bytes = pStream->avail_in;
        out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;

        status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
        pState->m_last_status = status;

        pStream->next_in += (mz_uint)in_bytes;
        pStream->avail_in -= (mz_uint)in_bytes;
        pStream->total_in += (mz_uint)in_bytes;
        pStream->adler = tinfl_get_adler32(&pState->m_decomp);

        pState->m_dict_avail = (mz_uint)out_bytes;

        n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
        memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
        pStream->next_out += n;
        pStream->avail_out -= n;
        pStream->total_out += n;
        pState->m_dict_avail -= n;
        pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);

        if (status < 0)
            return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */
        else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
            return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */
        else if (flush == MZ_FINISH)
        {
            /* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */
            if (status == TINFL_STATUS_DONE)
                return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
            /* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */
            else if (!pStream->avail_out)
                return MZ_BUF_ERROR;
        }
        else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
            break;
    }

    return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x8, -0x2c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x4ac8
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x4ad4
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5057
cmpl $0x1, -0x14(%rbp)
jne 0x4ae1
movl $0x2, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x4aff
cmpl $0x2, -0x14(%rbp)
je 0x4aff
cmpl $0x4, -0x14(%rbp)
je 0x4aff
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5057
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2b08(%rax)
jle 0x4b21
movl -0x2c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl 0x2b00(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, 0x2b00(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0xab0c(%rax)
jge 0x4b60
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x5057
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2b04(%rax)
je 0x4b7f
cmpl $0x4, -0x14(%rbp)
je 0x4b7f
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5057
cmpl $0x4, -0x14(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x20(%rbp), %rax
orl 0x2b04(%rax), %ecx
movl %ecx, 0x2b04(%rax)
cmpl $0x4, -0x14(%rbp)
jne 0x4cd5
cmpl $0x0, -0x28(%rbp)
je 0x4cd5
movl -0x2c(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %r8
movl -0x2c(%rbp), %eax
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %r9
movl %eax, (%rsp)
callq 0x5060
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xab0c(%rax)
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x20(%rax)
movq -0x40(%rbp), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
cmpl $0x0, -0x4c(%rbp)
jge 0x4ca7
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x5057
cmpl $0x0, -0x4c(%rbp)
je 0x4cc7
movq -0x20(%rbp), %rax
movl $0xffffffff, 0xab0c(%rax) # imm = 0xFFFFFFFF
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x5057
jmp 0x4cc9
movl $0x1, -0x4(%rbp)
jmp 0x5057
cmpl $0x4, -0x14(%rbp)
je 0x4ce4
movl -0x2c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2afc(%rax)
je 0x4df4
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x4d17
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %eax
movl %eax, -0x50(%rbp)
jmp 0x4d21
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2b0c, %rsi           # imm = 0x2B0C
movq -0x20(%rbp), %rax
movl 0x2af8(%rax), %eax
addq %rax, %rsi
movl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x3280
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x20(%rax)
movl -0x24(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movl -0x24(%rbp), %edx
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2afc(%rax)
movq -0x20(%rbp), %rax
movl 0x2af8(%rax), %ecx
addl -0x24(%rbp), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
movq -0x20(%rbp), %rax
movl %ecx, 0x2af8(%rax)
movq -0x20(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0xab0c(%rcx)
movb %al, -0x51(%rbp)
jne 0x4ddc
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2afc(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x5057
jmp 0x4df6
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rcx
movl $0x8000, %eax           # imm = 0x8000
subl 0x2af8(%rcx), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rcx
addq $0x2b0c, %rcx           # imm = 0x2B0C
movq -0x20(%rbp), %r8
addq $0x2b0c, %r8            # imm = 0x2B0C
movq -0x20(%rbp), %rax
movl 0x2af8(%rax), %eax
addq %rax, %r8
movl -0x2c(%rbp), %eax
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %r9
movl %eax, (%rsp)
callq 0x5060
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xab0c(%rax)
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2afc(%rax)
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x4ee5
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %eax
movl %eax, -0x58(%rbp)
jmp 0x4eef
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2b0c, %rsi           # imm = 0x2B0C
movq -0x20(%rbp), %rax
movl 0x2af8(%rax), %eax
addq %rax, %rsi
movl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x3280
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x20(%rax)
movl -0x24(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movl -0x24(%rbp), %edx
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2afc(%rax)
movq -0x20(%rbp), %rax
movl 0x2af8(%rax), %ecx
addl -0x24(%rbp), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
movq -0x20(%rbp), %rax
movl %ecx, 0x2af8(%rax)
cmpl $0x0, -0x4c(%rbp)
jge 0x4f97
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x5057
cmpl $0x1, -0x4c(%rbp)
jne 0x4fb0
cmpq $0x0, -0x48(%rbp)
jne 0x4fb0
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x5057
cmpl $0x4, -0x14(%rbp)
jne 0x4ff2
cmpl $0x0, -0x4c(%rbp)
jne 0x4fdb
movq -0x20(%rbp), %rax
movl 0x2afc(%rax), %edx
movl $0x1, %eax
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x5057
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x4fee
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x5057
jmp 0x4ff0
jmp 0x501d
cmpl $0x0, -0x4c(%rbp)
je 0x5019
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x5019
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x5019
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2afc(%rax)
je 0x501b
jmp 0x5026
jmp 0x501d
jmp 0x501f
jmp 0x5021
jmp 0x4df6
xorl %eax, %eax
cmpl $0x0, -0x4c(%rbp)
movb %al, -0x59(%rbp)
jne 0x5044
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2afc(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq