// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
xorl %r12d, %r12d
movl $0x3010, %esi           # imm = 0x3010
xorl %edi, %edi
callq 0x283f4
movq %rax, %rbx
movq %rax, %r15
addq $0x10, %r15
leaq 0x30(%rsp), %r13
movq %r13, %rbp
xorl %r14d, %r14d
callq 0x1faf0
andl $0x3f, %eax
movb %al, (%rbp)
movl %r14d, %esi
shrl $0x3, %esi
movl %r14d, %ecx
andb $0x6, %cl
movl $0x3f, %edx
shll %cl, %edx
notb %dl
andb (%r15,%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, (%r15,%rsi)
andb 0x1(%r15,%rsi), %r8b
shrq %cl, %rax
orb %r8b, %al
movb %al, 0x1(%r15,%rsi)
addq $0x6, %r14
incq %rbp
cmpq $0x18000, %r14          # imm = 0x18000
jne 0x61f59
xorl %esi, %esi
xorl %edx, %edx
movl %esi, %eax
shrl $0x3, %eax
movzbl (%r15,%rax), %edi
movl %esi, %ecx
andb $0x6, %cl
shrl %cl, %edi
movzbl 0x1(%r15,%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 0x6217d
incq %rdx
addl $0x6, %esi
cmpq $0x4000, %rdx           # imm = 0x4000
jne 0x61fbd
incl %r12d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x61f53
movq %rbx, 0x18(%rsp)
movl $0x3000, %edx           # imm = 0x3000
movq %r15, %rdi
xorl %esi, %esi
callq 0x1f110
callq 0x6196f
movq %rax, 0x8(%rsp)
callq 0x1faf0
movslq %eax, %r14
callq 0x1faf0
movl %eax, %ebx
shlq $0x20, %rbx
orq %r14, %rbx
movl $0x1, %r13d
movl $0xa, %ebp
movl $0x1, %r14d
movq %rbx, 0x20(%rsp)
movq %rbx, %rax
xorq %r13, %rax
movq %rax, 0x28(%rsp)
movl $0x8, %edx
movq %r15, %rdi
leaq 0x28(%rsp), %r12
movq %r12, %rsi
callq 0x60b69
movl $0x8, %edx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x61851
cmpq %r14, %r13
jne 0x62140
leaq 0x67f0b(%rip), %rax     # 0xc9fa8
movq 0x790(%rax), %rax
shrq %rax
cmpq %r13, %rax
jbe 0x620bf
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x4(%rax)
jne 0x621d7
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x6160b
movq 0x8(%rsp), %rcx
movq %rax, %r12
movq 0x8(%rcx), %rdi
xorl %esi, %esi
callq 0x6160b
cmpq %rax, %r12
jne 0x621a9
movq %r14, %rdi
xorl %esi, %esi
callq 0x6160b
movq %r13, %rdx
subq %rax, %rdx
movq %rdx, %rcx
negq %rcx
cmovsq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
mulsd 0x3e034(%rip), %xmm0    # 0xa0148
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x3e018(%rip), %xmm0    # 0xa0140
cvttsd2si %xmm0, %rsi
andq %rdx, %rsi
orq %rax, %rsi
movq %rbp, %r14
cmpq %rsi, %rcx
movq 0x20(%rsp), %rbx
ja 0x621bf
incq %r13
addq $0xa, %rbp
cmpq $0x989681, %r13         # imm = 0x989681
jne 0x6205b
leaq 0x686a5(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x2d97c
movq 0x18(%rsp), %rdi
callq 0x2850d
cmpq $0x0, 0x8(%rsp)
jne 0x621f2
jmp 0x621fc
leaq 0x3e053(%rip), %rsi     # 0xa01d7
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x2dc8a
movq %rbx, %rdi
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2850d
leaq 0x3e079(%rip), %rsi     # 0xa0229
movq 0x10(%rsp), %rdi
callq 0x2dc63
movq %r14, %rdi
jmp 0x621ed
leaq 0x3e084(%rip), %rsi     # 0xa024a
movq 0x10(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2dc8a
jmp 0x621e8
leaq 0x3e027(%rip), %rsi     # 0xa0205
movq 0x10(%rsp), %rdi
callq 0x2dc63
movq 0x18(%rsp), %rdi
callq 0x2850d
movq 0x8(%rsp), %rdi
callq 0x30b0c
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq