// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: zlexcountCommand
void zlexcountCommand(redisClient *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) != REDIS_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, REDIS_ZSET))
    {
        zslFreeLexRange(&range);
        return;
    }

    if (zobj->encoding == REDIS_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);
        redisAssertWithInfo(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 == REDIS_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 {
        redisPanic("Unknown sorted set encoding");
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x8(%rsp), %rdx
callq 0x3cae5
testl %eax, %eax
je 0x3e5aa
leaq 0x50e35(%rip), %rsi     # 0x8f3c9
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c2da
leaq 0x8924f(%rip), %r13     # 0xc7800
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2f9a9
testq %rax, %rax
je 0x3e5da
movq %rax, %r14
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2eec6
testl %eax, %eax
je 0x3e5f3
leaq 0x8(%rsp), %rdi
callq 0x3ae93
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x3e694
cmpl $0x5, %eax
jne 0x3e73e
movq 0x8(%r14), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x3b6dc
movq %rax, (%rsp)
testq %rax, %rax
je 0x3e723
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x2ae0d
movq %rax, 0x20(%rsp)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x3b6ae
testl %eax, %eax
je 0x3e758
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
leaq 0x20(%rsp), %rbp
testq %r12, %r12
je 0x3e700
movq %r12, %rdi
movq %r14, %rsi
callq 0x3b6ae
testl %eax, %eax
je 0x3e700
incl %r13d
movq %r15, %rdi
movq %rsp, %rsi
movq %rbp, %rdx
callq 0x3b25c
movq (%rsp), %r12
jmp 0x3e661
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3af62
testq %rax, %rax
je 0x3e6fd
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3ad26
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r13      # imm = 0xFFFFFFFF00000001
addq %rcx, %r13
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3b002
testq %rax, %rax
je 0x3e700
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3ad26
addl %eax, %r13d
subl 0x10(%r14), %r13d
jmp 0x3e700
xorl %r13d, %r13d
leaq 0x8(%rsp), %rdi
callq 0x3ae93
movslq %r13d, %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c794
leaq 0x8(%rsp), %rdi
callq 0x3ae93
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x3e5e4
leaq 0x4ec62(%rip), %rdi     # 0x8d3a7
leaq 0x50a77(%rip), %rsi     # 0x8f1c3
movl $0xd91, %edx            # imm = 0xD91
callq 0x490e8
jmp 0x3e777
leaq 0x50dd4(%rip), %rdx     # 0x8f533
leaq 0x50a5d(%rip), %rcx     # 0x8f1c3
movq %rbx, %rdi
movq %r14, %rsi
movl $0xd6d, %r8d            # imm = 0xD6D
callq 0x4980c
pushq $0x1
popq %rdi
callq 0x1f3b0