// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4b1db
movq 0x40(%rbx), %rax
movq 0x18(%rax), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4b1db
movl 0x38(%rbx), %r12d
cmpl $0x5, %r12d
jne 0x4b1a9
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x69d5f(%rip), %rsi     # 0xb4ee7
callq 0x262f0
testl %eax, %eax
je 0x4b1ab
leaq 0xaf178(%rip), %rax     # 0xfa310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4b1db
jge 0x4b191
leaq 0xaf15e(%rip), %r15     # 0xfa310
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3aee5
testq %rax, %rax
je 0x4b1db
movq %rax, %r14
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x4b1ea
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x490f5
movq 0x10(%rsp), %r13
movslq %eax, %rcx
testq %r13, %r13
jns 0x4b20c
addq %rcx, %r13
movq %r13, 0x10(%rsp)
movq 0x28(%rsp), %r14
testq %r14, %r14
jns 0x4b21e
addq %rcx, %r14
movq %r14, 0x28(%rsp)
testq %r13, %r13
jns 0x4b22c
andq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
cmpq %r14, %r13
jg 0x4b374
cmpq %rcx, %r13
jge 0x4b374
movq %rcx, %r15
cmpq %rcx, %r14
jb 0x4b250
decl %eax
movslq %eax, %r14
movq %r14, 0x28(%rsp)
cmpl $0x5, %r12d
sete %cl
movl %r14d, %eax
subl %r13d, %eax
incl %eax
shll %cl, %eax
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x370d9
movq 0x8(%rsp), %rcx
movl (%rcx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4b37d
cmpl $0x5, %eax
jne 0x4b46d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r15
movl 0x10(%rsp), %eax
addl %eax, %eax
movl %eax, %esi
xorl $-0x2, %esi
testl %ebp, %ebp
cmovel %eax, %esi
movq %r15, %rdi
callq 0x35aca
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x4b487
movq %r15, %rdi
movq %rax, %rsi
callq 0x35b60
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
notl %r14d
addl %r13d, %r14d
testl %r14d, %r14d
je 0x4b1db
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4b444
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x4b444
leaq 0x40(%rsp), %rsi
leaq 0x34(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x35be8
testl %eax, %eax
je 0x4b426
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
je 0x4b32c
movl 0x34(%rsp), %edx
movq %rbx, %rdi
callq 0x3716c
jmp 0x4b339
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x37206
cmpl $0x5, %r12d
jne 0x4b34f
movq %r13, %rdi
callq 0x48535
movq %rbx, %rdi
callq 0x36eb0
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
testl %ebp, %ebp
je 0x4b367
callq 0x48778
jmp 0x4b36c
callq 0x486f3
incl %r14d
jmp 0x4b2d3
movq 0x68(%r15), %rsi
jmp 0x4b19f
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rdi
testl %ebp, %ebp
je 0x4b39d
movq 0x10(%rsp), %rax
testq %rax, %rax
jle 0x4b3b7
movq %r15, %rsi
subq %rax, %rsi
pushq $0x10
jmp 0x4b3ac
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
jle 0x4b3bf
incq %rsi
pushq $0x18
popq %rbp
callq 0x4821b
movq %rax, %r15
jmp 0x4b3c9
movq 0x8(%rdi), %r15
pushq $0x10
jmp 0x4b3c8
movq (%rdi), %rax
movq 0x18(%rax), %r15
pushq $0x18
popq %rbp
notl %r14d
addl %r13d, %r14d
movq 0x8(%rsp), %r13
testl %r14d, %r14d
je 0x4b1db
testq %r15, %r15
je 0x4b40a
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x36fd9
cmpl $0x5, %r12d
jne 0x4b401
movsd 0x8(%r15), %xmm0
movq %rbx, %rdi
callq 0x36eb0
movq (%r15,%rbp), %r15
incl %r14d
jmp 0x4b3d4
leaq 0x66597(%rip), %rdx     # 0xb19a8
leaq 0x6973a(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq %r13, %rsi
movl $0x8e0, %r8d            # imm = 0x8E0
jmp 0x4b460
leaq 0x6975c(%rip), %rdx     # 0xb4b89
leaq 0x6971e(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl $0x8bf, %r8d            # imm = 0x8BF
jmp 0x4b460
leaq 0x69aa7(%rip), %rdx     # 0xb4ef2
leaq 0x69700(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl $0x8be, %r8d            # imm = 0x8BE
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0
leaq 0x6712a(%rip), %rdi     # 0xb259e
leaq 0x696d7(%rip), %rsi     # 0xb4b52
movl $0x8e8, %edx            # imm = 0x8E8
callq 0x57b45
jmp 0x4b465
leaq 0x6974d(%rip), %rdx     # 0xb4bdb
leaq 0x696bd(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl $0x8ba, %r8d            # imm = 0x8BA
jmp 0x4b460