// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4038, %rsp           # imm = 0x4038
movq %rdi, %r15
xorl %r12d, %r12d
movl $0x3010, %esi           # imm = 0x3010
xorl %edi, %edi
callq 0x3910c
movq %rax, %rbx
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %r13
xorl %ebp, %ebp
callq 0x26b80
andl $0x3f, %eax
movb %al, (%r13)
movl %ebp, %esi
shrl $0x3, %esi
movl %ebp, %ecx
andb $0x6, %cl
movb $0x3f, %dl
shlb %cl, %dl
notb %dl
andb 0x10(%rbx,%rsi), %dl
movq %rax, %rdi
shlq %cl, %rdi
orb %dl, %dil
movb $0x8, %dl
subb %cl, %dl
movl $0xffffffc0, %r8d       # imm = 0xFFFFFFC0
movl %edx, %ecx
sarl %cl, %r8d
movb %dil, 0x10(%rbx,%rsi)
andb 0x11(%rbx,%rsi), %r8b
shrq %cl, %rax
orb %r8b, %al
movb %al, 0x11(%rbx,%rsi)
addq $0x6, %rbp
incq %r13
cmpq $0x18000, %rbp          # imm = 0x18000
jne 0x81eda
xorl %esi, %esi
xorl %edx, %edx
movl %esi, %eax
shrl $0x3, %eax
movzbl 0x10(%rbx,%rax), %edi
movl %esi, %ecx
andb $0x6, %cl
shrl %cl, %edi
movzbl 0x11(%rbx,%rax), %r8d
movb $0x8, %al
subb %cl, %al
movl %eax, %ecx
shll %cl, %r8d
orl %edi, %r8d
andl $0x3f, %r8d
movzbl 0x30(%rsp,%rdx), %ecx
cmpl %ecx, %r8d
jne 0x82135
incq %rdx
addq $0x6, %rsi
cmpq $0x4000, %rdx           # imm = 0x4000
jne 0x81f3a
incl %r12d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x81ed5
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
movl $0x3000, %edx           # imm = 0x3000
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
callq 0x26110
callq 0x81834
movq %rax, 0x8(%rsp)
callq 0x26b80
movslq %eax, %r14
callq 0x26b80
movl %eax, %ebp
shlq $0x20, %rbp
orq %r14, %rbp
leaq 0x28(%rsp), %r13
movl $0x1, %r14d
movl $0x1, %ecx
movq %r15, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq %rbp, %rax
xorq %r14, %rax
movq %rax, 0x28(%rsp)
movq %rcx, %r12
movl $0x8, %edx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x8096f
movl $0x8, %edx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x816df
cmpq %r12, %r14
jne 0x820f0
leaq 0x84833(%rip), %rax     # 0x106858
movq 0x958(%rax), %rax
shrq %rax
cmpq %r14, %rax
jbe 0x82047
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x4(%rax)
jne 0x82179
movq %rbx, %rdi
xorl %esi, %esi
callq 0x814e1
movq %rax, %r13
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x814e1
cmpq %rax, %r13
jne 0x82170
movq %rbx, %rdi
xorl %esi, %esi
callq 0x814e1
movq %r12, %rbp
subq %rax, %rbp
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
mulsd 0x4e863(%rip), %xmm0    # 0xd08f0
callq 0x261a0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x4e842(%rip), %xmm0    # 0xd08e8
cvttsd2si %xmm0, %r15
andq %rcx, %r15
orq %rax, %r15
cmpq $0xa, %r14
movl $0x1, %eax
cmoveq %rax, %r15
movq %rbp, %r13
negq %r13
cmovsq %rbp, %r13
cmpq %r15, %r13
jle 0x820f5
movq 0x20(%rsp), %rdi
leaq 0x4e919(%rip), %rsi     # 0xd09f2
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3fff2
movq 0x18(%rsp), %rbp
movq %r12, %rcx
jmp 0x82101
movq %r12, %rcx
jmp 0x82110
addq %r12, %r12
leaq (%r12,%r12,4), %rcx
movq 0x18(%rsp), %rbp
cmpq %r15, %r13
movq 0x20(%rsp), %r15
leaq 0x28(%rsp), %r13
jg 0x82188
incq %r14
cmpq $0x989681, %r14         # imm = 0x989681
jne 0x81fe3
leaq 0x85189(%rip), %rax     # 0x1072b0
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x3fc19
jmp 0x82188
leaq 0x4e843(%rip), %rsi     # 0xd097f
xorl %r14d, %r14d
movq %r15, %rdi
xorl %eax, %eax
callq 0x3fff2
movq %rbx, %rdi
callq 0x392b6
testq %r14, %r14
je 0x8215e
movq %r14, %rdi
callq 0x440f3
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e85a(%rip), %rsi     # 0xd09d1
jmp 0x82180
leaq 0x4e82d(%rip), %rsi     # 0xd09ad
movq %r15, %rdi
callq 0x3ffcb
movq 0x8(%rsp), %r14
jmp 0x82149