// File: /workspace/github_c_makefile_star2_O3/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), %r14
callq 0x41ad6
testq %rax, %rax
je 0x7e795
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7dead
testl %eax, %eax
je 0x7e7b2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4f39e(%rip), %rsi     # 0xcdb3a
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdx
callq 0x41f24
movq %rax, %r15
movq 0x8(%rax), %r13
leaq 0x4f387(%rip), %rsi     # 0xcdb5b
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7e831
leaq 0x4f37b(%rip), %rsi     # 0xcdb62
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7e8ac
leaq 0x44b64(%rip), %rsi     # 0xc3362
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7e8e1
leaq 0x4f384(%rip), %rsi     # 0xcdb99
movq %r14, %rdi
callq 0x262f0
testl %eax, %eax
je 0x7e910
leaq 0x4f375(%rip), %rsi     # 0xcdba1
jmp 0x7e96d
cmpl $0x3, 0x38(%rbx)
jne 0x7e966
cmpb $0x1, 0x4(%r13)
jne 0x7e865
movq %r15, %rdi
callq 0x7d275
cmpl $-0x1, %eax
je 0x7e988
leaq 0x8304e(%rip), %rax     # 0x1018a8
incq 0x720(%rax)
movq 0x8(%r15), %r13
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
callq 0x3d274
xorl %ebp, %ebp
movl %ebp, %eax
shrl $0x3, %eax
movzbl 0x10(%r13,%rax), %ecx
movzbl 0x11(%r13,%rax), %esi
shll $0x8, %esi
orl %ecx, %esi
movl %ebp, %ecx
andb $0x7, %cl
shrl %cl, %esi
andl $0x3f, %esi
movq %rbx, %rdi
callq 0x3d23f
addl $0x6, %ebp
cmpl $0x18000, %ebp          # imm = 0x18000
jne 0x7e874
jmp 0x7e786
cmpl $0x3, 0x38(%rbx)
jne 0x7e966
movzbl -0x1(%r13), %ebp
movl %ebp, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x7e9c7
leaq 0x4f0a8(%rip), %rcx     # 0xcd978
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %ebp
jmp 0x7e9c9
cmpl $0x3, 0x38(%rbx)
jne 0x7e966
movzbl 0x4(%r13), %eax
leaq 0x4f099(%rip), %rcx     # 0xcd98c
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 0x3cdcb
cmpl $0x3, 0x38(%rbx)
jne 0x7e966
movb 0x4(%r13), %bpl
cmpb $0x1, %bpl
jne 0x7e93b
movq %r15, %rdi
callq 0x7d275
cmpl $-0x1, %eax
je 0x7e988
leaq 0x82f74(%rip), %rax     # 0x1018a8
incq 0x720(%rax)
xorl %eax, %eax
cmpb $0x1, %bpl
sete %al
leaq 0x839c5(%rip), %rcx     # 0x102310
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 0x3c854
leaq 0x4f254(%rip), %rsi     # 0xcdbc1
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc2d
leaq 0x4f264(%rip), %rdi     # 0xcdbf3
callq 0x362b0
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ca86
movq -0x11(%r13), %rbp
jmp 0x7e9c9
movzwl -0x5(%r13), %ebp
jmp 0x7e9c9
movl -0x9(%r13), %ebp
jmp 0x7e9c9
movzbl -0x3(%r13), %ebp
jmp 0x7e9c9
xorl %ebp, %ebp
callq 0x3628d
cmpb $0x1, 0x4(%r13)
jne 0x7eaa3
cmpq $0x11, %rbp
jl 0x7ea65
addq %r13, %rbp
addq $0x10, %r13
leaq 0x4f199(%rip), %r14     # 0xcdb8a
leaq 0x4f18c(%rip), %r15     # 0xcdb84
leaq 0x4f191(%rip), %r12     # 0xcdb90
movzbl (%r13), %edx
movl %edx, %ecx
andl $-0x40, %ecx
cmpl $0x40, %ecx
je 0x7ea1f
testl %ecx, %ecx
jne 0x7ea41
incl %edx
incq %r13
movq %rax, %rdi
movq %r15, %rsi
jmp 0x7ea38
andl $0x3f, %edx
shll $0x8, %edx
movzbl 0x1(%r13), %ecx
addl %ecx, %edx
incl %edx
addq $0x2, %r13
movq %rax, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x36f2d
jmp 0x7ea60
movl %edx, %ecx
andl $0x3, %ecx
incl %ecx
shrl $0x2, %edx
andl $0x1f, %edx
incl %edx
incq %r13
movq %rax, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x36f2d
cmpq %rbp, %r13
jb 0x7e9ff
leaq 0x46231(%rip), %rsi     # 0xc4c9d
movq %rax, %rdi
callq 0x376a4
movq %rax, %r14
movq %rax, %rdi
callq 0x7d3fd
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3d346
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36330
leaq 0x4f0bf(%rip), %rsi     # 0xcdb69
jmp 0x7e79c
nop