// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40e0, %rsp           # imm = 0x40E0
movq %rdi, -0x8(%rbp)
xorl %eax, %eax
movl %eax, %edi
movl $0x3010, %esi           # imm = 0x3010
callq 0x2c000
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
jge 0x84d8d
movl $0x0, -0x10(%rbp)
cmpl $0x4000, -0x10(%rbp)    # imm = 0x4000
jge 0x84c68
callq 0x1fb10
andl $0x3f, %eax
movl %eax, -0x4034(%rbp)
movl -0x4034(%rbp), %eax
movb %al, %cl
movslq -0x10(%rbp), %rax
movb %cl, -0x4030(%rbp,%rax)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x4040(%rbp)
imull $0x6, -0x10(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
movq %rax, -0x4048(%rbp)
imull $0x6, -0x10(%rbp), %eax
andl $0x7, %eax
cltq
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 0x84c5a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x84b2c
movl $0x0, -0x10(%rbp)
cmpl $0x4000, -0x10(%rbp)    # imm = 0x4000
jge 0x84d7d
jmp 0x84c7e
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x4070(%rbp)
imull $0x6, -0x10(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
movq %rax, -0x4078(%rbp)
imull $0x6, -0x10(%rbp), %eax
andl $0x7, %eax
cltq
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
movslq -0x10(%rbp), %rcx
movzbl -0x4030(%rbp,%rcx), %ecx
cmpl %ecx, %eax
je 0x84d6d
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %edx
movslq -0x10(%rbp), %rax
movzbl -0x4030(%rbp,%rax), %ecx
movl -0x4064(%rbp), %r8d
leaq 0x65588(%rip), %rsi     # 0xea2e9
movb $0x0, %al
callq 0x35d80
jmp 0x85009
jmp 0x84d6f
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x84c6f
jmp 0x84d7f
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x84b18
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
movl $0x3000, %edx           # imm = 0x3000
callq 0x1f110
callq 0x83f70
movq %rax, -0x30(%rbp)
movsd 0x65436(%rip), %xmm0    # 0xea1e8
callq 0x1fbb0
movaps %xmm0, %xmm1
movsd 0x6546e(%rip), %xmm0    # 0xea230
divsd %xmm1, %xmm0
movsd %xmm0, -0x40a0(%rbp)
movq $0x1, -0x40a8(%rbp)
callq 0x1fb10
cltq
movq %rax, -0x40c8(%rbp)
callq 0x1fb10
movl %eax, %ecx
movq -0x40c8(%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
jg 0x84ff5
movslq -0xc(%rbp), %rax
xorq -0x40b0(%rbp), %rax
movq %rax, -0x40b8(%rbp)
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
leaq -0x40b8(%rbp), %rsi
movl $0x8, %edx
callq 0x823b0
movq -0x30(%rbp), %rdi
leaq -0x40b8(%rbp), %rsi
movl $0x8, %edx
callq 0x83c60
movslq -0xc(%rbp), %rax
cmpq -0x40a8(%rbp), %rax
jne 0x84eb1
movslq -0xc(%rbp), %rax
leaq 0x8ea86(%rip), %rcx     # 0x1138f8
movq 0x790(%rcx), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x84eb1
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
je 0x84eaf
movq -0x8(%rbp), %rdi
leaq 0x65472(%rip), %rsi     # 0xea317
callq 0x35d40
jmp 0x85009
jmp 0x84eb1
movslq -0xc(%rbp), %rax
cmpq -0x40a8(%rbp), %rax
jne 0x84f07
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x83910
movq %rax, -0x40d0(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x83910
movq %rax, %rcx
movq -0x40d0(%rbp), %rax
cmpq %rcx, %rax
je 0x84f07
movq -0x8(%rbp), %rdi
leaq 0x6543e(%rip), %rsi     # 0xea33b
callq 0x35d40
jmp 0x85009
movslq -0xc(%rbp), %rax
cmpq -0x40a8(%rbp), %rax
jne 0x84fe5
movq -0x40a8(%rbp), %rax
movq %rax, -0x40d8(%rbp)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x83910
movq %rax, %rcx
movq -0x40d8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40c0(%rbp)
cmpq $0x0, -0x40c0(%rbp)
jge 0x84f61
xorl %eax, %eax
subq -0x40c0(%rbp), %rax
movq %rax, -0x40c0(%rbp)
movq -0x40c0(%rbp), %rax
movsd -0x40a0(%rbp), %xmm0
movsd 0x652c0(%rip), %xmm1    # 0xea238
mulsd %xmm1, %xmm0
cvtsi2sdq -0x40a8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x65288(%rip), %xmm1    # 0xea228
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x84fd6
movq -0x8(%rbp), %rdi
movq -0x40a8(%rbp), %rdx
movq -0x40c0(%rbp), %rcx
leaq 0x6538f(%rip), %rsi     # 0xea35c
movb $0x0, %al
callq 0x35d80
jmp 0x85009
imulq $0xa, -0x40a8(%rbp), %rax
movq %rax, -0x40a8(%rbp)
jmp 0x84fe7
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x84e0d
movq -0x8(%rbp), %rdi
leaq 0x8f150(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
movq -0x18(%rbp), %rdi
callq 0x2c160
cmpq $0x0, -0x30(%rbp)
je 0x85022
movq -0x30(%rbp), %rdi
callq 0x3aaa0
addq $0x40e0, %rsp           # imm = 0x40E0
popq %rbp
retq
nopl (%rax,%rax)