// File: /workspace/github_c_makefile_star2_O3/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
movq %rsp, %rdx
callq 0x52c43
testl %eax, %eax
je 0x5499f
leaq 0x6efc1(%rip), %rsi     # 0xc394a
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
leaq 0xad96a(%rip), %r13     # 0x102310
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41af9
testq %rax, %rax
je 0x549d1
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
je 0x549f2
movq (%rsp), %rdi
callq 0x40c8f
movq 0x8(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c8f
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x54a8d
cmpl $0x5, %eax
jne 0x54b4e
movq 0x8(%r14), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x513f4
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x54b21
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x20(%rsp)
movq %rsp, %rsi
movq %r12, %rdi
callq 0x513b6
testl %eax, %eax
je 0x54b68
xorl %r13d, %r13d
movq %rsp, %r14
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
movq %r14, %rsi
callq 0x513b6
testl %eax, %eax
je 0x54af5
incl %r13d
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x50f41
movq 0x18(%rsp), %r12
testq %r12, %r12
jne 0x54a5b
jmp 0x54af5
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
movq %rsp, %rsi
movq %r14, %rdi
callq 0x50b55
testq %rax, %rax
je 0x54af2
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x507f6
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %r13      # imm = 0xFFFFFFFF00000001
addq %rcx, %r13
movq %rsp, %rsi
movq %r14, %rdi
callq 0x50c5e
testq %rax, %rax
je 0x54af5
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x507f6
addl %eax, %r13d
subl 0x10(%r14), %r13d
jmp 0x54af5
xorl %r13d, %r13d
movq (%rsp), %rdi
callq 0x40c8f
movq 0x8(%rsp), %rdi
callq 0x40c8f
movslq %r13d, %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d23f
movq (%rsp), %rdi
callq 0x40c8f
movq 0x8(%rsp), %rdi
callq 0x40c8f
movq 0x20(%r13), %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3c854
leaq 0x6c171(%rip), %rdi     # 0xc0cc6
leaq 0x6eb7a(%rip), %rsi     # 0xc36d6
movl $0xa4c, %edx            # imm = 0xA4C
callq 0x619b4
jmp 0x54b87
leaq 0x6ef41(%rip), %rdx     # 0xc3ab0
leaq 0x6eb60(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r14, %rsi
movl $0xa28, %r8d            # imm = 0xA28
callq 0x627c3
movl $0x1, %edi
callq 0x263c0