// File: /workspace/github_c_makefile_star2_O2/imaya[P]zopfli-for-emscripten/deflate.c
// Function: ZopfliCalculateBlockSize
double ZopfliCalculateBlockSize(const unsigned short* litlens,
                                const unsigned short* dists,
                                size_t lstart, size_t lend, int btype) {
  size_t ll_counts[288];
  size_t d_counts[32];

  unsigned ll_lengths[288];
  unsigned d_lengths[32];

  double result = 3; /*bfinal and btype bits*/

  assert(btype == 1 || btype == 2); /* This is not for uncompressed blocks. */

  if(btype == 1) {
    GetFixedTree(ll_lengths, d_lengths);
  } else {
    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);
    result += CalculateTreeSize(ll_lengths, d_lengths, ll_counts, d_counts);
  }

  result += CalculateBlockSymbolSize(
      ll_lengths, d_lengths, litlens, dists, lstart, lend);

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf38, %rsp            # imm = 0xF38
movq %rcx, 0x8(%rsp)
leal -0x1(%r8), %eax
cmpl $0x2, %eax
jae 0x1eb5
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x1, %r8d
jne 0x1d23
leaq 0x1b0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1ed4
movsd 0x55b8(%rip), %xmm0     # 0x72d0
movapd %xmm0, 0x10(%rsp)
jmp 0x1e02
leaq 0x630(%rsp), %r13
leaq 0xb0(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
movq %r13, %r8
callq 0x5020
pushq $0xf
popq %rbp
leaq 0x1b0(%rsp), %rbx
movl $0x120, %esi            # imm = 0x120
movq %r13, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x632f
pushq $0x20
popq %rsi
leaq 0x30(%rsp), %r13
leaq 0xb0(%rsp), %rdi
movl %ebp, %edx
movq %r13, %rcx
callq 0x632f
movq %r13, %rdi
callq 0x1f47
leaq 0x28(%rsp), %rbp
andq $0x0, (%rbp)
leaq 0x20(%rsp), %r8
andq $0x0, (%r8)
leaq 0x7(%rsp), %r13
movb $0x0, (%r13)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r8, %rbx
callq 0x27e9
movq (%rbp), %rdi
callq 0x1030
movq (%rbx), %rax
movzbl (%r13), %ecx
andl $0x7, %ecx
leaq (%rcx,%rax,8), %rax
movq %rax, %xmm0
punpckldq 0x54d0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x54d8(%rip), %xmm0     # 0x72c0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x54d4(%rip), %xmm1     # 0x72d0
movapd %xmm1, 0x10(%rsp)
xorl %r13d, %r13d
cmpq 0x8(%rsp), %r14
jae 0x1e6e
cmpw $0x0, (%r15,%r14,2)
movzwl (%r12,%r14,2), %edi
je 0x1e5f
callq 0x63d5
cltq
movl 0x1b0(%rsp,%rax,4), %eax
addq %rax, %r13
movzwl (%r15,%r14,2), %edi
callq 0x6394
cltq
movl 0x30(%rsp,%rax,4), %ebp
movzwl (%r12,%r14,2), %edi
callq 0x63b9
movslq %eax, %rbx
addq %rbp, %rbx
addq %r13, %rbx
movzwl (%r15,%r14,2), %edi
callq 0x6358
movslq %eax, %r13
addq %rbx, %r13
jmp 0x1e69
movl 0x1b0(%rsp,%rdi,4), %eax
addq %rax, %r13
incq %r14
jmp 0x1e05
movl 0x5b0(%rsp), %eax
addq %rax, %r13
movq %r13, %xmm0
punpckldq 0x542b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5433(%rip), %xmm0     # 0x72c0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
addq $0xf38, %rsp            # imm = 0xF38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x541c(%rip), %rdi      # 0x72d8
leaq 0x542e(%rip), %rsi      # 0x72f1
leaq 0x5431(%rip), %rcx      # 0x72fb
movl $0x144, %edx            # imm = 0x144
callq 0x10b0