// File: Alcaro[P]bridges/arlib/deps/miniz.c
// Function: tdefl_compress_lz_codes
static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
{
  mz_uint flags;
  mz_uint8 *pLZ_codes;
  mz_uint8 *pOutput_buf = d->m_pOutput_buf;
  mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
  mz_uint64 bit_buffer = d->m_bit_buffer;
  mz_uint bits_in = d->m_bits_in;

#define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }

  flags = 1;
  for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
  {
    if (flags == 1)
      flags = *pLZ_codes++ | 0x100;

    if (flags & 1)
    {
      mz_uint s0, s1, n0, n1, sym, num_extra_bits;
      mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;

      MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
      TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
      TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);

      // This sequence coaxes MSVC into using cmov's vs. jmp's.
      s0 = s_tdefl_small_dist_sym[match_dist & 511];
      n0 = s_tdefl_small_dist_extra[match_dist & 511];
      s1 = s_tdefl_large_dist_sym[match_dist >> 8];
      n1 = s_tdefl_large_dist_extra[match_dist >> 8];
      sym = (match_dist < 512) ? s0 : s1;
      num_extra_bits = (match_dist < 512) ? n0 : n1;

      MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
      TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
      TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
    }
    else
    {
      mz_uint lit = *pLZ_codes++;
      MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
      TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);

      if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
      {
        flags >>= 1;
        lit = *pLZ_codes++;
        MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
        TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);

        if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
        {
          flags >>= 1;
          lit = *pLZ_codes++;
          MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
          TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
        }
      }
    }

    if (pOutput_buf >= d->m_pOutput_buf_end)
      return MZ_FALSE;

    *(mz_uint64*)pOutput_buf = bit_buffer;
    pOutput_buf += (bits_in >> 3);
    bit_buffer >>= (bits_in & ~7);
    bits_in &= 7;
  }

