// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/hyperloglog.c
// Function: pfcountCommand
void pfcountCommand(redisClient *c) {
    robj *o;
    struct hllhdr *hdr;
    uint64_t card;

    /* Case 1: multi-key keys, cardinality of the union.
     *
     * When multiple keys are specified, PFCOUNT actually computes
     * the cardinality of the merge of the N HLLs specified. */
    if (c->argc > 2) {
        uint8_t max[HLL_HDR_SIZE+HLL_REGISTERS], *registers;
        int j;

        /* Compute an HLL with M[i] = MAX(M[i]_j). */
        memset(max,0,sizeof(max));
        hdr = (struct hllhdr*) max;
        hdr->encoding = HLL_RAW; /* Special internal-only encoding. */
        registers = max + HLL_HDR_SIZE;
        for (j = 1; j < c->argc; j++) {
            /* Check type and size. */
            robj *o = lookupKeyRead(c->db,c->argv[j]);
            if (o == NULL) continue; /* Assume empty HLL for non existing var. */
            if (isHLLObjectOrReply(c,o) != REDIS_OK) return;

            /* Merge with this HLL with our 'max' HHL by setting max[i]
             * to MAX(max[i],hll[i]). */
            if (hllMerge(registers,o) == REDIS_ERR) {
                addReplySds(c,sdsnew(invalid_hll_err));
                return;
            }
        }

        /* Compute cardinality of the resulting set. */
        addReplyLongLong(c,hllCount(hdr,NULL));
        return;
    }

    /* Case 2: cardinality of the single HLL.
     *
     * The user specified a single key. Either return the cached value
     * or compute one and update the cache. */
    o = lookupKeyRead(c->db,c->argv[1]);
    if (o == NULL) {
        /* No key? Cardinality is zero since no element was added, otherwise
         * we would have a key as HLLADD creates it as a side effect. */
        addReply(c,shared.czero);
    } else {
        if (isHLLObjectOrReply(c,o) != REDIS_OK) return;
        o = dbUnshareStringValue(c->db,c->argv[1],o);

        /* Check if the cached cardinality is valid. */
        hdr = o->ptr;
        if (HLL_VALID_CACHE(hdr)) {
            /* Just return the cached value. */
            card = (uint64_t)hdr->card[0];
            card |= (uint64_t)hdr->card[1] << 8;
            card |= (uint64_t)hdr->card[2] << 16;
            card |= (uint64_t)hdr->card[3] << 24;
            card |= (uint64_t)hdr->card[4] << 32;
            card |= (uint64_t)hdr->card[5] << 40;
            card |= (uint64_t)hdr->card[6] << 48;
            card |= (uint64_t)hdr->card[7] << 56;
        } else {
            int invalid = 0;
            /* Recompute it and update the cached value. */
            card = hllCount(hdr,&invalid);
            if (invalid) {
                addReplySds(c,sdsnew(invalid_hll_err));
                return;
            }
            hdr->card[0] = card & 0xff;
            hdr->card[1] = (card >> 8) & 0xff;
            hdr->card[2] = (card >> 16) & 0xff;
            hdr->card[3] = (card >> 24) & 0xff;
            hdr->card[4] = (card >> 32) & 0xff;
            hdr->card[5] = (card >> 40) & 0xff;
            hdr->card[6] = (card >> 48) & 0xff;
            hdr->card[7] = (card >> 56) & 0xff;
            /* This is not considered a read-only command even if the
             * data structure is not modified, since the cached value
             * may be modified and given that the HLL is a Redis string
             * we need to propagate the change. */
            signalModifiedKey(c->db,c->argv[1]);
            server.dirty++;
        }
        addReplyLongLong(c,card);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4018, %rsp           # imm = 0x4018
movq %rdi, %rbx
cmpl $0x3, 0x30(%rdi)
jl 0x620bd
movq %rsp, %r14
movl $0x4010, %edx           # imm = 0x4010
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f110
movb $-0x1, 0x4(%r14)
cmpl $0x2, 0x30(%rbx)
jl 0x620a6
leaq 0x10(%rsp), %r14
movl $0x1, %r13d
leaq 0x3e27c(%rip), %r15     # 0xa02b3
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x3136a
testq %rax, %rax
je 0x62090
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
callq 0x61e16
movl $0x1, %ecx
testl %eax, %eax
jne 0x62095
movq %r14, %rdi
movq %r12, %rsi
callq 0x61cf6
xorl %ecx, %ecx
cmpl $-0x1, %eax
jne 0x62095
movq %r15, %rdi
callq 0x281da
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2d894
movl $0x1, %ecx
jmp 0x62095
movl $0x4, %ecx
testb $0x3, %cl
jne 0x620e5
incq %r13
movslq 0x30(%rbx), %rax
cmpq %rax, %r13
jl 0x62037
movq %rsp, %rdi
xorl %esi, %esi
callq 0x61b09
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2dea3
jmp 0x620e5
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3136a
testq %rax, %rax
je 0x620f7
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x61e16
testl %eax, %eax
je 0x6211b
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68702(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
movq %rbx, %rdi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d6f0
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x317d7
movq 0x8(%rax), %r14
movsbq 0x8(%r14), %rax
testq %rax, %rax
js 0x62199
movzbl 0x9(%r14), %ecx
shll $0x8, %ecx
orq %rax, %rcx
movzbl 0xa(%r14), %eax
shll $0x10, %eax
movzbl 0xb(%r14), %edx
shll $0x18, %edx
orq %rax, %rdx
orq %rcx, %rdx
movzbl 0xc(%r14), %eax
shlq $0x20, %rax
movzbl 0xd(%r14), %ecx
shlq $0x28, %rcx
orq %rax, %rcx
movzbl 0xe(%r14), %eax
shlq $0x30, %rax
orq %rcx, %rax
orq %rdx, %rax
movzbl 0xf(%r14), %r15d
shlq $0x38, %r15
orq %rax, %r15
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x620b6
movq %rsp, %r12
movl $0x0, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x61b09
movq %rax, %r15
movl (%r12), %ebp
testl %ebp, %ebp
je 0x621d3
leaq 0x3e0f2(%rip), %rdi     # 0xa02b3
callq 0x281da
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2d894
jmp 0x621f6
movq %r15, 0x8(%r14)
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x316b7
leaq 0x67db9(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
testl %ebp, %ebp
jne 0x620e5
jmp 0x6218e