// File: /workspace/github_c_makefile_star2_O3/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
movq %rsp, %rdx
callq 0x3fa0d
testl %eax, %eax
je 0x4165e
leaq 0x57dbd(%rip), %rsi     # 0x99405
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dc63
leaq 0x8919b(%rip), %r13     # 0xca800
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31745
testq %rax, %rax
je 0x41690
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x30bbf
testl %eax, %eax
je 0x416b1
movq (%rsp), %rdi
callq 0x30b0c
movq 0x8(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30b0c
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4174c
cmpl $0x5, %eax
jne 0x4180d
movq 0x8(%r14), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x3e552
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x417e0
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c558
movq %rax, 0x20(%rsp)
movq %rsp, %rsi
movq %r12, %rdi
callq 0x3e514
testl %eax, %eax
je 0x41827
xorl %r13d, %r13d
movq %rsp, %r14
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
movq %r14, %rsi
callq 0x3e514
testl %eax, %eax
je 0x417b4
incl %r13d
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x3e09f
movq 0x18(%rsp), %r12
testq %r12, %r12
jne 0x4171a
jmp 0x417b4
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
movq %rsp, %rsi
movq %r14, %rdi
callq 0x3dcb3
testq %rax, %rax
je 0x417b1
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3da08
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r13      # imm = 0xFFFFFFFF00000001
addq %rcx, %r13
movq %rsp, %rsi
movq %r14, %rdi
callq 0x3ddbc
testq %rax, %rax
je 0x417b4
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x3da08
addl %eax, %r13d
subl 0x10(%r14), %r13d
jmp 0x417b4
xorl %r13d, %r13d
movq (%rsp), %rdi
callq 0x30b0c
movq 0x8(%rsp), %rdi
callq 0x30b0c
movslq %r13d, %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2e133
movq (%rsp), %rdi
callq 0x30b0c
movq 0x8(%rsp), %rdi
callq 0x30b0c
movq 0x20(%r13), %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d97c
leaq 0x55b9f(%rip), %rdi     # 0x973b3
leaq 0x579e4(%rip), %rsi     # 0x991ff
movl $0xd91, %edx            # imm = 0xD91
callq 0x4cae0
jmp 0x41846
leaq 0x57d41(%rip), %rdx     # 0x9956f
leaq 0x579ca(%rip), %rcx     # 0x991ff
movq %rbx, %rdi
movq %r14, %rsi
movl $0xd6d, %r8d            # imm = 0xD6D
callq 0x4d277
movl $0x1, %edi
callq 0x1f3b0