// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/tree.c
// Function: ZopfliCalculateEntropy
void ZopfliCalculateEntropy(const size_t* count, size_t n, double* bitlengths) {
  static const double kInvLog2 = 1.4426950408889;  /* 1.0 / log(2.0) */
  unsigned sum = 0;
  unsigned i;
  double log2sum;
  for (i = 0; i < n; ++i) {
    sum += count[i];
  }
  log2sum = (sum == 0 ? log(n) : log(sum)) * kInvLog2;
  for (i = 0; i < n; ++i) {
    /* When the count of the symbol is 0, but its cost is requested anyway, it
    means the symbol will appear at least once anyway, so give it the cost as if
    its count is 1.*/
    if (count[i] == 0) bitlengths[i] = log2sum;
    else bitlengths[i] = log2sum - log(count[i]) * kInvLog2;
    /* Depending on compiler and architecture, the above subtraction of two
    floating point numbers may give a negative result very close to zero
    instead of zero (e.g. -5.973954e-17 with gcc 4.1.2 on Ubuntu 11.4). Clamp
    it to zero. These floating point imprecisions do not affect the cost model
    significantly so this is ok. */
    if (bitlengths[i] < 0 && bitlengths[i] > -1e-5) bitlengths[i] = 0;
    assert(bitlengths[i] >= 0);
  }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpq 0x28(%rsp), %rax
jae 0xb133
movq 0x30(%rsp), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rcx
movl 0x1c(%rsp), %eax
addq %rcx, %rax
movl %eax, 0x1c(%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xb103
cmpl $0x0, 0x1c(%rsp)
jne 0xb16f
movaps 0x217f(%rip), %xmm1     # 0xd2c0
movq 0x28(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x217d(%rip), %xmm1     # 0xd2d0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x10d0
movsd %xmm0, 0x8(%rsp)
jmp 0xb183
movl 0x1c(%rsp), %eax
cvtsi2sd %rax, %xmm0
callq 0x10d0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x2f57(%rip), %xmm1     # 0xe0e8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpq 0x28(%rsp), %rax
jae 0xb2dc
movq 0x30(%rsp), %rax
movl 0x18(%rsp), %ecx
cmpq $0x0, (%rax,%rcx,8)
jne 0xb1d8
movsd 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
jmp 0xb252
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x30(%rsp), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %xmm0
movaps 0x20c8(%rip), %xmm1     # 0xd2c0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x20cc(%rip), %xmm1     # 0xd2d0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x10d0
movsd (%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x2eac(%rip), %xmm2     # 0xe0e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
xorps %xmm0, %xmm0
ucomisd (%rax,%rcx,8), %xmm0
jbe 0xb292
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movsd 0x2e75(%rip), %xmm1     # 0xe0f0
ucomisd %xmm1, %xmm0
jbe 0xb292
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movl 0x18(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xb2ab
jmp 0xb2ca
leaq 0x2ebb(%rip), %rdi      # 0xe16d
leaq 0x2e55(%rip), %rsi      # 0xe10e
movl $0x5c, %edx
leaq 0x2ebb(%rip), %rcx      # 0xe180
callq 0x10b0
jmp 0xb2cc
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0xb1a3
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)