// File: /workspace/github_c_makefile_star2_O1/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 $0x1448, %rsp           # imm = 0x1448
movq %r9, 0x8(%rsp)
movq %r8, %rbp
movq %rcx, %r14
movl %esi, %ebx
movq %rdi, 0x18(%rsp)
movq 0x14a0(%rsp), %r12
movq 0x1498(%rsp), %r13
movq 0x1490(%rsp), %r15
movl %edx, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3e81
movl %ebx, %edi
andl $0x1, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3e81
movl %ebx, %edi
shrl %edi
andl $0x1, %edi
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdx
movq %r12, %rcx
callq 0x3e81
movq 0x8(%rsp), %rdx
cmpl $0x2, %ebx
movq %r14, 0x20(%rsp)
je 0x39fc
movq 0x1490(%rsp), %r13
cmpl $0x1, %ebx
jne 0x3e62
leaq 0x240(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x267d
movq 0x1480(%rsp), %rbx
jmp 0x3ae7
leaq 0xb40(%rsp), %rbx
movq %r14, %rdi
leaq 0x140(%rsp), %r14
movq %rbp, %rsi
movq 0x1480(%rsp), %rcx
movq %rbx, %r8
movq %r14, %r9
callq 0x73d7
leaq 0x240(%rsp), %r13
movl $0x120, %esi            # imm = 0x120
movq %rbx, %rdi
movl $0xf, %edx
movq %r13, %rcx
callq 0x89c8
leaq 0x40(%rsp), %rbx
movl $0x20, %esi
movq %r14, %rdi
movl $0xf, %edx
movq %rbx, %rcx
callq 0x89c8
movq %rbx, %rdi
callq 0x26f8
movq (%r12), %r14
movq %r13, %rdi
movq %rbx, %rsi
movq 0x1490(%rsp), %r13
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x2fb2
movq 0x18(%rsp), %r15
cmpl $0x0, (%r15)
jne 0x3d46
xorl %eax, %eax
movq 0x20(%rsp), %r14
movq 0x1480(%rsp), %rbx
cmpq $0x0, 0xb40(%rsp,%rax,8)
je 0x3abb
cmpl $0x0, 0x240(%rsp,%rax,4)
je 0x3d6a
incq %rax
cmpq $0x120, %rax            # imm = 0x120
jne 0x3aa2
xorl %eax, %eax
cmpq $0x0, 0x140(%rsp,%rax,8)
je 0x3ade
cmpl $0x0, 0x40(%rsp,%rax,4)
je 0x3d89
incq %rax
cmpq $0x20, %rax
jne 0x3ac8
leaq 0x240(%rsp), %rdi
leaq 0x6c0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movl $0xf, %edx
callq 0x878c
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rcx
movl $0x20, %esi
movl $0xf, %edx
callq 0x878c
movq (%r12), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %r15
xorl %ecx, %ecx
cmpq %rbx, %r15
jae 0x3c9a
movq %rbp, 0x30(%rsp)
movzwl (%rbp,%r15,2), %eax
movzwl (%r14,%r15,2), %ebx
testl %eax, %eax
movq %rcx, 0x38(%rsp)
je 0x3c42
movl %eax, %ebp
movl %ebx, %edi
callq 0x8a75
movl %eax, %r14d
movl %ebp, 0x14(%rsp)
movl %ebp, %edi
callq 0x8a34
leal -0x3(%rbx), %ecx
movzwl %cx, %ecx
cmpl $0x11e, %ecx            # imm = 0x11E
jae 0x3dc7
movl %r14d, %ecx
movl 0x240(%rsp,%rcx,4), %esi
testl %esi, %esi
je 0x3de6
movq %r12, %rbp
movl %eax, %r12d
cmpl $0x0, 0x40(%rsp,%r12,4)
je 0x3da8
movl 0x6c0(%rsp,%rcx,4), %edi
movq %r13, %rdx
movq 0x1498(%rsp), %rcx
movq %rbp, %r8
callq 0x38a9
movl %ebx, %edi
callq 0x8a67
movl %eax, %r14d
movl %ebx, %edi
callq 0x8a59
movl %r14d, %edi
movl %eax, %esi
movq %r13, %rdx
movq 0x1498(%rsp), %r14
movq %r14, %rcx
movq %rbp, %r8
callq 0x3800
movl 0xc0(%rsp,%r12,4), %edi
movl 0x40(%rsp,%r12,4), %esi
movq %rbp, %r12
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
callq 0x38a9
movl 0x14(%rsp), %ebp
movl %ebp, %edi
callq 0x8a09
movl %eax, %r14d
movl %ebp, %edi
callq 0x89f4
movl %r14d, %edi
movl %eax, %esi
movq %r13, %rdx
movq 0x1498(%rsp), %rcx
movq %r12, %r8
callq 0x3800
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r14
jmp 0x3c7e
cmpl $0x100, %ebx            # imm = 0x100
jae 0x3e24
movl %ebx, %eax
movl 0x240(%rsp,%rax,4), %esi
testl %esi, %esi
je 0x3e05
movl 0x6c0(%rsp,%rax,4), %edi
movq %r13, %rdx
movq 0x1498(%rsp), %rcx
movq %r12, %r8
callq 0x38a9
movl $0x1, %ebx
movq 0x38(%rsp), %rcx
addq %rbx, %rcx
incq %r15
movq 0x1480(%rsp), %rbx
cmpq %r15, %rbx
jne 0x3b40
movq 0x1488(%rsp), %rax
testq %rax, %rax
je 0x3cb0
cmpq %rax, %rcx
jne 0x3e43
movl 0xac0(%rsp), %edi
movl 0x640(%rsp), %esi
movq %r13, %rdx
movq 0x1498(%rsp), %rcx
movq %r12, %r8
callq 0x38a9
xorl %r8d, %r8d
movq 0x8(%rsp), %rdx
cmpq %rbx, %rdx
movq 0x18(%rsp), %rcx
jae 0x3d05
xorl %r8d, %r8d
cmpw $0x0, (%rbp,%rdx,2)
je 0x3cf5
movzwl (%r14,%rdx,2), %eax
jmp 0x3cfa
movl $0x1, %eax
addq %rax, %r8
incq %rdx
cmpq %rdx, %rbx
jne 0x3ce6
cmpl $0x0, (%rcx)
jne 0x3d1c
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdx
subq 0x28(%rsp), %rdx
movq 0xb2cc(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq %rdx, %rcx
shrq $0xa, %rcx
leaq 0x6908(%rip), %rsi      # 0xa645
xorl %eax, %eax
callq 0x10f0
jmp 0x3d0a
movq 0xb2ab(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movl (%r12), %edx
subl %r14d, %edx
leaq 0x688d(%rip), %rsi      # 0xa5eb
xorl %eax, %eax
callq 0x10f0
jmp 0x3a93
leaq 0x6888(%rip), %rdi      # 0xa5f9
leaq 0x6629(%rip), %rsi      # 0xa3a1
leaq 0x67c4(%rip), %rcx      # 0xa543
movl $0x18f, %edx            # imm = 0x18F
callq 0x10b0
leaq 0x6890(%rip), %rdi      # 0xa620
leaq 0x660a(%rip), %rsi      # 0xa3a1
leaq 0x67a5(%rip), %rcx      # 0xa543
movl $0x190, %edx            # imm = 0x190
callq 0x10b0
leaq 0x69f4(%rip), %rdi      # 0xa7a3
leaq 0x65eb(%rip), %rsi      # 0xa3a1
leaq 0x68c0(%rip), %rcx      # 0xa67d
movl $0x109, %edx            # imm = 0x109
callq 0x10b0
leaq 0x69a4(%rip), %rdi      # 0xa772
leaq 0x65cc(%rip), %rsi      # 0xa3a1
leaq 0x68a1(%rip), %rcx      # 0xa67d
movl $0x107, %edx            # imm = 0x107
callq 0x10b0
leaq 0x69a2(%rip), %rdi      # 0xa78f
leaq 0x65ad(%rip), %rsi      # 0xa3a1
leaq 0x6882(%rip), %rcx      # 0xa67d
movl $0x108, %edx            # imm = 0x108
callq 0x10b0
leaq 0x694f(%rip), %rdi      # 0xa75b
leaq 0x658e(%rip), %rsi      # 0xa3a1
leaq 0x6863(%rip), %rcx      # 0xa67d
movl $0x101, %edx            # imm = 0x101
callq 0x10b0
leaq 0x6845(%rip), %rdi      # 0xa670
leaq 0x656f(%rip), %rsi      # 0xa3a1
leaq 0x6844(%rip), %rcx      # 0xa67d
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x696b(%rip), %rdi      # 0xa7b5
leaq 0x6550(%rip), %rsi      # 0xa3a1
leaq 0x6825(%rip), %rcx      # 0xa67d
movl $0x115, %edx            # imm = 0x115
callq 0x10b0
leaq 0x652d(%rip), %rdi      # 0xa396
leaq 0x6531(%rip), %rsi      # 0xa3a1
leaq 0x66cc(%rip), %rcx      # 0xa543
movl $0x182, %edx            # imm = 0x182
callq 0x10b0