// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/hyperloglog.c
// Function: pfselftestCommand
void pfselftestCommand(redisClient *c) {
    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 4 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);
            if (abserr < 0) abserr = -abserr;
            if (abserr > (uint64_t)(relerr*4*checkpoint)) {
                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 0x28148
movq %rax, %rbx
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %r13
xorl %ebp, %ebp
callq 0x1faf0
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 0x6243f
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 0x62683
incq %rdx
addq $0x6, %rsi
cmpq $0x4000, %rdx           # imm = 0x4000
jne 0x6249f
incl %r12d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x6243a
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
movl $0x3000, %edx           # imm = 0x3000
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
callq 0x1f110
callq 0x61de9
movq %rax, 0x8(%rsp)
callq 0x1faf0
movslq %eax, %r14
callq 0x1faf0
movl %eax, %r13d
shlq $0x20, %r13
orq %r14, %r13
movl $0x1, %r14d
movl $0x1, %ebp
movq %r15, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq %r15, %r12
movq %r13, %rax
xorq %r14, %rax
movq %rax, 0x28(%rsp)
movl $0x8, %edx
movq 0x10(%rsp), %rdi
movq %rbp, %r15
leaq 0x28(%rsp), %rbp
movq %rbp, %rsi
callq 0x61087
movl $0x8, %edx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rbp
callq 0x61ccb
cmpq %r15, %r14
jne 0x62642
leaq 0x67a17(%rip), %rax     # 0xc9fa8
movq 0x790(%rax), %rax
shrq %rax
cmpq %r14, %rax
jbe 0x625b3
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x4(%rax)
jne 0x626c7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x61b09
movq %rax, %r13
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x61b09
cmpq %rax, %r13
jne 0x626be
movq %rbx, %rdi
xorl %esi, %esi
callq 0x61b09
movq %rbp, %rcx
subq %rax, %rcx
movq %rcx, %r13
negq %r13
cmovsq %rcx, %r13
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
mulsd 0x3dac5(%rip), %xmm0    # 0xa00c8
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x3daad(%rip), %xmm0    # 0xa00c0
cvttsd2si %xmm0, %r15
sarq $0x3f, %rcx
andq %rcx, %r15
orq %rax, %r15
cmpq %r15, %r13
jbe 0x62647
movq 0x18(%rsp), %rdi
leaq 0x3db97(%rip), %rsi     # 0xa01ca
movq %rbp, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2d9fe
jmp 0x6264f
movq %r12, %r15
jmp 0x6265e
addq %rbp, %rbp
leaq (%rbp,%rbp,4), %rbp
cmpq %r15, %r13
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r13
ja 0x626d6
incq %r14
cmpq $0x989681, %r14         # imm = 0x989681
jne 0x62544
leaq 0x6818b(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x2d6f0
jmp 0x626d6
leaq 0x3dacd(%rip), %rsi     # 0xa0157
xorl %r14d, %r14d
movq %r15, %rdi
xorl %eax, %eax
callq 0x2d9fe
movq %rbx, %rdi
callq 0x28204
testq %r14, %r14
je 0x626ac
movq %r14, %rdi
callq 0x30834
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3dae4(%rip), %rsi     # 0xa01a9
jmp 0x626ce
leaq 0x3dab7(%rip), %rsi     # 0xa0185
movq %r12, %rdi
callq 0x2d9d7
movq 0x8(%rsp), %r14
jmp 0x62697