// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/hyperloglog.c
// Function: pfdebugCommand
void pfdebugCommand(redisClient *c) {
    char *cmd = c->argv[1]->ptr;
    struct hllhdr *hdr;
    robj *o;
    int j;

    o = lookupKeyRead(c->db,c->argv[2]);
    if (o == NULL) {
        addReplyError(c,"The specified key does not exist");
        return;
    }
    if (isHLLObjectOrReply(c,o) != REDIS_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) == REDIS_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) == REDIS_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 0x8(%rdi), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rsi
movq 0x8(%rcx), %r14
callq 0x3136a
testq %rax, %rax
je 0x6272a
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x61e16
testl %eax, %eax
je 0x62747
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3dac9(%rip), %rsi     # 0xa01fa
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d9d7
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdx
callq 0x317d7
movq %rax, %r15
movq 0x8(%rax), %r13
leaq 0x3dab2(%rip), %rsi     # 0xa021b
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
je 0x627c6
leaq 0x3daa6(%rip), %rsi     # 0xa0222
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
je 0x62841
leaq 0x367f8(%rip), %rsi     # 0x98f8b
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
je 0x62921
leaq 0x3daaf(%rip), %rsi     # 0xa0259
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
je 0x62954
leaq 0x3daa0(%rip), %rsi     # 0xa0261
jmp 0x629b2
cmpl $0x3, 0x30(%rbx)
jne 0x629ab
cmpb $0x1, 0x4(%r13)
jne 0x627f6
movq %r15, %rdi
callq 0x613d7
cmpl $-0x1, %eax
je 0x629d9
leaq 0x677b9(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
movq 0x8(%r15), %r14
movl $0x4000, %esi           # imm = 0x4000
movq %rbx, %rdi
callq 0x2ded8
xorl %ebp, %ebp
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 0x2dea3
addl $0x6, %ebp
cmpl $0x18000, %ebp          # imm = 0x18000
jne 0x62809
jmp 0x6271b
cmpl $0x3, 0x30(%rbx)
jne 0x629ab
movslq -0x8(%r13), %rbp
callq 0x281b2
cmpb $0x1, 0x4(%r13)
jne 0x629cd
cmpl $0x11, %ebp
jl 0x628ea
addq %r13, %rbp
addq $0x10, %r13
leaq 0x3d9d4(%rip), %r14     # 0xa024a
leaq 0x3d9c7(%rip), %r15     # 0xa0244
leaq 0x3d9cc(%rip), %r12     # 0xa0250
movzbl (%r13), %edx
movl %edx, %ecx
andl $-0x40, %ecx
cmpl $0x40, %ecx
je 0x628a4
testl %ecx, %ecx
jne 0x628c6
incl %edx
incq %r13
movq %rax, %rdi
movq %r15, %rsi
jmp 0x628bd
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 0x28760
jmp 0x628e5
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 0x28760
cmpq %rbp, %r13
jb 0x62884
leaq 0x37ad6(%rip), %rsi     # 0x9a3c7
movq %rax, %rdi
callq 0x28b8c
movq %rax, %r14
movslq -0x8(%rax), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2dfa7
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28204
cmpl $0x3, 0x30(%rbx)
jne 0x629ab
movzbl 0x4(%r13), %eax
leaq 0x3d72d(%rip), %rcx     # 0xa0064
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 0x2db27
movl 0x30(%rbx), %ebp
cmpl $0x3, %ebp
jne 0x629ab
movb 0x4(%r13), %r12b
cmpb $0x1, %r12b
jne 0x62985
movq %r15, %rdi
callq 0x613d7
cmpl $-0x1, %eax
je 0x629fe
leaq 0x6762a(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
xorl %eax, %eax
cmpb $0x1, %r12b
sete %al
leaq 0x67e6b(%rip), %rcx     # 0xca800
movq 0x20(%rcx,%rax,8), %rsi
movq %rbx, %rdi
callq 0x2d6f0
cmpl $0x3, %ebp
je 0x6271b
leaq 0x3d8cf(%rip), %rsi     # 0xa0281
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 0x2d9fe
leaq 0x3d855(%rip), %rsi     # 0xa0229
jmp 0x62731
leaq 0x3d8d3(%rip), %rdi     # 0xa02b3
callq 0x281da
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d894
leaq 0x3d8ae(%rip), %rdi     # 0xa02b3
callq 0x281da
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2d894
jmp 0x629a2
nop