// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zcountCommand
void zcountCommand(client *c) {
    robj *key = c->argv[1];
    robj *zobj;
    zrangespec range;
    int count = 0;

    /* Parse the range arguments */
    if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
        addReplyError(c,"min or max is not a float");
        return;
    }

    /* Lookup the sorted set */
    if ((zobj = lookupKeyReadOrReply(c, key, shared.czero)) == NULL ||
        checkType(c, zobj, OBJ_ZSET)) return;

    if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
        unsigned char *zl = zobj->ptr;
        unsigned char *eptr, *sptr;
        double score;

        /* Use the first element in range as the starting point */
        eptr = zzlFirstInRange(zl,&range);

        /* No "first" element */
        if (eptr == NULL) {
            addReply(c, shared.czero);
            return;
        }

        /* First element is in range */
        sptr = ziplistNext(zl,eptr);
        score = zzlGetScore(sptr);
        serverAssertWithInfo(c,zobj,zslValueLteMax(score,&range));

        /* Iterate over elements in range */
        while (eptr) {
            score = zzlGetScore(sptr);

            /* Abort when the node is no longer in range. */
            if (!zslValueLteMax(score,&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 = zslFirstInRange(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 = zslLastInRange(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");
    }

    addReplyLongLong(c, count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
callq 0x56346
testl %eax, %eax
je 0x58017
leaq 0x6e8af(%rip), %rsi     # 0xc68b0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ffcb
leaq 0xaf292(%rip), %r13     # 0x1072b0
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x44f89
testq %rax, %rax
je 0x58049
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
je 0x58058
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x5813d
cmpl $0x5, %eax
jne 0x581dd
movq 0x8(%r12), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x547a3
movq %rax, (%rsp)
testq %rax, %rax
movq %rax, 0x28(%rsp)
je 0x581aa
movq %r15, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x54417
movsd 0x18(%rsp), %xmm1
xorl %eax, %eax
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
movl 0x24(%rsp), %r14d
setbe %al
setb %cl
testl %r14d, %r14d
cmovel %ecx, %eax
testb %al, %al
jne 0x581f7
cmpq $0x0, (%rsp)
je 0x581b6
xorl %ebp, %ebp
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rsp, %r12
leaq 0x8(%rsp), %r13
movq 0x8(%rsp), %rdi
callq 0x54417
xorl %eax, %eax
xorl %ecx, %ecx
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
setb %cl
testl %r14d, %r14d
cmovel %ecx, %eax
testb %al, %al
jne 0x581b8
incl %ebp
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x545d7
cmpq $0x0, (%rsp)
jne 0x580f8
jmp 0x581b8
movq 0x8(%r12), %rax
movq 0x8(%rax), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x53a8a
testq %rax, %rax
je 0x581a6
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x53f2f
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %rbp      # imm = 0xFFFFFFFF00000001
addq %rcx, %rbp
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x53b4f
testq %rax, %rax
je 0x581c4
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x53f2f
addl %eax, %ebp
subl 0x10(%r14), %ebp
jmp 0x581c4
xorl %ebp, %ebp
jmp 0x581c4
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x3fc19
xorl %ebp, %ebp
cmpq $0x0, 0x28(%rsp)
je 0x58049
movslq %ebp, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40606
leaq 0x6ba92(%rip), %rdi     # 0xc3c76
leaq 0x6e46b(%rip), %rsi     # 0xc6656
movl $0x9fe, %edx            # imm = 0x9FE
callq 0x6558d
jmp 0x58216
leaq 0x6e815(%rip), %rdx     # 0xc6a13
leaq 0x6e451(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r12, %rsi
movl $0x9d8, %r8d            # imm = 0x9D8
callq 0x66380
movl $0x1, %edi
callq 0x263d0