// File: /workspace/github_c_makefile_star2_O2/imaya[P]zopfli-for-emscripten/deflate.c
// Function: AddLZ77Block
static void AddLZ77Block(const ZopfliOptions* options, int btype, int final,
                         const unsigned short* litlens,
                         const unsigned short* dists,
                         size_t lstart, size_t lend,
                         size_t expected_data_size,
                         unsigned char* bp, unsigned char** out, size_t* outsize) {
  size_t ll_counts[288];
  size_t d_counts[32];
  unsigned ll_lengths[288];
  unsigned d_lengths[32];
  unsigned ll_symbols[288];
  unsigned d_symbols[32];
  size_t detect_block_size = *outsize;
  size_t compressed_size;
  size_t uncompressed_size = 0;
  size_t i;

  AddBit(final, bp, out, outsize);
  AddBit(btype & 1, bp, out, outsize);
  AddBit((btype & 2) >> 1, bp, out, outsize);

  if (btype == 1) {
    /* Fixed block. */
    GetFixedTree(ll_lengths, d_lengths);
  } else {
    /* Dynamic block. */
    unsigned detect_tree_size;
    assert(btype == 2);
    ZopfliLZ77Counts(litlens, dists, lstart, lend, ll_counts, d_counts);
    ZopfliCalculateBitLengths(ll_counts, 288, 15, ll_lengths);
    ZopfliCalculateBitLengths(d_counts, 32, 15, d_lengths);
    PatchDistanceCodesForBuggyDecoders(d_lengths);
    detect_tree_size = *outsize;
    AddDynamicTree(ll_lengths, d_lengths, bp, out, outsize);
    if (options->verbose) {
      fprintf(stderr, "treesize: %d\n", (int)(*outsize - detect_tree_size));
    }

    /* Assert that for every present symbol, the code length is non-zero. */
    /* TODO(lode): remove this in release version. */
    for (i = 0; i < 288; i++) assert(ll_counts[i] == 0 || ll_lengths[i] > 0);
    for (i = 0; i < 32; i++) assert(d_counts[i] == 0 || d_lengths[i] > 0);
  }

  ZopfliLengthsToSymbols(ll_lengths, 288, 15, ll_symbols);
  ZopfliLengthsToSymbols(d_lengths, 32, 15, d_symbols);

  detect_block_size = *outsize;
  AddLZ77Data(litlens, dists, lstart, lend, expected_data_size,
              ll_symbols, ll_lengths, d_symbols, d_lengths,
              bp, out, outsize);
  /* End symbol. */
  AddHuffmanBits(ll_symbols[256], ll_lengths[256], bp, out, outsize);

  for (i = lstart; i < lend; i++) {
    uncompressed_size += dists[i] == 0 ? 1 : litlens[i];
  }
  compressed_size = *outsize - detect_block_size;
  if (options->verbose) {
    fprintf(stderr, "compressed block size: %d (%dk) (unc: %d)\n",
           (int)compressed_size, (int)(compressed_size / 1024),
           (int)(uncompressed_size));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1438, %rsp           # imm = 0x1438
movq %r9, (%rsp)
movq %r8, %r15
movq %rcx, %r13
movl %esi, %r14d
movq %rdi, 0x8(%rsp)
movq 0x1490(%rsp), %rbp
movq 0x1488(%rsp), %r12
movq 0x1480(%rsp), %rbx
movl %edx, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x36b2
movl %r14d, %edi
andl $0x1, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x36b2
movl %r14d, %edi
shrl %edi
andl $0x1, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x36b2
cmpl $0x2, %r14d
movq %r15, 0x18(%rsp)
movq %r13, 0x10(%rsp)
je 0x3453
movq (%rsp), %rbx
cmpl $0x1, %r14d
jne 0x3693
leaq 0x230(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1ed4
leaq 0x230(%rsp), %rdi
pushq $0xf
popq %r14
leaq 0x6b0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movl %r14d, %edx
callq 0x6144
leaq 0x30(%rsp), %rdi
pushq $0x20
popq %rsi
leaq 0xb0(%rsp), %rcx
movl %r14d, %edx
callq 0x6144
movq (%rbp), %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq 0x1470(%rsp), %r14
cmpq %r14, %rbx
jae 0x33d0
movzwl (%r15,%rbx,2), %r12d
movzwl (%r13,%rbx,2), %r14d
testl %r12d, %r12d
movq %rcx, 0x28(%rsp)
je 0x337f
movl %r14d, %edi
callq 0x63d5
movl %eax, %r13d
movl %r12d, %edi
callq 0x6394
leal -0x3(%r14), %ecx
cmpw $0x11e, %cx             # imm = 0x11E
jae 0x35d9
movl %r13d, %ecx
movl 0x230(%rsp,%rcx,4), %esi
testl %esi, %esi
je 0x359b
movq %rbp, %r15
movl %eax, %ebp
cmpl $0x0, 0x30(%rsp,%rbp,4)
je 0x35ba
movl 0x6b0(%rsp,%rcx,4), %edi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq %r15, %r8
callq 0x30d4
movl %r14d, %edi
callq 0x63c7
movl %eax, %r13d
movl %r14d, %edi
callq 0x63b9
movl %r13d, %edi
movl %eax, %esi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq %r15, %r8
callq 0x302a
movl 0xb0(%rsp,%rbp,4), %edi
movl 0x30(%rsp,%rbp,4), %esi
movq 0x1480(%rsp), %rbp
movq %rbp, %rdx
movq 0x1488(%rsp), %rcx
movq %r15, %r8
callq 0x30d4
movl %r12d, %edi
callq 0x636d
movl %eax, %r13d
movl %r12d, %edi
callq 0x6358
movl %r13d, %edi
movl %eax, %esi
movq %rbp, %rdx
movq %r15, %rbp
movq 0x1488(%rsp), %rcx
movq %r15, %r8
callq 0x302a
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
jmp 0x33c0
cmpw $0x100, %r14w           # imm = 0x100
jae 0x35f8
movl %r14d, %eax
movl 0x230(%rsp,%rax,4), %esi
testl %esi, %esi
je 0x3617
movl 0x6b0(%rsp,%rax,4), %edi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq %rbp, %r8
callq 0x30d4
pushq $0x1
popq %r14
movq 0x28(%rsp), %rcx
addq %r14, %rcx
incq %rbx
jmp 0x3262
movq 0x1478(%rsp), %rax
testq %rax, %rax
je 0x33e6
cmpq %rax, %rcx
jne 0x3674
movl 0xab0(%rsp), %edi
movl 0x630(%rsp), %esi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq %rbp, %r8
callq 0x30d4
xorl %r8d, %r8d
pushq $0x1
popq %rax
movq (%rsp), %rdx
movq 0x8(%rsp), %rsi
cmpq %r14, %rdx
jae 0x3438
cmpw $0x0, (%r15,%rdx,2)
movl %eax, %ecx
je 0x3430
movzwl (%r13,%rdx,2), %ecx
addl %ecx, %r8d
incq %rdx
jmp 0x341b
cmpl $0x0, (%rsi)
jne 0x354c
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb30(%rsp), %r14
leaq 0x130(%rsp), %rbx
movq %r13, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq %rdx, %r15
movq 0x1470(%rsp), %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x5020
pushq $0xf
popq %r13
leaq 0x230(%rsp), %r12
movl $0x120, %esi            # imm = 0x120
movq %r14, %rdi
movl %r13d, %edx
movq %r12, %rcx
callq 0x632f
pushq $0x20
popq %rsi
leaq 0x30(%rsp), %r14
movq %rbx, %rdi
movl %r13d, %edx
movq %r14, %rcx
callq 0x632f
movq %r14, %rdi
callq 0x1f47
movq (%rbp), %rbx
movq %r12, %rdi
movq %r14, %rsi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq %rbp, %r8
callq 0x27e9
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3579
xorl %eax, %eax
movq %r15, %rbx
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
cmpq $0x120, %rax            # imm = 0x120
je 0x3525
cmpq $0x0, 0xb30(%rsp,%rax,8)
je 0x3520
cmpl $0x0, 0x230(%rsp,%rax,4)
je 0x3636
incq %rax
jmp 0x34ff
xorl %eax, %eax
cmpq $0x20, %rax
je 0x321e
cmpq $0x0, 0x130(%rsp,%rax,8)
je 0x3547
cmpl $0x0, 0x30(%rsp,%rax,4)
je 0x3655
incq %rax
jmp 0x3527
movq (%rbp), %rdx
subq 0x20(%rsp), %rdx
movq 0x8a9c(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq %rdx, %rcx
shrq $0xa, %rcx
leaq 0x401d(%rip), %rsi      # 0x758a
xorl %eax, %eax
callq 0x10f0
jmp 0x3441
movq 0x8a78(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl (%rbp), %edx
subl %ebx, %edx
leaq 0x3fa1(%rip), %rsi      # 0x7530
xorl %eax, %eax
callq 0x10f0
jmp 0x34f0
leaq 0x4132(%rip), %rdi      # 0x76d4
leaq 0x3d48(%rip), %rsi      # 0x72f1
leaq 0x4012(%rip), %rcx      # 0x75c2
movl $0x108, %edx            # imm = 0x108
callq 0x10b0
leaq 0x4127(%rip), %rdi      # 0x76e8
leaq 0x3d29(%rip), %rsi      # 0x72f1
leaq 0x3ff3(%rip), %rcx      # 0x75c2
movl $0x109, %edx            # imm = 0x109
callq 0x10b0
leaq 0x40d7(%rip), %rdi      # 0x76b7
leaq 0x3d0a(%rip), %rsi      # 0x72f1
leaq 0x3fd4(%rip), %rcx      # 0x75c2
movl $0x107, %edx            # imm = 0x107
callq 0x10b0
leaq 0x3fb6(%rip), %rdi      # 0x75b5
leaq 0x3ceb(%rip), %rsi      # 0x72f1
leaq 0x3fb5(%rip), %rcx      # 0x75c2
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x4082(%rip), %rdi      # 0x76a0
leaq 0x3ccc(%rip), %rsi      # 0x72f1
leaq 0x3f96(%rip), %rcx      # 0x75c2
movl $0x101, %edx            # imm = 0x101
callq 0x10b0
leaq 0x3f01(%rip), %rdi      # 0x753e
leaq 0x3cad(%rip), %rsi      # 0x72f1
leaq 0x3e3d(%rip), %rcx      # 0x7488
movl $0x18f, %edx            # imm = 0x18F
callq 0x10b0
leaq 0x3f09(%rip), %rdi      # 0x7565
leaq 0x3c8e(%rip), %rsi      # 0x72f1
leaq 0x3e1e(%rip), %rcx      # 0x7488
movl $0x190, %edx            # imm = 0x190
callq 0x10b0
leaq 0x407f(%rip), %rdi      # 0x76fa
leaq 0x3c6f(%rip), %rsi      # 0x72f1
leaq 0x3f39(%rip), %rcx      # 0x75c2
movl $0x115, %edx            # imm = 0x115
callq 0x10b0
leaq 0x3c4c(%rip), %rdi      # 0x72e6
leaq 0x3c50(%rip), %rsi      # 0x72f1
leaq 0x3de0(%rip), %rcx      # 0x7488
movl $0x182, %edx            # imm = 0x182
callq 0x10b0