// File: /workspace/github_c_makefile_star2_O3/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
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 0x36178
movq %rax, %rbx
movq %rax, %r15
addq $0x10, %r15
leaq 0x30(%rsp), %r13
movq %r13, %rbp
xorl %r14d, %r14d
callq 0x26b70
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 0x7e481
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 0x7e6b7
incq %rdx
addl $0x6, %esi
cmpq $0x4000, %rdx           # imm = 0x4000
jne 0x7e4e5
incl %r12d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x7e47b
movq %rbx, 0x18(%rsp)
movl $0x3000, %edx           # imm = 0x3000
movq %r15, %rdi
xorl %esi, %esi
callq 0x26110
callq 0x7de80
movq %rax, 0x8(%rsp)
callq 0x26b70
movslq %eax, %r14
callq 0x26b70
movl %eax, %ebx
shlq $0x20, %rbx
orq %r14, %rbx
movl $0xa, %r12d
movl $0x1, %ebp
movl $0x1, %r14d
movq %rbx, 0x20(%rsp)
movq %rbx, %rax
xorq %rbp, %rax
movq %rax, 0x28(%rsp)
movl $0x8, %edx
movq %r15, %rdi
leaq 0x28(%rsp), %r13
movq %r13, %rsi
callq 0x7cf25
movl $0x8, %edx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x7dd2b
cmpq %r14, %rbp
jne 0x7e67a
leaq 0x832e3(%rip), %rax     # 0x1018a8
movq 0x968(%rax), %rax
shrq %rax
cmpq %rbp, %rax
jbe 0x7e5e7
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpb $0x1, 0x4(%rax)
jne 0x7e711
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x7daa9
movq 0x8(%rsp), %rcx
movq %rax, %r13
movq 0x8(%rcx), %rdi
xorl %esi, %esi
callq 0x7daa9
cmpq %rax, %r13
jne 0x7e6e3
movq %r14, %rdi
xorl %esi, %esi
callq 0x7daa9
movq %rbp, %r14
subq %rax, %r14
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
mulsd 0x4f3d6(%rip), %xmm0    # 0xcda08
callq 0x261a0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x4f3b9(%rip), %xmm0    # 0xcda00
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
cmpq $0xa, %rbp
movl $0x1, %eax
cmoveq %rax, %rdx
movq %r14, %rcx
negq %rcx
cmovsq %r14, %rcx
movq %r12, %r14
cmpq %rdx, %rcx
movq 0x20(%rsp), %rbx
jg 0x7e6f9
incq %rbp
addq $0xa, %r12
cmpq $0x989681, %rbp         # imm = 0x989681
jne 0x7e583
leaq 0x83c7b(%rip), %rax     # 0x102310
movq 0x8(%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x3c854
movq 0x18(%rsp), %rdi
callq 0x36330
cmpq $0x0, 0x8(%rsp)
jne 0x7e72c
jmp 0x7e736
leaq 0x4f3d9(%rip), %rsi     # 0xcda97
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x3cc2d
movq %rbx, %rdi
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36330
leaq 0x4f3ff(%rip), %rsi     # 0xcdae9
movq 0x10(%rsp), %rdi
callq 0x3cc06
movq %r14, %rdi
jmp 0x7e727
leaq 0x4f40a(%rip), %rsi     # 0xcdb0a
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3cc2d
jmp 0x7e722
leaq 0x4f3ad(%rip), %rsi     # 0xcdac5
movq 0x10(%rsp), %rdi
callq 0x3cc06
movq 0x18(%rsp), %rdi
callq 0x36330
movq 0x8(%rsp), %rdi
callq 0x40c8f
addq $0x4038, %rsp           # imm = 0x4038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq