// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/hyperloglog.c
// Function: pfcountCommand
void pfcountCommand(client *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) != C_OK) return;

            /* Merge with this HLL with our 'max' HHL by setting max[i]
             * to MAX(max[i],hll[i]). */
            if (hllMerge(registers,o) == C_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 = lookupKeyWrite(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) != C_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 %r12
pushq %rbx
subq $0x4010, %rsp           # imm = 0x4010
movq %rdi, %rbx
movl 0x38(%rdi), %ebp
cmpl $0x3, %ebp
jl 0x7149f
movq %rsp, %r14
movl $0x4010, %edx           # imm = 0x4010
movq %r14, %rdi
xorl %esi, %esi
callq 0x26110
movb $-0x1, 0x4(%r14)
pushq $0x1
popq %r12
leaq 0x10(%rsp), %r14
movslq %ebp, %rax
cmpq %rax, %r12
jge 0x71528
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %rsi
callq 0x3aebb
testq %rax, %rax
je 0x71497
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x71238
testl %eax, %eax
jne 0x71592
movq %r14, %rdi
movq %r15, %rsi
callq 0x710c1
cmpl $-0x1, %eax
je 0x7157b
incq %r12
movl 0x38(%rbx), %ebp
jmp 0x7144b
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3aec2
testq %rax, %rax
je 0x7153f
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x71238
testl %eax, %eax
jne 0x71592
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x3b27c
movq 0x8(%rax), %r15
movsbq 0xf(%r15), %r14
testq %r14, %r14
js 0x71561
movl 0x8(%r15), %eax
movzbl 0xc(%r15), %ecx
shlq $0x20, %rcx
movzbl 0xd(%r15), %edx
shlq $0x28, %rdx
movzbl 0xe(%r15), %esi
shlq $0x30, %rsi
shlq $0x38, %r14
orq %rax, %r14
orq %rcx, %r14
orq %rdx, %r14
orq %rsi, %r14
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x71538
movq %rsp, %rdi
xorl %esi, %esi
callq 0x70eca
movq %rbx, %rdi
movq %rax, %rsi
callq 0x370a6
jmp 0x71592
leaq 0x88dca(%rip), %rax     # 0xfa310
movq 0x20(%rax), %rsi
movq %rbx, %rdi
addq $0x4010, %rsp           # imm = 0x4010
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x36987
movq %rsp, %r12
andl $0x0, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x70eca
cmpl $0x0, (%r12)
je 0x715a2
leaq 0x4d236(%rip), %rdi     # 0xbe7b8
callq 0x3115a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x36a9d
addq $0x4010, %rsp           # imm = 0x4010
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rax, 0x8(%r15)
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3b125
leaq 0x882e7(%rip), %rax     # 0xf98a8
incq 0x720(%rax)
jmp 0x71520