// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zrangeGenericCommand
void zrangeGenericCommand(client *c, int reverse) {
    robj *key = c->argv[1];
    robj *zobj;
    int withscores = 0;
    long start;
    long end;
    int llen;
    int rangelen;

    if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
        (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;

    if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) {
        withscores = 1;
    } else if (c->argc >= 5) {
        addReply(c,shared.syntaxerr);
        return;
    }

    if ((zobj = lookupKeyReadOrReply(c,key,shared.emptymultibulk)) == NULL
         || checkType(c,zobj,OBJ_ZSET)) return;

    /* Sanitize indexes. */
    llen = zsetLength(zobj);
    if (start < 0) start = llen+start;
    if (end < 0) end = llen+end;
    if (start < 0) start = 0;

    /* Invariant: start >= 0, so this test will be true when end < 0.
     * The range is empty when start > end or start >= length. */
    if (start > end || start >= llen) {
        addReply(c,shared.emptymultibulk);
        return;
    }
    if (end >= llen) end = llen-1;
    rangelen = (end-start)+1;

    /* Return the result in form of a multi-bulk reply */
    addReplyMultiBulkLen(c, withscores ? (rangelen*2) : rangelen);

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

        if (reverse)
            eptr = ziplistIndex(zl,-2-(2*start));
        else
            eptr = ziplistIndex(zl,2*start);

        serverAssertWithInfo(c,zobj,eptr != NULL);
        sptr = ziplistNext(zl,eptr);

        while (rangelen--) {
            serverAssertWithInfo(c,zobj,eptr != NULL && sptr != NULL);
            serverAssertWithInfo(c,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
            if (vstr == NULL)
                addReplyBulkLongLong(c,vlong);
            else
                addReplyBulkCBuffer(c,vstr,vlen);

            if (withscores)
                addReplyDouble(c,zzlGetScore(sptr));

            if (reverse)
                zzlPrev(zl,&eptr,&sptr);
            else
                zzlNext(zl,&eptr,&sptr);
        }

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

        /* Check if starting point is trivial, before doing log(N) lookup. */
        if (reverse) {
            ln = zsl->tail;
            if (start > 0)
                ln = zslGetElementByRank(zsl,llen-start);
        } else {
            ln = zsl->header->level[0].forward;
            if (start > 0)
                ln = zslGetElementByRank(zsl,start+1);
        }

        while(rangelen--) {
            serverAssertWithInfo(c,zobj,ln != NULL);
            ele = ln->obj;
            addReplyBulk(c,ele);
            if (withscores)
                addReplyDouble(c,ln->score);
            ln = reverse ? ln->backward : ln->level[0].forward;
        }
    } else {
        serverPanic("Unknown sorted set encoding");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rsi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x57863
movq 0x40(%rbx), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x57863
movl 0x38(%rbx), %r15d
cmpl $0x5, %r15d
jne 0x57667
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x6f38d(%rip), %rsi     # 0xc69eb
callq 0x26300
testl %eax, %eax
je 0x57682
movb $0x1, %al
cmpl $0x5, %r15d
jl 0x57684
leaq 0xafc3a(%rip), %rax     # 0x1072b0
movq 0x80(%rax), %rsi
jmp 0x5785b
xorl %eax, %eax
movl %eax, 0xc(%rsp)
leaq 0xafc21(%rip), %r15     # 0x1072b0
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x44f89
testq %rax, %rax
je 0x57863
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
jne 0x57863
movq %r14, %rdi
callq 0x551a5
movq (%rsp), %rcx
testq %rcx, %rcx
jns 0x576dd
movslq %eax, %rdx
addq %rdx, %rcx
movq %rcx, (%rsp)
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
jns 0x576f2
movslq %eax, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rsp)
cmpq $0x0, (%rsp)
jns 0x57701
movq $0x0, (%rsp)
movq (%rsp), %r13
movq 0x10(%rsp), %rcx
cmpq %rcx, %r13
jg 0x57857
movslq %eax, %r12
cmpq %r12, %r13
jge 0x57857
cmpq %r12, %rcx
jl 0x5772d
decl %eax
cltq
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %r15
movl %r15d, %edx
subl %r13d, %edx
incl %edx
movl 0xc(%rsp), %eax
movl %eax, %ecx
xorb $0x1, %cl
movl %edx, 0x1c(%rsp)
movl %edx, %eax
shll %cl, %eax
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x4063b
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x57872
cmpl $0x5, %eax
jne 0x579f7
movq 0x8(%r14), %r12
movl (%rsp), %eax
addl %eax, %eax
movl %eax, %esi
xorl $-0x2, %esi
testl %ebp, %ebp
cmovel %eax, %esi
movq %r12, %rdi
callq 0x3ea40
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x57a11
movq %r12, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x57863
notl %r15d
addl %r13d, %r15d
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x579ce
movq 0x20(%rsp), %r13
testq %r13, %r13
je 0x579ce
leaq 0x40(%rsp), %rsi
leaq 0x34(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x3eb60
testl %eax, %eax
je 0x579b2
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
je 0x5780b
movl 0x34(%rsp), %edx
movq %rbx, %rdi
callq 0x4070f
jmp 0x57818
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x407de
cmpb $0x0, 0xc(%rsp)
jne 0x5782f
movq %r13, %rdi
callq 0x54417
movq %rbx, %rdi
callq 0x40403
testl %ebp, %ebp
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
je 0x57847
callq 0x5465e
jmp 0x5784c
callq 0x545d7
incl %r15d
jne 0x577bb
jmp 0x57863
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x3fc19
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
movq %r13, %r9
testl %ebp, %ebp
je 0x578dd
movq (%rsp), %rax
testq %rax, %rax
jle 0x57937
subq %rax, %r12
movq (%rcx), %r13
movslq 0x18(%rcx), %rax
xorl %ecx, %ecx
testq %rax, %rax
jle 0x57932
decq %rax
movq %rax, %rdx
shlq $0x4, %rdx
movq %r13, %rsi
movq %rcx, %rdi
movq %rdi, %rcx
movq %rsi, %r13
movq 0x18(%rsi,%rdx), %rsi
testq %rsi, %rsi
je 0x578d6
leaq (%rdx,%r13), %rdi
addq $0x18, %rdi
movl 0x8(%rdi), %edi
addq %rcx, %rdi
cmpq %r12, %rdi
jbe 0x578b3
cmpq %r12, %rcx
jne 0x5789a
jmp 0x57941
movq (%rcx), %r13
movq (%rsp), %rax
testq %rax, %rax
jle 0x5793d
incq %rax
movslq 0x18(%rcx), %rcx
xorl %edx, %edx
testq %rcx, %rcx
jle 0x57932
decq %rcx
movq %rcx, %rsi
shlq $0x4, %rsi
movq %r13, %rdi
movq %rdx, %r8
movq %r8, %rdx
movq %rdi, %r13
movq 0x18(%rdi,%rsi), %rdi
testq %rdi, %rdi
je 0x5792b
leaq (%rsi,%r13), %r8
addq $0x18, %r8
movl 0x8(%r8), %r8d
addq %rdx, %r8
cmpq %rax, %r8
jbe 0x57907
cmpq %rax, %rdx
jne 0x578f2
jmp 0x57941
xorl %r13d, %r13d
jmp 0x57941
movq 0x8(%rcx), %r13
jmp 0x57941
movq 0x18(%r13), %r13
cmpl $0x0, 0x1c(%rsp)
je 0x57863
xorl %eax, %eax
testl %ebp, %ebp
sete %al
leaq 0x10(,%rax,8), %r12
notl %r15d
addl %r9d, %r15d
testq %r13, %r13
je 0x57996
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x40537
cmpb $0x0, 0xc(%rsp)
jne 0x57987
movsd 0x8(%r13), %xmm0
movq %rbx, %rdi
callq 0x40403
movq (%r13,%r12), %r13
incl %r15d
jne 0x57961
jmp 0x57863
leaq 0x6b61f(%rip), %rdx     # 0xc2fbc
leaq 0x6ecb2(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8e0, %r8d            # imm = 0x8E0
jmp 0x579e8
leaq 0x6ecd4(%rip), %rdx     # 0xc668d
leaq 0x6ec96(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8bf, %r8d            # imm = 0x8BF
jmp 0x579e8
leaq 0x6f021(%rip), %rdx     # 0xc69f6
leaq 0x6ec7a(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8be, %r8d            # imm = 0x8BE
callq 0x66380
movl $0x1, %edi
callq 0x263d0
leaq 0x6c278(%rip), %rdi     # 0xc3c76
leaq 0x6ec51(%rip), %rsi     # 0xc6656
movl $0x8e8, %edx            # imm = 0x8E8
callq 0x6558d
jmp 0x579ed
leaq 0x6ecc7(%rip), %rdx     # 0xc66df
leaq 0x6ec37(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0x8ba, %r8d            # imm = 0x8BA
jmp 0x579e8