// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/hyperloglog.c
// Function: pfselftestCommand
void pfselftestCommand(client *c) {
    unsigned int j, i;
    sds bitcounters = sdsnewlen(NULL,HLL_DENSE_SIZE);
    struct hllhdr *hdr = (struct hllhdr*) bitcounters, *hdr2;
    robj *o = NULL;
    uint8_t bytecounters[HLL_REGISTERS];

    /* Test 1: access registers.
     * The test is conceived to test that the different counters of our data
     * structure are accessible and that setting their values both result in
     * the correct value to be retained and not affect adjacent values. */
    for (j = 0; j < HLL_TEST_CYCLES; j++) {
        /* Set the HLL counters and an array of unsigned byes of the
         * same size to the same set of random values. */
        for (i = 0; i < HLL_REGISTERS; i++) {
            unsigned int r = rand() & HLL_REGISTER_MAX;

            bytecounters[i] = r;
            HLL_DENSE_SET_REGISTER(hdr->registers,i,r);
        }
        /* Check that we are able to retrieve the same values. */
        for (i = 0; i < HLL_REGISTERS; i++) {
            unsigned int val;

            HLL_DENSE_GET_REGISTER(val,hdr->registers,i);
            if (val != bytecounters[i]) {
                addReplyErrorFormat(c,
                    "TESTFAILED Register %d should be %d but is %d",
                    i, (int) bytecounters[i], (int) val);
                goto cleanup;
            }
        }
    }

    /* Test 2: approximation error.
     * The test adds unique elements and check that the estimated value
     * is always reasonable bounds.
     *
     * We check that the error is smaller than a few times than the expected
     * standard error, to make it very unlikely for the test to fail because
     * of a "bad" run.
     *
     * The test is performed with both dense and sparse HLLs at the same
     * time also verifying that the computed cardinality is the same. */
    memset(hdr->registers,0,HLL_DENSE_SIZE-HLL_HDR_SIZE);
    o = createHLLObject();
    double relerr = 1.04/sqrt(HLL_REGISTERS);
    int64_t checkpoint = 1;
    uint64_t seed = (uint64_t)rand() | (uint64_t)rand() << 32;
    uint64_t ele;
    for (j = 1; j <= 10000000; j++) {
        ele = j ^ seed;
        hllDenseAdd(hdr->registers,(unsigned char*)&ele,sizeof(ele));
        hllAdd(o,(unsigned char*)&ele,sizeof(ele));

        /* Make sure that for small cardinalities we use sparse
         * encoding. */
        if (j == checkpoint && j < server.hll_sparse_max_bytes/2) {
            hdr2 = o->ptr;
            if (hdr2->encoding != HLL_SPARSE) {
                addReplyError(c, "TESTFAILED sparse encoding not used");
                goto cleanup;
            }
        }

        /* Check that dense and sparse representations agree. */
        if (j == checkpoint && hllCount(hdr,NULL) != hllCount(o->ptr,NULL)) {
                addReplyError(c, "TESTFAILED dense/sparse disagree");
                goto cleanup;
        }

        /* Check error. */
        if (j == checkpoint) {
            int64_t abserr = checkpoint - (int64_t)hllCount(hdr,NULL);
            uint64_t maxerr = ceil(relerr*6*checkpoint);

            /* Adjust the max error we expect for cardinality 10
             * since from time to time it is statistically likely to get
             * much higher error due to collision, resulting into a false
             * positive. */
            if (j == 10) maxerr = 1;

            if (abserr < 0) abserr = -abserr;
            if (abserr > (int64_t)maxerr) {
                addReplyErrorFormat(c,
                    "TESTFAILED Too big error. card:%llu abserr:%llu",
                    (unsigned long long) checkpoint,
                    (unsigned long long) abserr);
                goto cleanup;
            }
            checkpoint *= 10;
        }
    }

    /* Success! */
    addReply(c,shared.ok);

cleanup:
    sdsfree(bitcounters);
    if (o) decrRefCount(o);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40e0, %rsp           # imm = 0x40E0
movq %rdi, -0x8(%rbp)
xorl %eax, %eax
movl %eax, %edi
movl $0x3010, %esi           # imm = 0x3010
callq 0x38230
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3e8, -0xc(%rbp)      # imm = 0x3E8
jae 0xa0860
movl $0x0, -0x10(%rbp)
cmpl $0x4000, -0x10(%rbp)    # imm = 0x4000
jae 0xa0742
callq 0x26b80
andl $0x3f, %eax
movl %eax, -0x4034(%rbp)
movl -0x4034(%rbp), %eax
movb %al, %cl
movl -0x10(%rbp), %eax
movb %cl, -0x4030(%rbp,%rax)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x4040(%rbp)
imull $0x6, -0x10(%rbp), %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, -0x4048(%rbp)
imull $0x6, -0x10(%rbp), %eax
andl $0x7, %eax
movl %eax, %eax
movq %rax, -0x4050(%rbp)
movl $0x8, %eax
subq -0x4050(%rbp), %rax
movq %rax, -0x4058(%rbp)
movl -0x4034(%rbp), %eax
movq %rax, -0x4060(%rbp)
movq -0x4050(%rbp), %rax
movl %eax, %ecx
movl $0x3f, %esi
shll %cl, %esi
xorl $-0x1, %esi
movq -0x4040(%rbp), %rax
movq -0x4048(%rbp), %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x4060(%rbp), %rsi
movq -0x4050(%rbp), %rcx
shlq %cl, %rsi
movq -0x4040(%rbp), %rax
movq -0x4048(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orq %rsi, %rdx
movb %dl, (%rax,%rcx)
movq -0x4058(%rbp), %rax
movl %eax, %ecx
movl $0x3f, %esi
sarl %cl, %esi
xorl $-0x1, %esi
movq -0x4040(%rbp), %rax
movq -0x4048(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edx
andl %esi, %edx
movb %dl, 0x1(%rax,%rcx)
movq -0x4060(%rbp), %rsi
movq -0x4058(%rbp), %rcx
shrq %cl, %rsi
movq -0x4040(%rbp), %rax
movq -0x4048(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edx
orq %rsi, %rdx
movb %dl, 0x1(%rax,%rcx)
jmp 0xa0734
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xa060c
movl $0x0, -0x10(%rbp)
cmpl $0x4000, -0x10(%rbp)    # imm = 0x4000
jae 0xa0850
jmp 0xa0758
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x4070(%rbp)
imull $0x6, -0x10(%rbp), %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, -0x4078(%rbp)
imull $0x6, -0x10(%rbp), %eax
andl $0x7, %eax
movl %eax, %eax
movq %rax, -0x4080(%rbp)
movl $0x8, %eax
subq -0x4080(%rbp), %rax
movq %rax, -0x4088(%rbp)
movq -0x4070(%rbp), %rax
movq -0x4078(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x4090(%rbp)
movq -0x4070(%rbp), %rax
movq -0x4078(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
movq %rax, -0x4098(%rbp)
movq -0x4090(%rbp), %rax
movq -0x4080(%rbp), %rcx
shrq %cl, %rax
movq -0x4098(%rbp), %rdx
movq -0x4088(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
andq $0x3f, %rax
movl %eax, -0x4064(%rbp)
movl -0x4064(%rbp), %eax
movl -0x10(%rbp), %ecx
movzbl -0x4030(%rbp,%rcx), %ecx
cmpl %ecx, %eax
je 0xa0840
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %edx
movl -0x10(%rbp), %eax
movzbl -0x4030(%rbp,%rax), %ecx
movl -0x4064(%rbp), %r8d
leaq 0xa7025(%rip), %rsi     # 0x147859
movb $0x0, %al
callq 0x42fd0
jmp 0xa0af8
jmp 0xa0842
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xa0749
jmp 0xa0852
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xa05f8
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
movl $0x3000, %edx           # imm = 0x3000
callq 0x26110
callq 0x9fa20
movq %rax, -0x30(%rbp)
movsd 0xa6ed3(%rip), %xmm0    # 0x147758
callq 0x26c20
movaps %xmm0, %xmm1
movsd 0xa6f0b(%rip), %xmm0    # 0x1477a0
divsd %xmm1, %xmm0
movsd %xmm0, -0x40a0(%rbp)
movq $0x1, -0x40a8(%rbp)
callq 0x26b80
cltq
movq %rax, -0x40d0(%rbp)
callq 0x26b80
movl %eax, %ecx
movq -0x40d0(%rbp), %rax
movslq %ecx, %rcx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, -0x40b0(%rbp)
movl $0x1, -0xc(%rbp)
cmpl $0x989680, -0xc(%rbp)   # imm = 0x989680
ja 0xa0ae4
movl -0xc(%rbp), %eax
xorq -0x40b0(%rbp), %rax
movq %rax, -0x40b8(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
leaq -0x40b8(%rbp), %rsi
movl $0x8, %edx
callq 0x9ddd0
movq -0x30(%rbp), %rdi
leaq -0x40b8(%rbp), %rsi
movl $0x8, %edx
callq 0x9f710
movl -0xc(%rbp), %eax
cmpq -0x40a8(%rbp), %rax
jne 0xa0981
movl -0xc(%rbp), %eax
leaq 0xd7896(%rip), %rcx     # 0x1781d8
movq 0x968(%rcx), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0xa0981
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
je 0xa097f
movq -0x8(%rbp), %rdi
leaq 0xa6f12(%rip), %rsi     # 0x147887
callq 0x42f90
jmp 0xa0af8
jmp 0xa0981
movl -0xc(%rbp), %eax
cmpq -0x40a8(%rbp), %rax
jne 0xa09d6
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9f3c0
movq %rax, -0x40d8(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9f3c0
movq %rax, %rcx
movq -0x40d8(%rbp), %rax
cmpq %rcx, %rax
je 0xa09d6
movq -0x8(%rbp), %rdi
leaq 0xa6edf(%rip), %rsi     # 0x1478ab
callq 0x42f90
jmp 0xa0af8
movl -0xc(%rbp), %eax
cmpq -0x40a8(%rbp), %rax
jne 0xa0ad4
movq -0x40a8(%rbp), %rax
movq %rax, -0x40e0(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9f3c0
movq %rax, %rcx
movq -0x40e0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40c0(%rbp)
movsd -0x40a0(%rbp), %xmm0
movsd 0xa6d83(%rip), %xmm1    # 0x1477a8
mulsd %xmm1, %xmm0
cvtsi2sdq -0x40a8(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x261a0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0xa6d46(%rip), %xmm1    # 0x147798
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40c8(%rbp)
cmpl $0xa, -0xc(%rbp)
jne 0xa0a79
movq $0x1, -0x40c8(%rbp)
cmpq $0x0, -0x40c0(%rbp)
jge 0xa0a93
xorl %eax, %eax
subq -0x40c0(%rbp), %rax
movq %rax, -0x40c0(%rbp)
movq -0x40c0(%rbp), %rax
cmpq -0x40c8(%rbp), %rax
jle 0xa0ac5
movq -0x8(%rbp), %rdi
movq -0x40a8(%rbp), %rdx
movq -0x40c0(%rbp), %rcx
leaq 0xa6e10(%rip), %rsi     # 0x1478cc
movb $0x0, %al
callq 0x42fd0
jmp 0xa0af8
imulq $0xa, -0x40a8(%rbp), %rax
movq %rax, -0x40a8(%rbp)
jmp 0xa0ad6
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xa08e0
movq -0x8(%rbp), %rdi
leaq 0xd8151(%rip), %rax     # 0x178c40
movq 0x8(%rax), %rsi
callq 0x42cc0
movq -0x18(%rbp), %rdi
callq 0x38620
cmpq $0x0, -0x30(%rbp)
je 0xa0b11
movq -0x30(%rbp), %rdi
callq 0x48f70
addq $0x40e0, %rsp           # imm = 0x40E0
popq %rbp
retq
nopw (%rax,%rax)