// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: genericZrangebyscoreCommand
void genericZrangebyscoreCommand(redisClient *c, int reverse) {
    zrangespec range;
    robj *key = c->argv[1];
    robj *zobj;
    long offset = 0, limit = -1;
    int withscores = 0;
    unsigned long rangelen = 0;
    void *replylen = NULL;
    int minidx, maxidx;

    /* Parse the range arguments. */
    if (reverse) {
        /* Range is given as [max,min] */
        maxidx = 2; minidx = 3;
    } else {
        /* Range is given as [min,max] */
        minidx = 2; maxidx = 3;
    }

    // 分析并读入范围
    if (zslParseRange(c->argv[minidx],c->argv[maxidx],&range) != REDIS_OK) {
        addReplyError(c,"min or max is not a float");
        return;
    }

    /* Parse optional extra arguments. Note that ZCOUNT will exactly have
     * 4 arguments, so we'll never enter the following code path. */
    // 分析并读入可选参数
    if (c->argc > 4) {
        int remaining = c->argc - 4;
        int pos = 4;

        while (remaining) {
            if (remaining >= 1 && !strcasecmp(c->argv[pos]->ptr,"withscores")) {
                pos++; remaining--;
                withscores = 1;
            } else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
                if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) ||
                    (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return;
                pos += 3; remaining -= 3;
            } else {
                addReply(c,shared.syntaxerr);
                return;
            }
        }
    }

    /* Ok, lookup the key and get the range */
    // 取出有序集合对象
    if ((zobj = lookupKeyReadOrReply(c,key,shared.emptymultibulk)) == NULL ||
        checkType(c,zobj,REDIS_ZSET)) return;

    if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *zl = zobj->ptr;
        unsigned char *eptr, *sptr;
        unsigned char *vstr;
        unsigned int vlen;
        long long vlong;
        double score;

        /* If reversed, get the last node in range as starting point. */
        // 迭代的方向
        if (reverse) {
            eptr = zzlLastInRange(zl,&range);
        } else {
            eptr = zzlFirstInRange(zl,&range);
        }

        /* No "first" element in the specified interval. */
        // 没有元素在指定范围之内
        if (eptr == NULL) {
            addReply(c, shared.emptymultibulk);
            return;
        }

        /* Get score pointer for the first element. */
        redisAssertWithInfo(c,zobj,eptr != NULL);
        sptr = ziplistNext(zl,eptr);

        /* We don't know in advance how many matching elements there are in the
         * list, so we push this object that will represent the multi-bulk
         * length in the output buffer, and will "fix" it later */
        replylen = addDeferredMultiBulkLength(c);

        /* If there is an offset, just traverse the number of elements without
         * checking the score because that is done in the next loop. */
        // 跳过 offset 指定数量的元素
        while (eptr && offset--) {
            if (reverse) {
                zzlPrev(zl,&eptr,&sptr);
            } else {
                zzlNext(zl,&eptr,&sptr);
            }
        }

        // 遍历并返回所有在范围内的元素
        while (eptr && limit--) {

            // 分值
            score = zzlGetScore(sptr);

            /* Abort when the node is no longer in range. */
            // 检查分值是否符合范围
            if (reverse) {
                if (!zslValueGteMin(score,&range)) break;
            } else {
                if (!zslValueLteMax(score,&range)) break;
            }

            /* We know the element exists, so ziplistGet should always succeed */
            redisAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));

            rangelen++;
            if (vstr == NULL) {
                addReplyBulkLongLong(c,vlong);
            } else {
                addReplyBulkCBuffer(c,vstr,vlen);
            }

            if (withscores) {
                addReplyDouble(c,score);
            }

            /* Move to next node */
            if (reverse) {
                zzlPrev(zl,&eptr,&sptr);
            } else {
                zzlNext(zl,&eptr,&sptr);
            }
        }

    } else if (zobj->encoding == REDIS_ENCODING_SKIPLIST) {
        zset *zs = zobj->ptr;
        zskiplist *zsl = zs->zsl;
        zskiplistNode *ln;

        /* If reversed, get the last node in range as starting point. */
        // 方向
        if (reverse) {
            ln = zslLastInRange(zsl,&range);
        } else {
            ln = zslFirstInRange(zsl,&range);
        }

        /* No "first" element in the specified interval. */
        // 没有值在指定范围之内
        if (ln == NULL) {
            addReply(c, shared.emptymultibulk);
            return;
        }

        /* We don't know in advance how many matching elements there are in the
         * list, so we push this object that will represent the multi-bulk
         * length in the output buffer, and will "fix" it later */
        replylen = addDeferredMultiBulkLength(c);

        /* If there is an offset, just traverse the number of elements without
         * checking the score because that is done in the next loop. */
        // 跳过 offset 参数指定的元素数量
        while (ln && offset--) {
            if (reverse) {
                ln = ln->backward;
            } else {
                ln = ln->level[0].forward;
            }
        }

        // 遍历并返回所有在范围内的元素
        while (ln && limit--) {
            /* Abort when the node is no longer in range. */
            if (reverse) {
                if (!zslValueGteMin(ln->score,&range)) break;
            } else {
                if (!zslValueLteMax(ln->score,&range)) break;
            }

            rangelen++;
            addReplyBulk(c,ln->obj);

            if (withscores) {
                addReplyDouble(c,ln->score);
            }

            /* Move to next node */
            if (reverse) {
                ln = ln->backward;
            } else {
                ln = ln->level[0].forward;
            }
        }
    } else {
        redisPanic("Unknown sorted set encoding");
    }

    if (withscores) {
        rangelen *= 2;
    }

    setDeferredMultiBulkLength(c, replylen, rangelen);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $-0x1, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x5360f
