// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/hyperloglog.c
// Function: hllCount
uint64_t hllCount(struct hllhdr *hdr, int *invalid) {
    double m = HLL_REGISTERS;
    double E, alpha = 0.7213/(1+1.079/m);
    int j, ez; /* Number of registers equal to 0. */

    /* We precompute 2^(-reg[j]) in a small table in order to
     * speedup the computation of SUM(2^-register[0..i]). */
    static int initialized = 0;
    static double PE[64];
    if (!initialized) {
        PE[0] = 1; /* 2^(-reg[j]) is 1 when m is 0. */
        for (j = 1; j < 64; j++) {
            /* 2^(-reg[j]) is the same as 1/2^reg[j]. */
            PE[j] = 1.0/(1ULL << j);
        }
        initialized = 1;
    }

    /* Compute SUM(2^-register[0..i]). */
    if (hdr->encoding == HLL_DENSE) {
        E = hllDenseSum(hdr->registers,PE,&ez);
    } else if (hdr->encoding == HLL_SPARSE) {
        E = hllSparseSum(hdr->registers,
                         sdslen((sds)hdr)-HLL_HDR_SIZE,PE,&ez,invalid);
    } else if (hdr->encoding == HLL_RAW) {
        E = hllRawSum(hdr->registers,PE,&ez);
    } else {
        serverPanic("Unknown HyperLogLog encoding in hllCount()");
    }

    /* Muliply the inverse of E for alpha_m * m^2 to have the raw estimate. */
    E = (1/E)*alpha*m*m;

    /* Use the LINEARCOUNTING algorithm for small cardinalities.
     * For larger values but up to 72000 HyperLogLog raw approximation is
     * used since linear counting error starts to increase. However HyperLogLog
     * shows a strong bias in the range 2.5*16384 - 72000, so we try to
     * compensate for it. */
    if (E < m*2.5 && ez != 0) {
        E = m*log(m/ez); /* LINEARCOUNTING() */
    } else if (m == 16384 && E < 72000) {
        /* We did polynomial regression of the bias for this range, this
         * way we can compute the bias for a given cardinality and correct
         * according to it. Only apply the correction for P=14 that's what
         * we use and the value the correction was verified with. */
        double bias = 5.9119*1.0e-18*(E*E*E*E)
                      -1.4253*1.0e-12*(E*E*E)+
                      1.2940*1.0e-7*(E*E)
                      -5.2921*1.0e-3*E+
                      83.3216;
        E -= E*(bias/100);
    }
    /* We don't apply the correction for E > 1/30 of 2^32 since we use
     * a 64 bit function and 6 bit counters. To apply the correction for
     * 1/30 of 2^64 is not needed since it would require a huge set
     * to approach such a value. */
    return (uint64_t) E;
}

// Assembly:
pushq %rax
movq %rsi, %r8
cmpb $0x0, 0x98ccc(%rip)     # 0x116780
jne 0x7db78
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x98cc5(%rip)     # 0x116790
xorl %eax, %eax
movdqa 0x3e58b(%rip), %xmm0    # 0xbc060
movdqa 0x3e593(%rip), %xmm1    # 0xbc070
movdqa 0x4febb(%rip), %xmm2    # 0xcd9a0
pshufd $0xf5, %xmm2, %xmm3     # xmm3 = xmm2[1,1,3,3]
leaq 0x98c9f(%rip), %rcx     # 0x116790
movabsq $0x3fe0000000000000, %rdx # imm = 0x3FE0000000000000
movabsq $0x3fd0000000000000, %rsi # imm = 0x3FD0000000000000
movq %rax, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm0, %xmm4
pxor %xmm1, %xmm4
movdqa %xmm2, %xmm5
pcmpgtd %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm4     # xmm4 = xmm4[1,1,3,3]
pcmpeqd %xmm3, %xmm4
pand %xmm5, %xmm4
movd %xmm4, %r9d
testb $0x1, %r9b
je 0x7db49
movq %rax, %r9
shlq $0x34, %r9
movq %rdx, %r10
subq %r9, %r10
movq %r10, 0x8(%rcx,%rax,8)
pextrw $0x4, %xmm4, %r9d
testb $0x1, %r9b
je 0x7db67
movq %rax, %r9
shlq $0x34, %r9
movq %rsi, %r10
subq %r9, %r10
movq %r10, 0x10(%rcx,%rax,8)
addq $0x2, %rax
cmpq $0x40, %rax
jne 0x7db05
movb $0x1, 0x98c08(%rip)     # 0x116780
movzbl 0x4(%rdi), %eax
cmpl $0xff, %eax
je 0x7dbce
cmpl $0x1, %eax
je 0x7dba7
testl %eax, %eax
jne 0x7dd09
addq $0x10, %rdi
leaq 0x98bf5(%rip), %rsi     # 0x116790
leaq 0x4(%rsp), %rdx
callq 0x7cfd1
jmp 0x7dc15
leaq 0x10(%rdi), %rax
movzbl -0x1(%rdi), %esi
movl %esi, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x7dbfc
leaq 0x4fd7c(%rip), %rdx     # 0xcd93c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %esi
jmp 0x7dbfe
addq $0x10, %rdi
leaq 0x98bb7(%rip), %rsi     # 0x116790
leaq 0x4(%rsp), %rdx
callq 0x7d9b0
jmp 0x7dc15
movq -0x11(%rdi), %rsi
jmp 0x7dbfe
movzwl -0x5(%rdi), %esi
jmp 0x7dbfe
movl -0x9(%rdi), %esi
jmp 0x7dbfe
movzbl -0x3(%rdi), %esi
jmp 0x7dbfe
xorl %esi, %esi
addl $-0x10, %esi
leaq 0x98b88(%rip), %rdx     # 0x116790
leaq 0x4(%rsp), %rcx
movq %rax, %rdi
callq 0x7d8ef
movdqa %xmm0, %xmm1
movsd 0x42dff(%rip), %xmm0    # 0xc0a20
divsd %xmm1, %xmm0
mulsd 0x4fd83(%rip), %xmm0    # 0xcd9b0
movsd 0x4fd83(%rip), %xmm2    # 0xcd9b8
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd 0x4fd7b(%rip), %xmm1    # 0xcd9c0
ucomisd %xmm0, %xmm1
seta %cl
movl 0x4(%rsp), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x7dc7a
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x264b0
mulsd 0x4fd40(%rip), %xmm0    # 0xcd9b8
jmp 0x7dce8
movsd 0x4fd46(%rip), %xmm1    # 0xcd9c8
ucomisd %xmm0, %xmm1
jbe 0x7dce8
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm2, %xmm3
mulsd 0x4fd28(%rip), %xmm2    # 0xcd9d0
mulsd 0x4fd28(%rip), %xmm3    # 0xcd9d8
addsd %xmm2, %xmm3
mulsd 0x4fd24(%rip), %xmm1    # 0xcd9e0
addsd %xmm3, %xmm1
movsd 0x4fd20(%rip), %xmm2    # 0xcd9e8
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
addsd 0x4fd18(%rip), %xmm2    # 0xcd9f0
divsd 0x4fd18(%rip), %xmm2    # 0xcd9f8
mulsd %xmm0, %xmm2
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
subsd 0x4fd08(%rip), %xmm0    # 0xcda00
cvttsd2si %xmm0, %rax
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rcx, %rax
popq %rcx
retq
leaq 0x4fd20(%rip), %rdi     # 0xcda30
leaq 0x4fd0b(%rip), %rsi     # 0xcda22
movl $0x3e2, %edx            # imm = 0x3E2
callq 0x619b4
movl $0x1, %edi
callq 0x263c0