#undef TDEFL_PUT_BITS_FAST

  d->m_pOutput_buf = pOutput_buf;
  d->m_bits_in = 0;
  d->m_bit_buffer = 0;

  while (bits_in)
  {
    mz_uint32 n = MZ_MIN(bits_in, 16);
    TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n);
    bit_buffer >>= n;
    bits_in -= n;
  }

  TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);

  return (d->m_pOutput_buf < d->m_pOutput_buf_end);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x92aa, %rax           # imm = 0x92AA
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x6197a
cmpl $0x1, -0x14(%rbp)
jne 0x6151f
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x61757
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x1(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, %edx
leaq 0xa151(%rip), %rcx      # 0x6b6b0
movzwl (%rcx,%rdx,2), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x61572
jmp 0x61591
leaq 0x9e13(%rip), %rdi      # 0x6b38c
leaq 0x9a5c(%rip), %rsi      # 0x6afdc
movl $0x243, %edx            # imm = 0x243
leaq 0x9e34(%rip), %rcx      # 0x6b3c0
callq 0x4200
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, %edx
leaq 0xa10f(%rip), %rcx      # 0x6b6b0
movzwl (%rcx,%rdx,2), %ecx
movzwl 0x888a(%rax,%rcx,2), %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, %edx
leaq 0xa0e5(%rip), %rcx      # 0x6b6b0
movzwl (%rcx,%rdx,2), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x58(%rbp), %eax
movl -0x58(%rbp), %ecx
movl %ecx, %edx
leaq 0xa314(%rip), %rcx      # 0x6b900
movzbl (%rcx,%rdx), %ecx
movl %ecx, %edx
leaq 0xa2b7(%rip), %rcx      # 0x6b8b0
andl (%rcx,%rdx,4), %eax
movl %eax, %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x58(%rbp), %eax
movl %eax, %ecx
leaq 0xa2e8(%rip), %rax      # 0x6b900
movzbl (%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x5c(%rbp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %eax
movl %eax, %ecx
leaq 0x9dfb(%rip), %rax      # 0x6b430
movzbl (%rax,%rcx), %eax
movl %eax, -0x40(%rbp)
movl -0x5c(%rbp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %eax
movl %eax, %ecx
leaq 0xa3b1(%rip), %rax      # 0x6ba00
movzbl (%rax,%rcx), %eax
movl %eax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x9fc9(%rip), %rax      # 0x6b630
movzbl (%rax,%rcx), %eax
movl %eax, -0x44(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0xa581(%rip), %rax      # 0x6bc00
movzbl (%rax,%rcx), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x200, -0x5c(%rbp)     # imm = 0x200
jae 0x61697
movl -0x40(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x6169d
movl -0x44(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x200, -0x5c(%rbp)     # imm = 0x200
jae 0x616b4
movl -0x48(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x616ba
movl -0x4c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
movzbl 0x906a(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x616d6
jmp 0x616f5
leaq 0x9d17(%rip), %rdi      # 0x6b3f4
leaq 0x98f8(%rip), %rsi      # 0x6afdc
movl $0x24f, %edx            # imm = 0x24F
leaq 0x9cd0(%rip), %rcx      # 0x6b3c0
callq 0x4200
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
movzwl 0x8aca(%rax,%rcx,2), %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
movzbl 0x906a(%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x5c(%rbp), %eax
movl -0x54(%rbp), %ecx
movl %ecx, %edx
leaq 0xa17a(%rip), %rcx      # 0x6b8b0
andl (%rcx,%rdx,4), %eax
movl %eax, %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x54(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x61919
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x61782
jmp 0x617a1
leaq 0x9c88(%rip), %rdi      # 0x6b411
leaq 0x984c(%rip), %rsi      # 0x6afdc
movl $0x256, %edx            # imm = 0x256
leaq 0x9c24(%rip), %rcx      # 0x6b3c0
callq 0x4200
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzwl 0x888a(%rax,%rcx,2), %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x61917
movq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x61917
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x61823
jmp 0x61842
leaq 0x9be7(%rip), %rdi      # 0x6b411
leaq 0x97ab(%rip), %rsi      # 0x6afdc
movl $0x25d, %edx            # imm = 0x25D
leaq 0x9b83(%rip), %rcx      # 0x6b3c0
callq 0x4200
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzwl 0x888a(%rax,%rcx,2), %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x61915
movq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x61915
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x618c4
jmp 0x618e3
leaq 0x9b46(%rip), %rdi      # 0x6b411
leaq 0x970a(%rip), %rsi      # 0x6afdc
movl $0x264, %edx            # imm = 0x264
leaq 0x9ae2(%rip), %rcx      # 0x6b3c0
callq 0x4200
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzwl 0x888a(%rax,%rcx,2), %eax
movl -0x3c(%rbp), %ecx
shlq %cl, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movzbl 0x8f4a(%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x61917
jmp 0x61919
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jb 0x61933
movl $0x0, -0x4(%rbp)
jmp 0x61ba1
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %ecx
shrl $0x3, %ecx
movq -0x28(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %ecx
andl $-0x8, %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, -0x14(%rbp)
jmp 0x614f1
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x60(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x61ab4
cmpl $0x10, -0x3c(%rbp)
jae 0x619b4
movl -0x3c(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x619be
movl $0x10, %eax
movl %eax, -0x80(%rbp)
jmp 0x619be
movl -0x80(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rax
movl -0x64(%rbp), %ecx
movl %ecx, %edx
leaq 0x9edc(%rip), %rcx      # 0x6b8b0
andl (%rcx,%rdx,4), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %eax
movl -0x6c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
ja 0x619f8
jmp 0x61a17
leaq 0x98c1(%rip), %rdi      # 0x6b2c0
leaq 0x95d6(%rip), %rsi      # 0x6afdc
movl $0x27c, %edx            # imm = 0x27C
leaq 0x99ae(%rip), %rcx      # 0x6b3c0
callq 0x4200
movl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x5c(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
orl 0x60(%rax), %ecx
movl %ecx, 0x60(%rax)
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x5c(%rax), %ecx
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x5c(%rax)
jb 0x61a92
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x61a76
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rdx
movq 0x40(%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, 0x40(%rdx)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
shrl $0x8, %ecx
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %ecx
subl $0x8, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x61a3c
jmp 0x61a94
movl -0x64(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, -0x38(%rbp)
movl -0x64(%rbp), %ecx
movl -0x3c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6199c
jmp 0x61ab6
movq -0x10(%rbp), %rax
movzwl 0x8a8a(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x904a(%rax), %eax
movl %eax, -0x74(%rbp)
movl -0x70(%rbp), %eax
movl -0x74(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
ja 0x61aea
jmp 0x61b09
leaq 0x97cf(%rip), %rdi      # 0x6b2c0
leaq 0x94e4(%rip), %rsi      # 0x6afdc
movl $0x281, %edx            # imm = 0x281
leaq 0x98bc(%rip), %rcx      # 0x6b3c0
callq 0x4200
movl -0x70(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x5c(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
orl 0x60(%rax), %ecx
movl %ecx, 0x60(%rax)
movl -0x74(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x5c(%rax), %ecx
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x5c(%rax)
jb 0x61b84
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x61b68
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rdx
movq 0x40(%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, 0x40(%rdx)
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
shrl $0x8, %ecx
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %ecx
subl $0x8, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x61b2e
jmp 0x61b86
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
setb %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)