// File: /workspace/github_c_makefile_star2_O0/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 %r15
pushq %r14
pushq %rbx
subq $0x1490, %rsp           # imm = 0x1490
movq 0x14d0(%rsp), %rax
movq 0x14c8(%rsp), %rax
movq 0x14c0(%rsp), %rax
movq 0x14b8(%rsp), %rax
movq 0x14b0(%rsp), %rax
movq %rdi, 0x1488(%rsp)
movl %esi, 0x1484(%rsp)
movl %edx, 0x1480(%rsp)
movq %rcx, 0x1478(%rsp)
movq %r8, 0x1470(%rsp)
movq %r9, 0x1468(%rsp)
movq 0x14d0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq $0x0, 0x48(%rsp)
movl 0x1480(%rsp), %edi
movq 0x14c0(%rsp), %rsi
movq 0x14c8(%rsp), %rdx
movq 0x14d0(%rsp), %rcx
callq 0x4e10
movl 0x1484(%rsp), %edi
andl $0x1, %edi
movq 0x14c0(%rsp), %rsi
movq 0x14c8(%rsp), %rdx
movq 0x14d0(%rsp), %rcx
callq 0x4e10
movl 0x1484(%rsp), %edi
andl $0x2, %edi
sarl %edi
movq 0x14c0(%rsp), %rsi
movq 0x14c8(%rsp), %rdx
movq 0x14d0(%rsp), %rcx
callq 0x4e10
cmpl $0x1, 0x1484(%rsp)
jne 0x4a53
leaq 0x5e0(%rsp), %rdi
leaq 0x560(%rsp), %rsi
callq 0x2960
jmp 0x4c3e
cmpl $0x2, 0x1484(%rsp)
jne 0x4a5f
jmp 0x4a7e
leaq 0x8888(%rip), %rdi      # 0xd2ee
leaq 0x888c(%rip), %rsi      # 0xd2f9
movl $0x182, %edx            # imm = 0x182
leaq 0x8a22(%rip), %rcx      # 0xd49b
callq 0x10b0
movq 0x1478(%rsp), %rdi
movq 0x1470(%rsp), %rsi
movq 0x1468(%rsp), %rdx
movq 0x14b0(%rsp), %rcx
leaq 0xb60(%rsp), %r8
leaq 0xa60(%rsp), %r9
callq 0x9140
leaq 0xb60(%rsp), %rdi
leaq 0x5e0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movl $0xf, %edx
callq 0xb2f0
leaq 0xa60(%rsp), %rdi
leaq 0x560(%rsp), %rcx
movl $0x20, %esi
movl $0xf, %edx
callq 0xb2f0
leaq 0x560(%rsp), %rdi
callq 0x2a80
movq 0x14d0(%rsp), %rax
movq (%rax), %rax
movl %eax, 0x3c(%rsp)
leaq 0x5e0(%rsp), %rdi
leaq 0x560(%rsp), %rsi
movq 0x14c0(%rsp), %rdx
movq 0x14c8(%rsp), %rcx
movq 0x14d0(%rsp), %r8
callq 0x35e0
movq 0x1488(%rsp), %rax
cmpl $0x0, (%rax)
je 0x4b73
movq 0xd4aa(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq 0x14d0(%rsp), %rax
movq (%rax), %rax
movl 0x3c(%rsp), %ecx
subq %rcx, %rax
movl %eax, %edx
leaq 0x89d7(%rip), %rsi      # 0xd543
movb $0x0, %al
callq 0x10f0
movq $0x0, 0x40(%rsp)
cmpq $0x120, 0x40(%rsp)      # imm = 0x120
jae 0x4bd9
movq 0x40(%rsp), %rax
cmpq $0x0, 0xb60(%rsp,%rax,8)
je 0x4ba6
movq 0x40(%rsp), %rax
cmpl $0x0, 0x5e0(%rsp,%rax,4)
jbe 0x4ba8
jmp 0x4bc7
leaq 0x89a2(%rip), %rdi      # 0xd551
leaq 0x8743(%rip), %rsi      # 0xd2f9
movl $0x18f, %edx            # imm = 0x18F
leaq 0x88d9(%rip), %rcx      # 0xd49b
callq 0x10b0
jmp 0x4bc9
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x4b7c
movq $0x0, 0x40(%rsp)
cmpq $0x20, 0x40(%rsp)
jae 0x4c3c
movq 0x40(%rsp), %rax
cmpq $0x0, 0xa60(%rsp,%rax,8)
je 0x4c09
movq 0x40(%rsp), %rax
cmpl $0x0, 0x560(%rsp,%rax,4)
jbe 0x4c0b
jmp 0x4c2a
leaq 0x8966(%rip), %rdi      # 0xd578
leaq 0x86e0(%rip), %rsi      # 0xd2f9
movl $0x190, %edx            # imm = 0x190
leaq 0x8876(%rip), %rcx      # 0xd49b
callq 0x10b0
jmp 0x4c2c
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x4be2
jmp 0x4c3e
leaq 0x5e0(%rsp), %rdi
leaq 0xe0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movl $0xf, %edx
callq 0xaee0
leaq 0x560(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movl $0x20, %esi
movl $0xf, %edx
callq 0xaee0
movq 0x14d0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x1478(%rsp), %rdi
movq 0x1470(%rsp), %rsi
movq 0x1468(%rsp), %rdx
movq 0x14b0(%rsp), %rcx
movq 0x14b8(%rsp), %r8
leaq 0xe0(%rsp), %r9
leaq 0x5e0(%rsp), %r15
leaq 0x60(%rsp), %r14
leaq 0x560(%rsp), %rbx
movq 0x14c0(%rsp), %r11
movq 0x14c8(%rsp), %r10
movq 0x14d0(%rsp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x4f10
movl 0x4e0(%rsp), %edi
movl 0x9e0(%rsp), %esi
movq 0x14c0(%rsp), %rdx
movq 0x14c8(%rsp), %rcx
movq 0x14d0(%rsp), %r8
callq 0x4800
movq 0x1468(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x14b0(%rsp), %rax
jae 0x4da5
movq 0x1470(%rsp), %rax
movq 0x40(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0x4d70
movl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x4d85
movq 0x1478(%rsp), %rax
movq 0x40(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
cltq
addq 0x48(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x4d40
movq 0x14d0(%rsp), %rax
movq (%rax), %rax
subq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x1488(%rsp), %rax
cmpl $0x0, (%rax)
je 0x4df9
movq 0xd22a(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq 0x50(%rsp), %rax
movl %eax, %edx
movq 0x50(%rsp), %rax
shrq $0xa, %rax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %eax, %r8d
leaq 0x87ab(%rip), %rsi      # 0xd59d
movb $0x0, %al
callq 0x10f0
addq $0x1490, %rsp           # imm = 0x1490
popq %rbx
popq %r14
popq %r15
retq
nopw %cs:(%rax,%rax)