// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
cmpb $0x0, 0x9d8a8(%rip)     # 0x10e780
jne 0x70f18
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x9d8a5(%rip)     # 0x10e790
pushq $0x1
popq %rcx
leaq 0x9d89b(%rip), %rdx     # 0x10e790
cmpq $0x40, %rcx
je 0x70f11
movq %rcx, %rsi
shlq $0x34, %rsi
movq %rax, %r8
subq %rsi, %r8
movq %r8, (%rdx,%rcx,8)
incq %rcx
jmp 0x70ef5
movb $0x1, 0x9d868(%rip)     # 0x10e780
movzbl 0x4(%rdi), %eax
cmpl $0xff, %eax
je 0x70f6c
cmpl $0x1, %eax
je 0x70f47
testl %eax, %eax
jne 0x71078
addq $0x10, %rdi
leaq 0x9d855(%rip), %rsi     # 0x10e790
leaq 0x4(%rsp), %rdx
callq 0x7045d
jmp 0x70f81
leaq 0x10(%rdi), %r14
callq 0x70863
leal -0x10(%rax), %esi
leaq 0x9d836(%rip), %rdx     # 0x10e790
leaq 0x4(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %r8
callq 0x70d1a
jmp 0x70f81
addq $0x10, %rdi
leaq 0x9d819(%rip), %rsi     # 0x10e790
leaq 0x4(%rsp), %rdx
callq 0x70dcc
movapd %xmm0, %xmm1
movsd 0x41433(%rip), %xmm0    # 0xb23c0
divsd %xmm1, %xmm0
mulsd 0x4d5bf(%rip), %xmm0    # 0xbe558
movsd 0x4d5bf(%rip), %xmm2    # 0xbe560
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd 0x4d5b7(%rip), %xmm1    # 0xbe568
ucomisd %xmm0, %xmm1
seta %cl
movl 0x4(%rsp), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x70fe3
cvtsi2sd %eax, %xmm1
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x264b0
mulsd 0x4d57f(%rip), %xmm0    # 0xbe560
jmp 0x71051
movsd 0x4d585(%rip), %xmm1    # 0xbe570
ucomisd %xmm0, %xmm1
jbe 0x71051
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm2, %xmm3
mulsd 0x4d567(%rip), %xmm2    # 0xbe578
mulsd 0x4d567(%rip), %xmm3    # 0xbe580
addsd %xmm2, %xmm3
mulsd 0x4d563(%rip), %xmm1    # 0xbe588
addsd %xmm3, %xmm1
movsd 0x4d55f(%rip), %xmm2    # 0xbe590
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
addsd 0x4d557(%rip), %xmm2    # 0xbe598
divsd 0x4d557(%rip), %xmm2    # 0xbe5a0
mulsd %xmm0, %xmm2
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
subsd 0x4d547(%rip), %xmm0    # 0xbe5a8
cvttsd2si %xmm0, %rax
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rcx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x4d559(%rip), %rdi     # 0xbe5d8
leaq 0x4d544(%rip), %rsi     # 0xbe5ca
movl $0x3e2, %edx            # imm = 0x3E2
callq 0x57b45
pushq $0x1
popq %rdi
callq 0x263c0