// File: /workspace/github_c_makefile_star2_O3/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 0x2698
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
cmpl $0x1, %r8d
jne 0x24bf
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x26b7
movsd 0x7ecc(%rip), %xmm0     # 0xa380
movapd %xmm0, 0x10(%rsp)
jmp 0x25db
leaq 0x630(%rsp), %r13
leaq 0x530(%rsp), %rbp
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0x7526
leaq 0xb0(%rsp), %rcx
movl $0x120, %esi            # imm = 0x120
movq %r13, %rdi
movl $0xf, %edx
callq 0x8b29
leaq 0x30(%rsp), %r13
movl $0x20, %esi
movq %rbp, %rdi
movl $0xf, %edx
movq %r13, %rcx
callq 0x8b29
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, 0x30(%rsp,%rax,4)
sbbl $-0x1, %ecx
cmpl $0x1, %ecx
ja 0x255e
incq %rax
cmpq $0x1e, %rax
jne 0x2520
testl %ecx, %ecx
je 0x254e
xorl %eax, %eax
cmpl $0x0, 0x30(%rsp)
setne %al
leaq (%rsp,%rax,4), %r13
addq $0x30, %r13
jmp 0x2556
movl $0x1, 0x34(%rsp)
movl $0x1, (%r13)
xorl %eax, %eax
leaq 0x28(%rsp), %r13
movq %rax, (%r13)
leaq 0x20(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x7(%rsp), %rbp
movb $0x0, (%rbp)
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq 0x2fb3
movq (%r13), %rdi
callq 0x1030
movq (%rbx), %rax
movzbl (%rbp), %ecx
andl $0x7, %ecx
leaq (%rcx,%rax,8), %rax
movq %rax, %xmm0
punpckldq 0x7d67(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x7d6f(%rip), %xmm0     # 0xa330
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x7dab(%rip), %xmm1     # 0xa380
movapd %xmm1, 0x10(%rsp)
cmpq 0x8(%rsp), %r14
jae 0x264e
xorl %r13d, %r13d
cmpw $0x0, (%r15,%r14,2)
movzwl (%r12,%r14,2), %edi
je 0x2638
callq 0x8bd5
cltq
movl 0xb0(%rsp,%rax,4), %eax
addq %rax, %r13
movzwl (%r15,%r14,2), %edi
callq 0x8b94
cltq
movl 0x30(%rsp,%rax,4), %ebp
movzwl (%r12,%r14,2), %edi
callq 0x8bb9
movslq %eax, %rbx
addq %rbp, %rbx
addq %r13, %rbx
movzwl (%r15,%r14,2), %edi
callq 0x8b54
movslq %eax, %r13
addq %rbx, %r13
jmp 0x2642
movl 0xb0(%rsp,%rdi,4), %eax
addq %rax, %r13
incq %r14
cmpq %r14, 0x8(%rsp)
jne 0x25e5
jmp 0x2651
xorl %r13d, %r13d
movl 0x4b0(%rsp), %eax
addq %r13, %rax
movq %rax, %xmm0
punpckldq 0x7cb8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x7cc0(%rip), %xmm0     # 0xa330
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 0x7ce9(%rip), %rdi      # 0xa388
leaq 0x7cfb(%rip), %rsi      # 0xa3a1
leaq 0x7cfe(%rip), %rcx      # 0xa3ab
movl $0x144, %edx            # imm = 0x144
callq 0x10b0