// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zlexcountCommand
void zlexcountCommand(client *c) {
    robj *key = c->argv[1];
    robj *zobj;
    zlexrangespec range;
    int count = 0;

    /* Parse the range arguments */
    if (zslParseLexRange(c->argv[2],c->argv[3],&range) != C_OK) {
        addReplyError(c,"min or max not valid string range item");
        return;
    }

    /* Lookup the sorted set */
    if ((zobj = lookupKeyReadOrReply(c, key, shared.czero)) == NULL ||
        checkType(c, zobj, OBJ_ZSET))
    {
        zslFreeLexRange(&range);
        return;
    }

    if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
        unsigned char *zl = zobj->ptr;
        unsigned char *eptr, *sptr;

        /* Use the first element in range as the starting point */
        eptr = zzlFirstInLexRange(zl,&range);

        /* No "first" element */
        if (eptr == NULL) {
            zslFreeLexRange(&range);
            addReply(c, shared.czero);
            return;
        }

        /* First element is in range */
        sptr = ziplistNext(zl,eptr);
        serverAssertWithInfo(c,zobj,zzlLexValueLteMax(eptr,&range));

        /* Iterate over elements in range */
        while (eptr) {
            /* Abort when the node is no longer in range. */
            if (!zzlLexValueLteMax(eptr,&range)) {
                break;
            } else {
                count++;
                zzlNext(zl,&eptr,&sptr);
            }
        }
    } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
        zset *zs = zobj->ptr;
        zskiplist *zsl = zs->zsl;
        zskiplistNode *zn;
        unsigned long rank;

        /* Find first element in range */
        zn = zslFirstInLexRange(zsl, &range);

        /* Use rank of first element, if any, to determine preliminary count */
        if (zn != NULL) {
            rank = zslGetRank(zsl, zn->score, zn->obj);
            count = (zsl->length - (rank - 1));

            /* Find last element in range */
            zn = zslLastInLexRange(zsl, &range);

            /* Use rank of last element, if any, to determine the actual count */
            if (zn != NULL) {
                rank = zslGetRank(zsl, zn->score, zn->obj);
                count -= (zsl->length - rank);
            }
        }
    } else {
        serverPanic("Unknown sorted set encoding");
    }

    zslFreeLexRange(&range);
    addReplyLongLong(c, count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
callq 0x5646e
testl %eax, %eax
je 0x5826c
leaq 0x6e674(%rip), %rsi     # 0xc68ca
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ffcb
leaq 0xaf03d(%rip), %r13     # 0x1072b0
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x44f89
testq %rax, %rax
je 0x5829e
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
je 0x582c0
movq 0x10(%rsp), %rdi
callq 0x440f3
movq 0x18(%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x440f3
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x5839f
cmpl $0x5, %eax
jne 0x58475
movq 0x8(%r12), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x54a5d
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq %rax, 0x28(%rsp)
je 0x5840e
movq %rax, %r14
movq %r15, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x30(%rsp)
movq %r14, %rdi
callq 0x544b6
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x53e28
movl %eax, %ebp
movq %r13, %rdi
callq 0x440f3
testl %ebp, %ebp
je 0x5848f
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5842e
xorl %r12d, %r12d
leaq 0x30(%rsp), %rbp
callq 0x544b6
movq %rax, %r14
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x53e28
movl %eax, %r13d
movq %r14, %rdi
callq 0x440f3
testl %r13d, %r13d
je 0x58431
incl %r12d
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x545d7
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x58354
jmp 0x58431
movq 0x8(%r12), %rax
movq 0x8(%rax), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x5426f
testq %rax, %rax
je 0x58409
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x53f2f
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r12      # imm = 0xFFFFFFFF00000001
addq %rcx, %r12
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x54345
testq %rax, %rax
je 0x58439
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x53f2f
addl %eax, %r12d
subl 0x10(%r14), %r12d
jmp 0x58439
xorl %r12d, %r12d
jmp 0x58439
movq 0x10(%rsp), %rdi
callq 0x440f3
movq 0x18(%rsp), %rdi
callq 0x440f3
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x3fc19
xorl %r12d, %r12d
cmpq $0x0, 0x28(%rsp)
je 0x58466
movq 0x10(%rsp), %rdi
callq 0x440f3
movq 0x18(%rsp), %rdi
callq 0x440f3
movslq %r12d, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40606
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6b7fa(%rip), %rdi     # 0xc3c76
leaq 0x6e1d3(%rip), %rsi     # 0xc6656
movl $0xa4c, %edx            # imm = 0xA4C
callq 0x6558d
jmp 0x584ae
leaq 0x6e59a(%rip), %rdx     # 0xc6a30
leaq 0x6e1b9(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r12, %rsi
movl $0xa28, %r8d            # imm = 0xA28
callq 0x66380
movl $0x1, %edi
callq 0x263d0