// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0x20(%rsp), %rdx
callq 0x4a088
testl %eax, %eax
je 0x4ba20
leaq 0x693a2(%rip), %rsi     # 0xb4dac
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36b6f
leaq 0xae8e9(%rip), %r13     # 0xfa310
movq 0x20(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3aee5
testq %rax, %rax
je 0x4ba50
movq %rax, %r15
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x4ba5f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r15), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4bb36
cmpl $0x5, %eax
jne 0x4bbca
movq 0x8(%r15), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x488b1
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x4bbb9
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0x35b60
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x48535
movsd 0x28(%rsp), %xmm1
xorl %eax, %eax
xorl %ecx, %ecx
movsd %xmm1, 0x18(%rsp)
ucomisd %xmm0, %xmm1
movl 0x34(%rsp), %r13d
setbe %al
setb %cl
testl %r13d, %r13d
cmovel %ecx, %eax
testb %al, %al
jne 0x4bbe4
xorl %ebp, %ebp
leaq 0x8(%rsp), %r15
testq %r12, %r12
je 0x4bba0
movq 0x8(%rsp), %rdi
callq 0x48535
xorl %eax, %eax
xorl %ecx, %ecx
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
setb %cl
testl %r13d, %r13d
cmovel %ecx, %eax
testb %al, %al
jne 0x4bba0
incl %ebp
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x486f3
movq 0x10(%rsp), %r12
jmp 0x4bae8
movq 0x8(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x47d7b
testq %rax, %rax
je 0x4bb9e
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x48176
movq 0x10(%r14), %rcx
subq %rax, %rcx
movabsq $-0xffffffff, %rbp      # imm = 0xFFFFFFFF00000001
addq %rcx, %rbp
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x47e31
testq %rax, %rax
je 0x4bba0
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x48176
addl %eax, %ebp
subl 0x10(%r14), %ebp
jmp 0x4bba0
xorl %ebp, %ebp
movslq %ebp, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x370a6
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4ba50
leaq 0x669cd(%rip), %rdi     # 0xb259e
leaq 0x68f7a(%rip), %rsi     # 0xb4b52
movl $0x9fe, %edx            # imm = 0x9FE
callq 0x57b45
jmp 0x4bc03
leaq 0x69324(%rip), %rdx     # 0xb4f0f
leaq 0x68f60(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq %r15, %rsi
movl $0x9d8, %r8d            # imm = 0x9D8
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0