// File: /workspace/github_c_makefile_star2_O2/wkoszek[P]mini_gzip/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->crc32 = tinfl_get_crc32(&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); pStream->crc32 = tinfl_get_crc32(&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 $-0x2
popq %rax
testq %rdi, %rdi
je 0x3195
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movq 0x38(%rdi), %rbx
testq %rbx, %rbx
je 0x3187
cmpl $0x1, %esi
pushq $0x2
popq %r13
cmovnel %esi, %r13d
cmpl $0x4, %r13d
ja 0x3187
pushq $0x15
popq %rcx
btl %r13d, %ecx
jae 0x3187
xorl %edx, %edx
cmpl $0x0, 0x2b10(%rbx)
setg %dil
movl 0x8(%r14), %r10d
movl 0x2b08(%rbx), %ecx
andl $0x0, 0x2b08(%rbx)
pushq $-0x3
popq %rsi
cmpl $0x0, 0xab14(%rbx)
js 0x2faa
cmpl $0x4, %r13d
setne %r8b
movl 0x2b0c(%rbx), %esi
testl %esi, %esi
setne %r9b
testb %r9b, %r8b
jne 0x3187
movb %dil, %dl
orl $0x8, %edx
xorl %eax, %eax
cmpl $0x4, %r13d
sete %al
orl %eax, %esi
movl %esi, 0x2b0c(%rbx)
cmpl $0x4, %r13d
jne 0x2fb1
testl %ecx, %ecx
je 0x2fb1
orl $0x4, %edx
leaq 0x20(%rsp), %r15
movq %r10, (%r15)
movl 0x20(%r14), %eax
leaq 0x18(%rsp), %r12
movq %rax, (%r12)
movq (%r14), %rsi
movq 0x18(%r14), %rcx
movl %edx, (%rsp)
movq %rbx, %rdi
movq %r15, %rdx
movq %rcx, %r8
movq %r12, %r9
callq 0x31ac
movl %eax, %ecx
movl %eax, 0xab14(%rbx)
movq (%r15), %rax
movl %eax, %edx
addq %rdx, (%r14)
subl %eax, 0x8(%r14)
addq %rdx, 0x10(%r14)
movsd 0x20(%rbx), %xmm0
xorps %xmm1, %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movups %xmm0, 0x60(%r14)
movq (%r12), %rax
movl %eax, %edx
addq %rdx, 0x18(%r14)
subl %eax, 0x20(%r14)
addq %rdx, 0x28(%r14)
pushq $-0x3
popq %rax
testl %ecx, %ecx
js 0x3187
je 0x3180
orl $-0x1, 0xab14(%rbx)
pushq $-0x5
jmp 0x3186
movl %esi, %eax
jmp 0x3187
movl %edx, %r9d
orl $0x2, %r9d
cmpl $0x4, %r13d
cmovel %edx, %r9d
movl 0x2b04(%rbx), %eax
testl %eax, %eax
je 0x303f
movl 0x20(%r14), %r15d
cmpl %r15d, %eax
cmovbl %eax, %r15d
movq 0x18(%r14), %rdi
movl 0x2b00(%rbx), %eax
leaq (%rbx,%rax), %rsi
addq $0x2b14, %rsi           # imm = 0x2B14
movq %r15, %rdx
callq 0x10e0
addq %r15, 0x18(%r14)
subl %r15d, 0x20(%r14)
addq %r15, 0x28(%r14)
movl 0x2b04(%rbx), %ecx
movl %ecx, %eax
subl %r15d, %eax
movl %eax, 0x2b04(%rbx)
movl 0x2b00(%rbx), %eax
addl %r15d, %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movl %eax, 0x2b00(%rbx)
xorl %eax, %eax
cmpl $0x0, 0xab14(%rbx)
jne 0x3187
xorl %eax, %eax
cmpl %r15d, %ecx
sete %al
jmp 0x3187
leaq 0x2b14(%rbx), %rax
movq %rax, 0x30(%rsp)
movl 0x2b00(%rbx), %ecx
movl %r10d, %edi
movl %r9d, 0x14(%rsp)
movq %r10, 0x28(%rsp)
movq 0x30(%rsp), %r15
movl %edi, %eax
movq %rax, 0x20(%rsp)
movl $0x8000, %eax           # imm = 0x8000
subl %ecx, %eax
movq %rax, 0x18(%rsp)
movq (%r14), %rsi
movl %ecx, %r8d
addq %r15, %r8
movl %r9d, (%rsp)
movq %rbx, %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rcx
leaq 0x18(%rsp), %r9
callq 0x31ac
movl %eax, %r12d
movl %eax, 0xab14(%rbx)
movq 0x20(%rsp), %rax
movl %eax, %ecx
addq %rcx, (%r14)
subl %eax, 0x8(%r14)
addq %rcx, 0x10(%r14)
movsd 0x20(%rbx), %xmm0
unpcklps 0x4d21(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
movups %xmm0, 0x60(%r14)
movl 0x18(%rsp), %ebp
movl %ebp, 0x2b04(%rbx)
movl 0x20(%r14), %eax
cmpl %ebp, %eax
cmovbl %eax, %ebp
movq 0x18(%r14), %rdi
movl 0x2b00(%rbx), %esi
addq %r15, %rsi
movq %rbp, %rdx
callq 0x10e0
addq %rbp, 0x18(%r14)
movl 0x20(%r14), %esi
movl %esi, %eax
subl %ebp, %eax
movl %eax, 0x20(%r14)
addq %rbp, 0x28(%r14)
movl 0x2b04(%rbx), %edx
movl %edx, %eax
subl %ebp, %eax
movl %eax, 0x2b04(%rbx)
movl 0x2b00(%rbx), %ecx
addl %ebp, %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
movl %ecx, 0x2b00(%rbx)
testl %r12d, %r12d
js 0x3184
movl %r12d, %eax
xorl $0x1, %eax
movq 0x28(%rsp), %r10
orl %r10d, %eax
je 0x2fa3
cmpl $0x4, %r13d
jne 0x315e
testl %r12d, %r12d
je 0x3196
cmpl %ebp, %esi
je 0x2fa3
movl 0x8(%r14), %edi
movl 0x14(%rsp), %r9d
jmp 0x3063
testl %r12d, %r12d
je 0x31a3
movl 0x8(%r14), %edi
xorl %eax, %eax
testl %edi, %edi
je 0x3187
cmpl %ebp, %esi
je 0x3187
cmpl %ebp, %edx
movl 0x14(%rsp), %r9d
je 0x3063
jmp 0x3187
pushq $0x1
jmp 0x3186
pushq $-0x3
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %ebp, %edx
pushq $0x1
popq %rcx
pushq $-0x5
popq %rax
cmovel %ecx, %eax
jmp 0x3187
xorl %eax, %eax
cmpl %ebp, %edx
jmp 0x3037