// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/hyperloglog.c
// Function: pfdebugCommand
void pfdebugCommand(client *c) {
    char *cmd = c->argv[1]->ptr;
    struct hllhdr *hdr;
    robj *o;
    int j;

    o = lookupKeyWrite(c->db,c->argv[2]);
    if (o == NULL) {
        addReplyError(c,"The specified key does not exist");
        return;
    }
    if (isHLLObjectOrReply(c,o) != C_OK) return;
    o = dbUnshareStringValue(c->db,c->argv[2],o);
    hdr = o->ptr;

    /* PFDEBUG GETREG <key> */
    if (!strcasecmp(cmd,"getreg")) {
        if (c->argc != 3) goto arityerr;

        if (hdr->encoding == HLL_SPARSE) {
            if (hllSparseToDense(o) == C_ERR) {
                addReplySds(c,sdsnew(invalid_hll_err));
                return;
            }
            server.dirty++; /* Force propagation on encoding change. */
        }

        hdr = o->ptr;
        addReplyMultiBulkLen(c,HLL_REGISTERS);
        for (j = 0; j < HLL_REGISTERS; j++) {
            uint8_t val;

            HLL_DENSE_GET_REGISTER(val,hdr->registers,j);
            addReplyLongLong(c,val);
        }
    }
    /* PFDEBUG DECODE <key> */
    else if (!strcasecmp(cmd,"decode")) {
        if (c->argc != 3) goto arityerr;

        uint8_t *p = o->ptr, *end = p+sdslen(o->ptr);
        sds decoded = sdsempty();

        if (hdr->encoding != HLL_SPARSE) {
            addReplyError(c,"HLL encoding is not sparse");
            return;
        }

        p += HLL_HDR_SIZE;
        while(p < end) {
            int runlen, regval;

            if (HLL_SPARSE_IS_ZERO(p)) {
                runlen = HLL_SPARSE_ZERO_LEN(p);
                p++;
                decoded = sdscatprintf(decoded,"z:%d ",runlen);
            } else if (HLL_SPARSE_IS_XZERO(p)) {
                runlen = HLL_SPARSE_XZERO_LEN(p);
                p += 2;
                decoded = sdscatprintf(decoded,"Z:%d ",runlen);
            } else {
                runlen = HLL_SPARSE_VAL_LEN(p);
                regval = HLL_SPARSE_VAL_VALUE(p);
                p++;
                decoded = sdscatprintf(decoded,"v:%d,%d ",regval,runlen);
            }
        }
        decoded = sdstrim(decoded," ");
        addReplyBulkCBuffer(c,decoded,sdslen(decoded));
        sdsfree(decoded);
    }
    /* PFDEBUG ENCODING <key> */
    else if (!strcasecmp(cmd,"encoding")) {
        char *encodingstr[2] = {"dense","sparse"};
        if (c->argc != 3) goto arityerr;

        addReplyStatus(c,encodingstr[hdr->encoding]);
    }
    /* PFDEBUG TODENSE <key> */
    else if (!strcasecmp(cmd,"todense")) {
        int conv = 0;
        if (c->argc != 3) goto arityerr;

        if (hdr->encoding == HLL_SPARSE) {
            if (hllSparseToDense(o) == C_ERR) {
                addReplySds(c,sdsnew(invalid_hll_err));
                return;
            }
            conv = 1;
            server.dirty++; /* Force propagation on encoding change. */
        }
        addReply(c,conv ? shared.cone : shared.czero);
    } else {
        addReplyErrorFormat(c,"Unknown PFDEBUG subcommand '%s'", cmd);
    }
    return;

arityerr:
    addReplyErrorFormat(c,
        "Wrong number of arguments for the '%s' subcommand",cmd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rsi
movq 0x8(%rcx), %r15
callq 0x3aec2
testq %rax, %rax
je 0x71adc
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x71238
testl %eax, %eax
je 0x71af9
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4cc1c(%rip), %rsi     # 0xbe6ff
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36b6f
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdx
callq 0x3b27c
movq %rax, %r12
movq 0x8(%rax), %r14
leaq 0x4cc05(%rip), %rsi     # 0xbe720
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x71b78
leaq 0x4cbf9(%rip), %rsi     # 0xbe727
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x71bf5
leaq 0x42db1(%rip), %rsi     # 0xb48f6
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x71ca1
leaq 0x4cc02(%rip), %rsi     # 0xbe75e
movq %r15, %rdi
callq 0x262f0
testl %eax, %eax
je 0x71cd4
leaq 0x4cbf3(%rip), %rsi     # 0xbe766
jmp 0x71d35
cmpl $0x3, 0x38(%rbx)
jne 0x71d2e
cmpb $0x1, 0x4(%r14)
jne 0x71bad
movq %r12, %rdi
callq 0x706fa
cmpl $-0x1, %eax
je 0x71d9a
leaq 0x87d07(%rip), %rax     # 0xf98a8
incq 0x720(%rax)
movq 0x8(%r12), %r14
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
callq 0x370d9
xorl %ebp, %ebp
cmpl $0x18000, %ebp          # imm = 0x18000
je 0x71acd
movl %ebp, %eax
shrl $0x3, %eax
movzbl 0x10(%r14,%rax), %ecx
movzbl 0x11(%r14,%rax), %esi
shll $0x8, %esi
orl %ecx, %esi
movl %ebp, %ecx
andb $0x7, %cl
shrl %cl, %esi
andl $0x3f, %esi
movq %rbx, %rdi
callq 0x370a6
addl $0x6, %ebp
jmp 0x71bbc
cmpl $0x3, 0x38(%rbx)
jne 0x71d2e
movq %r14, %rdi
callq 0x70863
movq %rax, %r15
callq 0x3114c
cmpb $0x1, 0x4(%r14)
jne 0x71d50
addq %r14, %r15
addq $0x10, %r14
leaq 0x4cb27(%rip), %r12     # 0xbe74f
leaq 0x4cb1a(%rip), %r13     # 0xbe749
leaq 0x4cb1f(%rip), %rbp     # 0xbe755
cmpq %r15, %r14
jae 0x71d5c
movzbl (%r14), %edx
movl %edx, %ecx
andl $-0x40, %ecx
cmpl $0x40, %ecx
je 0x71c5e
testl %ecx, %ecx
jne 0x71c80
incl %edx
incq %r14
movq %rax, %rdi
movq %r13, %rsi
jmp 0x71c77
andl $0x3f, %edx
shll $0x8, %edx
movzbl 0x1(%r14), %ecx
addl %ecx, %edx
incl %edx
addq $0x2, %r14
movq %rax, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x31a38
jmp 0x71c36
movl %edx, %ecx
andl $0x3, %ecx
incl %ecx
shrl $0x2, %edx
andl $0x1f, %edx
incl %edx
incq %r14
movq %rax, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x31a38
jmp 0x71c36
cmpl $0x3, 0x38(%rbx)
jne 0x71d2e
movzbl 0x4(%r14), %eax
leaq 0x4c895(%rip), %rcx     # 0xbe54c
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36cc3
cmpl $0x3, 0x38(%rbx)
jne 0x71d2e
movb 0x4(%r14), %bpl
cmpb $0x1, %bpl
jne 0x71d03
movq %r12, %rdi
callq 0x706fa
cmpl $-0x1, %eax
je 0x71d9a
leaq 0x87bac(%rip), %rax     # 0xf98a8
incq 0x720(%rax)
xorl %eax, %eax
cmpb $0x1, %bpl
sete %al
leaq 0x885fd(%rip), %rcx     # 0xfa310
movq 0x20(%rcx,%rax,8), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36987
leaq 0x4ca51(%rip), %rsi     # 0xbe786
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36b96
leaq 0x4c9d7(%rip), %rsi     # 0xbe72e
jmp 0x71ae3
leaq 0x442ee(%rip), %rsi     # 0xb6051
movq %rax, %rdi
callq 0x31dec
movq %rax, %r14
movq %rax, %rdi
callq 0x70863
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3716c
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x311c8
leaq 0x4ca17(%rip), %rdi     # 0xbe7b8
callq 0x3115a
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36a9d
nop