// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x4018, %rsp           # imm = 0x4018
movq %rdi, %rbx
cmpl $0x3, 0x38(%rdi)
jl 0x7e156
movq %rsp, %r14
movl $0x4010, %edx           # imm = 0x4010
movq %r14, %rdi
xorl %esi, %esi
callq 0x26110
movb $-0x1, 0x4(%r14)
movl $0x1, %r12d
leaq 0x10(%rsp), %r14
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %rsi
callq 0x41acf
testq %rax, %rax
je 0x7e135
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7dead
testl %eax, %eax
jne 0x7e235
movq %r14, %rdi
movq %r15, %rsi
callq 0x7dd56
cmpl $-0x1, %eax
je 0x7e21e
incq %r12
movslq 0x38(%rbx), %rax
cmpq %rax, %r12
jl 0x7e0f5
movq %rsp, %rdi
xorl %esi, %esi
callq 0x7daa9
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x7e1d9
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x41ad6
testq %rax, %rax
je 0x7e1e0
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7dead
testl %eax, %eax
jne 0x7e235
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x41f24
movq 0x8(%rax), %r15
movsbq 0xf(%r15), %r14
testq %r14, %r14
js 0x7e201
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
callq 0x3d23f
jmp 0x7e235
leaq 0x84129(%rip), %rax     # 0x102310
movq 0x20(%rax), %rsi
movq %rbx, %rdi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3c854
movq %rsp, %r12
movl $0x0, (%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x7daa9
cmpl $0x0, (%r12)
je 0x7e244
leaq 0x4f9ce(%rip), %rdi     # 0xcdbf3
callq 0x362b0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3ca86
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %r14
movq %rax, 0x8(%r15)
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x41d90
leaq 0x83645(%rip), %rax     # 0x1018a8
incq 0x720(%rax)
jmp 0x7e1d3