// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x8(%rsp), %rdx
callq 0x4a19e
testl %eax, %eax
je 0x4bc57
leaq 0x69185(%rip), %rsi     # 0xb4dc6
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36b6f
leaq 0xae6b2(%rip), %r13     # 0xfa310
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3aee5
testq %rax, %rax
je 0x4bc87
movq %rax, %r14
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x4bca0
leaq 0x8(%rsp), %rdi
callq 0x4832a
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 0x4bd41
cmpl $0x5, %eax
jne 0x4bdeb
movq 0x8(%r14), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x48b73
movq %rax, (%rsp)
testq %rax, %rax
je 0x4bdd0
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x35b60
movq %rax, 0x20(%rsp)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x48b45
testl %eax, %eax
je 0x4be05
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
leaq 0x20(%rsp), %rbp
testq %r12, %r12
je 0x4bdad
movq %r12, %rdi
movq %r14, %rsi
callq 0x48b45
testl %eax, %eax
je 0x4bdad
incl %r13d
movq %r15, %rdi
movq %rsp, %rsi
movq %rbp, %rdx
callq 0x486f3
movq (%rsp), %r12
jmp 0x4bd0e
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x483f9
testq %rax, %rax
je 0x4bdaa
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x48176
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r13      # imm = 0xFFFFFFFF00000001
addq %rcx, %r13
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x48499
testq %rax, %rax
je 0x4bdad
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x48176
addl %eax, %r13d
subl 0x10(%r14), %r13d
jmp 0x4bdad
xorl %r13d, %r13d
leaq 0x8(%rsp), %rdi
callq 0x4832a
movslq %r13d, %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x370a6
leaq 0x8(%rsp), %rdi
callq 0x4832a
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4bc91
leaq 0x667ac(%rip), %rdi     # 0xb259e
leaq 0x68d59(%rip), %rsi     # 0xb4b52
movl $0xa4c, %edx            # imm = 0xA4C
callq 0x57b45
jmp 0x4be24
leaq 0x69120(%rip), %rdx     # 0xb4f2c
leaq 0x68d3f(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq %r14, %rsi
movl $0xa28, %r8d            # imm = 0xA28
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0