// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x51560
cmpl $0x0, %eax
je 0x5400e
movq -0x8(%rbp), %rdi
leaq 0x8f490(%rip), %rsi     # 0xe3494
callq 0x35d40
jmp 0x54243
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0xc0133(%rip), %rax     # 0x114150
movq 0x20(%rax), %rdx
callq 0x3c0c0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x54047
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x3, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x54055
leaq -0x30(%rbp), %rdi
callq 0x4ea60
jmp 0x54243
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x5413e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4f7a0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x540b0
leaq -0x30(%rbp), %rdi
callq 0x4ea60
movq -0x8(%rbp), %rdi
leaq 0xc00ae(%rip), %rax     # 0x114150
movq 0x20(%rax), %rsi
callq 0x35a70
jmp 0x54243
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x33330
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4f760
cmpl $0x0, %eax
je 0x540d5
jmp 0x54100
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x8f51a(%rip), %rdx     # 0xe35fe
leaq 0x8f1a3(%rip), %rcx     # 0xe328e
movl $0xd6d, %r8d            # imm = 0xD6D
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
jmp 0x54102
cmpq $0x0, -0x48(%rbp)
je 0x54139
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4f760
cmpl $0x0, %eax
jne 0x5411d
jmp 0x54139
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x4f100
jmp 0x54102
jmp 0x5422d
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x54209
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4ec10
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x54207
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x68(%rbp), %rax
movq (%rax), %rsi
callq 0x4e640
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
subq %rcx, %rax
movl %eax, -0x34(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4ed50
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x54205
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x68(%rbp), %rax
movq (%rax), %rsi
callq 0x4e640
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
subq -0x70(%rbp), %rcx
movslq -0x34(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x34(%rbp)
jmp 0x54207
jmp 0x5422b
leaq 0x8d28b(%rip), %rdi     # 0xe149b
leaq 0x8f077(%rip), %rsi     # 0xe328e
movl $0xd91, %edx            # imm = 0xD91
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x5422d
leaq -0x30(%rbp), %rdi
callq 0x4ea60
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x36480
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)