// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
callq 0x3f9d9
testl %eax, %eax
je 0x416ac
leaq 0x57d26(%rip), %rsi     # 0x993bc
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d9d7
leaq 0x8914d(%rip), %r13     # 0xca800
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31475
testq %rax, %rax
je 0x416de
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x308e7
testl %eax, %eax
je 0x41700
movq 0x10(%rsp), %rdi
callq 0x30834
movq 0x18(%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30834
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x417df
cmpl $0x5, %eax
jne 0x418b5
movq 0x8(%r12), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3e403
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq %rax, 0x28(%rsp)
je 0x4184e
movq %rax, %r14
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c2b3
movq %rax, 0x30(%rsp)
movq %r14, %rdi
callq 0x3de5c
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x3d886
movl %eax, %ebp
movq %r13, %rdi
callq 0x30834
testl %ebp, %ebp
je 0x418cf
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4186e
xorl %r12d, %r12d
leaq 0x30(%rsp), %rbp
callq 0x3de5c
movq %rax, %r14
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3d886
movl %eax, %r13d
movq %r14, %rdi
callq 0x30834
testl %r13d, %r13d
je 0x41871
incl %r12d
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x3df7d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x41794
jmp 0x41871
movq 0x8(%r12), %rax
movq 0x8(%rax), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3dc15
testq %rax, %rax
je 0x41849
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3d98d
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r12      # imm = 0xFFFFFFFF00000001
addq %rcx, %r12
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3dceb
testq %rax, %rax
je 0x41879
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3d98d
addl %eax, %r12d
subl 0x10(%r14), %r12d
jmp 0x41879
xorl %r12d, %r12d
jmp 0x41879
movq 0x10(%rsp), %rdi
callq 0x30834
movq 0x18(%rsp), %rdi
callq 0x30834
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x2d6f0
xorl %r12d, %r12d
cmpq $0x0, 0x28(%rsp)
je 0x418a6
movq 0x10(%rsp), %rdi
callq 0x30834
movq 0x18(%rsp), %rdi
callq 0x30834
movslq %r12d, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dea3
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55a97(%rip), %rdi     # 0x97353
leaq 0x578f3(%rip), %rsi     # 0x991b6
movl $0xd91, %edx            # imm = 0xD91
callq 0x4d0e5
jmp 0x418ee
leaq 0x57c50(%rip), %rdx     # 0x99526
leaq 0x578d9(%rip), %rcx     # 0x991b6
movq %rbx, %rdi
movq %r12, %rsi
movl $0xd6d, %r8d            # imm = 0xD6D
callq 0x4d872
movl $0x1, %edi
callq 0x1f3b0