movl $0x2, -0x68(%rbp)
movl $0x3, -0x64(%rbp)
jmp 0x5361d
movl $0x2, -0x64(%rbp)
movl $0x3, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x28(%rbp), %rdx
callq 0x51360
cmpl $0x0, %eax
je 0x53660
movq -0x8(%rbp), %rdi
leaq 0x8fe24(%rip), %rsi     # 0xe347a
callq 0x35d40
jmp 0x53cab
movq -0x8(%rbp), %rax
cmpl $0x4, 0x30(%rax)
jle 0x53798
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x4, %eax
movl %eax, -0x6c(%rbp)
movl $0x4, -0x70(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x53796
cmpl $0x1, -0x6c(%rbp)
jl 0x536d5
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0x8ff0c(%rip), %rsi     # 0xe35b9
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x536d5
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x6c(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x53791
cmpl $0x3, -0x6c(%rbp)
jl 0x53773
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0x90359(%rip), %rsi     # 0xe3a53
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x53773
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x70(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
jne 0x5375a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x70(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x48(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x5375f
jmp 0x53cab
movl -0x70(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x6c(%rbp)
jmp 0x5378f
movq -0x8(%rbp), %rdi
leaq 0xc09d2(%rip), %rax     # 0x114150
movq 0x80(%rax), %rsi
callq 0x35a70
jmp 0x53cab
jmp 0x53791
jmp 0x53682
jmp 0x53798
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0xc09a9(%rip), %rax     # 0x114150
movq 0x68(%rax), %rdx
callq 0x3c0c0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x537d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x3, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x537d6
jmp 0x53cab
movq -0x38(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x53a70
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x53810
movq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4f4c0
movq %rax, -0x80(%rbp)
jmp 0x53821
movq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4f3c0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x53841
movq -0x8(%rbp), %rdi
leaq 0xc091d(%rip), %rax     # 0x114150
movq 0x68(%rax), %rsi
callq 0x35a70
jmp 0x53cab
cmpq $0x0, -0x80(%rbp)
je 0x5384a
jmp 0x53875
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x8fabe(%rip), %rdx     # 0xe3317
leaq 0x8fa2e(%rip), %rcx     # 0xe328e
movl $0xc60, %r8d            # imm = 0xC60
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x33330
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
callq 0x36050
movq %rax, -0x60(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x80(%rbp)
movb %al, -0xc1(%rbp)
je 0x538c1
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x40(%rbp)
cmpq $0x0, %rax
setne %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x538cd
jmp 0x538ff
cmpl $0x0, -0xc(%rbp)
je 0x538e9
movq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x4f1d0
jmp 0x538fd
movq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x4f100
jmp 0x53896
jmp 0x53901
xorl %eax, %eax
cmpq $0x0, -0x80(%rbp)
movb %al, -0xc2(%rbp)
je 0x5392c
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x48(%rbp)
cmpq $0x0, %rax
setne %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x5393b
jmp 0x53a6b
movq -0x88(%rbp), %rdi
callq 0x4ee80
movsd %xmm0, -0xa8(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x53972
movsd -0xa8(%rbp), %xmm0
leaq -0x28(%rbp), %rdi
callq 0x4db90
cmpl $0x0, %eax
jne 0x53970
jmp 0x53a6b
jmp 0x5398f
movsd -0xa8(%rbp), %xmm0
leaq -0x28(%rbp), %rdi
callq 0x4dbe0
cmpl $0x0, %eax
jne 0x5398d
jmp 0x53a6b
jmp 0x5398f
movq -0x80(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x94(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x33490
cmpl $0x0, %eax
je 0x539b4
jmp 0x539df
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x8f902(%rip), %rdx     # 0xe32c5
leaq 0x8f8c4(%rip), %rcx     # 0xe328e
movl $0xc82, %r8d            # imm = 0xC82
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x53a07
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x366c0
jmp 0x53a1f
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl -0x94(%rbp), %eax
movl %eax, %edx
callq 0x36670
cmpl $0x0, -0x4c(%rbp)
je 0x53a36
movq -0x8(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
callq 0x36230
cmpl $0x0, -0xc(%rbp)
je 0x53a52
movq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x4f1d0
jmp 0x53a66
movq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x4f100
jmp 0x53901
jmp 0x53c89
movq -0x38(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x53c65
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x53ac5
movq -0xb8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4dd80
movq %rax, -0xc0(%rbp)
jmp 0x53adc
movq -0xb8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4dc40
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x53aff
movq -0x8(%rbp), %rdi
leaq 0xc065f(%rip), %rax     # 0x114150
movq 0x68(%rax), %rsi
callq 0x35a70
jmp 0x53cab
movq -0x8(%rbp), %rdi
callq 0x36050
movq %rax, -0x60(%rbp)
xorl %eax, %eax
cmpq $0x0, -0xc0(%rbp)
movb %al, -0xc3(%rbp)
je 0x53b3a
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x40(%rbp)
cmpq $0x0, %rax
setne %al
movb %al, -0xc3(%rbp)
movb -0xc3(%rbp), %al
testb $0x1, %al
jne 0x53b46
jmp 0x53b74
cmpl $0x0, -0xc(%rbp)
je 0x53b60
movq -0xc0(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x53b72
movq -0xc0(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x53b0c
jmp 0x53b76
xorl %eax, %eax
cmpq $0x0, -0xc0(%rbp)
movb %al, -0xc4(%rbp)
je 0x53ba4
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x48(%rbp)
cmpq $0x0, %rax
setne %al
movb %al, -0xc4(%rbp)
movb -0xc4(%rbp), %al
testb $0x1, %al
jne 0x53bb3
jmp 0x53c63
cmpl $0x0, -0xc(%rbp)
je 0x53bda
movq -0xc0(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x28(%rbp), %rdi
callq 0x4db90
cmpl $0x0, %eax
jne 0x53bd8
jmp 0x53c63
jmp 0x53bf8
movq -0xc0(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x28(%rbp), %rdi
callq 0x4dbe0
cmpl $0x0, %eax
jne 0x53bf6
jmp 0x53c63
jmp 0x53bf8
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq (%rax), %rsi
callq 0x36620
cmpl $0x0, -0x4c(%rbp)
je 0x53c32
movq -0x8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movsd 0x8(%rax), %xmm0
callq 0x36230
cmpl $0x0, -0xc(%rbp)
je 0x53c4c
movq -0xc0(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x53c5e
movq -0xc0(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x53b76
jmp 0x53c87
leaq 0x8d82f(%rip), %rdi     # 0xe149b
leaq 0x8f61b(%rip), %rsi     # 0xe328e
movl $0xcd3, %edx            # imm = 0xCD3
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x53c89
cmpl $0x0, -0x4c(%rbp)
je 0x53c9a
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x360c0
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)