// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %r8, %r13
movq %rcx, (%rsp)
movl %esi, %ebx
movq %rdi, 0x10(%rsp)
movq 0x1490(%rsp), %r14
movq 0x1488(%rsp), %r15
movq 0x1480(%rsp), %rbp
movq 0x1470(%rsp), %r12
movl %edx, %edi
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3f8d
movl %ebx, %edi
andl $0x1, %edi
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3f8d
movl %ebx, %edi
shrl %edi
andl $0x1, %edi
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3f8d
movq (%rsp), %rdi
cmpl $0x2, %ebx
je 0x3a82
movq 0x8(%rsp), %r15
cmpl $0x1, %ebx
jne 0x3f6e
leaq 0x230(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x26b7
jmp 0x3bae
leaq 0xb30(%rsp), %rbx
leaq 0x130(%rsp), %r12
movq %r13, %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdx
movq 0x1470(%rsp), %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x7526
leaq 0x230(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movq %rbx, %rdi
movl $0xf, %edx
callq 0x8b29
leaq 0x30(%rsp), %rbx
movl $0x20, %esi
movq %r12, %rdi
movq 0x1470(%rsp), %r12
movl $0xf, %edx
movq %rbx, %rcx
callq 0x8b29
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, 0x30(%rsp,%rax,4)
sbbl $-0x1, %ecx
cmpl $0x1, %ecx
ja 0x3b2c
incq %rax
cmpq $0x1e, %rax
jne 0x3af0
testl %ecx, %ecx
je 0x3b1e
xorl %eax, %eax
cmpl $0x0, 0x30(%rsp)
setne %al
leaq (%rsp,%rax,4), %rbx
addq $0x30, %rbx
jmp 0x3b26
movl $0x1, 0x34(%rsp)
movl $0x1, (%rbx)
movq 0x1490(%rsp), %r8
movq (%r8), %rbx
leaq 0x230(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
callq 0x2fb3
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3e4d
xorl %eax, %eax
cmpq $0x0, 0xb30(%rsp,%rax,8)
je 0x3b82
cmpl $0x0, 0x230(%rsp,%rax,4)
je 0x3e76
incq %rax
cmpq $0x120, %rax            # imm = 0x120
jne 0x3b69
xorl %eax, %eax
cmpq $0x0, 0x130(%rsp,%rax,8)
je 0x3ba5
cmpl $0x0, 0x30(%rsp,%rax,4)
je 0x3e95
incq %rax
cmpq $0x20, %rax
jne 0x3b8f
leaq 0x230(%rsp), %rdi
leaq 0x6b0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movl $0xf, %edx
callq 0x88e8
leaq 0x30(%rsp), %rdi
leaq 0xb0(%rsp), %rcx
movl $0x20, %esi
movl $0xf, %edx
callq 0x88e8
movq 0x1490(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
cmpq %r12, %r15
jae 0x3d8b
movq %r15, %r14
movq (%rsp), %r15
movq %r13, 0x20(%rsp)
movzwl (%r13,%r14,2), %r12d
movzwl (%r15,%r14,2), %ebx
testl %r12d, %r12d
je 0x3d2c
movl %ebx, %edi
callq 0x8bd5
movl %eax, %r13d
movl %r12d, %edi
callq 0x8b94
leal -0x3(%rbx), %ecx
movzwl %cx, %ecx
cmpl $0x11e, %ecx            # imm = 0x11E
jae 0x3ed3
movl %r13d, %ecx
movl 0x230(%rsp,%rcx,4), %esi
testl %esi, %esi
je 0x3ef2
movq %rbp, 0x28(%rsp)
movl %eax, %r15d
cmpl $0x0, 0x30(%rsp,%r15,4)
je 0x3eb4
movl 0x6b0(%rsp,%rcx,4), %edi
movq 0x1480(%rsp), %rbp
movq %rbp, %rdx
movq 0x1488(%rsp), %rcx
movq 0x1490(%rsp), %r8
callq 0x392d
movl %ebx, %edi
callq 0x8bc7
movl %eax, %r13d
movl %ebx, %edi
callq 0x8bb9
movl %r13d, %edi
movl %eax, %esi
movq %rbp, %rdx
movq 0x1488(%rsp), %r13
movq %r13, %rcx
movq 0x1490(%rsp), %r8
callq 0x3876
movl 0xb0(%rsp,%r15,4), %edi
movl 0x30(%rsp,%r15,4), %esi
movq %rbp, %rdx
movq %r13, %rcx
movq 0x1490(%rsp), %r15
movq %r15, %r8
callq 0x392d
movl %r12d, %edi
callq 0x8b69
movl %eax, %r13d
movl %r12d, %edi
callq 0x8b54
movl %r13d, %edi
movl %eax, %esi
movq %rbp, %rdx
movq 0x1488(%rsp), %rcx
movq %r15, %r8
callq 0x3876
movq 0x20(%rsp), %r13
movq (%rsp), %r15
movq 0x1470(%rsp), %r12
movq 0x28(%rsp), %rbp
jmp 0x3d7a
cmpl $0x100, %ebx            # imm = 0x100
jae 0x3f30
movl %ebx, %eax
movl 0x230(%rsp,%rax,4), %esi
testl %esi, %esi
movq 0x1470(%rsp), %r12
je 0x3f11
movl 0x6b0(%rsp,%rax,4), %edi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq 0x1490(%rsp), %r8
callq 0x392d
movl $0x1, %ebx
addq %rbx, %rbp
incq %r14
cmpq %r14, %r12
jne 0x3c10
jmp 0x3d8f
movq (%rsp), %r15
movq 0x1478(%rsp), %rax
testq %rax, %rax
je 0x3da5
cmpq %rax, %rbp
jne 0x3f4f
movl 0xab0(%rsp), %edi
movl 0x630(%rsp), %esi
movq 0x1480(%rsp), %rdx
movq 0x1488(%rsp), %rcx
movq 0x1490(%rsp), %r8
callq 0x392d
xorl %r8d, %r8d
movq 0x8(%rsp), %rcx
cmpq %r12, %rcx
jae 0x3e00
xorl %r8d, %r8d
cmpw $0x0, (%r13,%rcx,2)
je 0x3df0
movzwl (%r15,%rcx,2), %eax
jmp 0x3df5
movl $0x1, %eax
addl %eax, %r8d
incq %rcx
cmpq %rcx, %r12
jne 0x3de0
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3e1c
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1490(%rsp), %rax
movq (%rax), %rdx
subq 0x18(%rsp), %rdx
movq 0xb1c5(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq %rdx, %rcx
shrq $0xa, %rcx
leaq 0x67f6(%rip), %rsi      # 0xa63a
xorl %eax, %eax
callq 0x1100
jmp 0x3e0a
movq 0xb1a4(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq 0x1490(%rsp), %rax
movl (%rax), %edx
subl %ebx, %edx
leaq 0x6776(%rip), %rsi      # 0xa5e0
xorl %eax, %eax
callq 0x1100
jmp 0x3b67
leaq 0x6771(%rip), %rdi      # 0xa5ee
leaq 0x651d(%rip), %rsi      # 0xa3a1
leaq 0x66ad(%rip), %rcx      # 0xa538
movl $0x18f, %edx            # imm = 0x18F
callq 0x10b0
leaq 0x6779(%rip), %rdi      # 0xa615
leaq 0x64fe(%rip), %rsi      # 0xa3a1
leaq 0x668e(%rip), %rcx      # 0xa538
movl $0x190, %edx            # imm = 0x190
callq 0x10b0
leaq 0x68dd(%rip), %rdi      # 0xa798
leaq 0x64df(%rip), %rsi      # 0xa3a1
leaq 0x67a9(%rip), %rcx      # 0xa672
movl $0x109, %edx            # imm = 0x109
callq 0x10b0
leaq 0x688d(%rip), %rdi      # 0xa767
leaq 0x64c0(%rip), %rsi      # 0xa3a1
leaq 0x678a(%rip), %rcx      # 0xa672
movl $0x107, %edx            # imm = 0x107
callq 0x10b0
leaq 0x688b(%rip), %rdi      # 0xa784
leaq 0x64a1(%rip), %rsi      # 0xa3a1
leaq 0x676b(%rip), %rcx      # 0xa672
movl $0x108, %edx            # imm = 0x108
callq 0x10b0
leaq 0x6838(%rip), %rdi      # 0xa750
leaq 0x6482(%rip), %rsi      # 0xa3a1
leaq 0x674c(%rip), %rcx      # 0xa672
movl $0x101, %edx            # imm = 0x101
callq 0x10b0
leaq 0x672e(%rip), %rdi      # 0xa665
leaq 0x6463(%rip), %rsi      # 0xa3a1
leaq 0x672d(%rip), %rcx      # 0xa672
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x6854(%rip), %rdi      # 0xa7aa
leaq 0x6444(%rip), %rsi      # 0xa3a1
leaq 0x670e(%rip), %rcx      # 0xa672
movl $0x115, %edx            # imm = 0x115
callq 0x10b0
leaq 0x6421(%rip), %rdi      # 0xa396
leaq 0x6425(%rip), %rsi      # 0xa3a1
leaq 0x65b5(%rip), %rcx      # 0xa538
movl $0x182, %edx            # imm = 0x182
callq 0x10b0