// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x62950
cmpl $0x0, %eax
je 0x6542e
movq -0x8(%rbp), %rdi
leaq 0xd8a72(%rip), %rsi     # 0x13de96
callq 0x42f90
jmp 0x65663
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x113803(%rip), %rax    # 0x178c40
movq 0x20(%rax), %rdx
callq 0x4a730
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x65467
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x3, %edx
callq 0x490a0
cmpl $0x0, %eax
je 0x65475
leaq -0x30(%rbp), %rdi
callq 0x5fa40
jmp 0x65663
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x6555e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x60780
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x654d0
leaq -0x30(%rbp), %rdi
callq 0x5fa40
movq -0x8(%rbp), %rdi
leaq 0x11377e(%rip), %rax    # 0x178c40
movq 0x20(%rax), %rsi
callq 0x42cc0
jmp 0x65663
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x412e0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x60740
cmpl $0x0, %eax
je 0x654f5
jmp 0x65520
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0xd8af8(%rip), %rdx     # 0x13dffc
leaq 0xd8717(%rip), %rcx     # 0x13dc22
movl $0xa28, %r8d            # imm = 0xA28
callq 0x78360
movl $0x1, %edi
callq 0x263c0
jmp 0x65522
cmpq $0x0, -0x48(%rbp)
je 0x65559
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x60740
cmpl $0x0, %eax
jne 0x6553d
jmp 0x65559
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x600e0
jmp 0x65522
jmp 0x6564d
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x65629
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 0x5fbf0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x65627
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x68(%rbp), %rax
movq (%rax), %rsi
callq 0x5f590
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 0x5fd30
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x65625
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x68(%rbp), %rax
movq (%rax), %rsi
callq 0x5f590
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 0x65627
jmp 0x6564b
leaq 0xd60ba(%rip), %rdi     # 0x13b6ea
leaq 0xd85eb(%rip), %rsi     # 0x13dc22
movl $0xa4c, %edx            # imm = 0xA4C
callq 0x76d80
movl $0x1, %edi
callq 0x263c0
jmp 0x6564d
leaq -0x30(%rbp), %rdi
callq 0x5fa40
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x43780
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)