// File: /workspace/github_c_makefile_star2_O3/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 0x52b1b
testl %eax, %eax
je 0x54769
leaq 0x6f1dd(%rip), %rsi     # 0xc3930
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
leaq 0xadba0(%rip), %r12     # 0x102310
movq 0x20(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41af9
testq %rax, %rax
je 0x5479c
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
je 0x547ab
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 0x5487b
cmpl $0x5, %eax
jne 0x54912
movq 0x8(%r15), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x5110d
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x54900
movq %r14, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x50d7b
movsd 0x28(%rsp), %xmm1
xorl %eax, %eax
xorl %ecx, %ecx
movsd %xmm1, 0x18(%rsp)
ucomisd %xmm0, %xmm1
movl 0x34(%rsp), %ebp
setbe %al
setb %cl
testl %ebp, %ebp
cmovel %ecx, %eax
testb %al, %al
jne 0x5492c
xorl %r13d, %r13d
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
movq 0x8(%rsp), %rdi
callq 0x50d7b
xorl %eax, %eax
xorl %ecx, %ecx
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
setb %cl
testl %ebp, %ebp
cmovel %ecx, %eax
testb %al, %al
jne 0x548e7
incl %r13d
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x50f41
cmpq $0x0, 0x10(%rsp)
jne 0x54835
jmp 0x548e7
movq 0x8(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x50364
testq %rax, %rax
je 0x548e4
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
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x50428
testq %rax, %rax
je 0x548e7
movsd 0x8(%rax), %xmm0
movq (%rax), %rsi
movq %r14, %rdi
callq 0x507f6
addl %eax, %r13d
subl 0x10(%r14), %r13d
jmp 0x548e7
xorl %r13d, %r13d
movslq %r13d, %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d23f
movq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x5479c
leaq 0x6c3ad(%rip), %rdi     # 0xc0cc6
leaq 0x6edb6(%rip), %rsi     # 0xc36d6
movl $0x9fe, %edx            # imm = 0x9FE
callq 0x619b4
jmp 0x5494b
leaq 0x6f160(%rip), %rdx     # 0xc3a93
leaq 0x6ed9c(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r15, %rsi
movl $0x9d8, %r8d            # imm = 0x9D8
callq 0x627c3
movl $0x1, %edi
callq 0x263c0