// File: /workspace/github_c_makefile_star2_O3/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 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x53e79
movq 0x40(%rbx), %rax
movq 0x18(%rax), %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x53e79
movl 0x38(%rbx), %r12d
cmpl $0x5, %r12d
jne 0x53e40
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x6fc4c(%rip), %rsi     # 0xc3a6b
callq 0x262f0
testl %eax, %eax
je 0x53e42
leaq 0xae4e1(%rip), %rax     # 0x102310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x53e79
jge 0x53e28
leaq 0xae4c7(%rip), %r13     # 0x102310
movq 0x68(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41af9
testq %rax, %rax
je 0x53e79
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
movq %rax, (%rsp)
callq 0x40d47
movq (%rsp), %rdi
testl %eax, %eax
je 0x53e88
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x51a88
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
jns 0x53ea2
movslq %eax, %rcx
addq %rcx, %rdx
movq %rdx, 0x8(%rsp)
movq 0x20(%rsp), %r15
testq %r15, %r15
jns 0x53eb7
movslq %eax, %rcx
addq %rcx, %r15
movq %r15, 0x20(%rsp)
testq %rdx, %rdx
jns 0x53ec7
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
cmpq %r15, %rdx
jg 0x54017
movslq %eax, %r14
cmpq %r14, %rdx
jge 0x54017
cmpq %r14, %r15
jb 0x53eeb
decl %eax
movslq %eax, %r15
movq %r15, 0x20(%rsp)
cmpl $0x5, %r12d
sete %cl
movl %r15d, %r13d
movq %rdx, 0x30(%rsp)
subl %edx, %r13d
incl %r13d
movl %r13d, %eax
shll %cl, %eax
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x3d274
movq (%rsp), %rcx
movl (%rcx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x54020
cmpl $0x5, %eax
jne 0x541a9
movq 0x8(%rcx), %r14
movl 0x8(%rsp), %eax
addl %eax, %eax
movl %eax, %esi
xorl $-0x2, %esi
testl %ebp, %ebp
cmovel %eax, %esi
movq %r14, %rdi
callq 0x3b680
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x541c3
movq %r14, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x10(%rsp)
testl %r13d, %r13d
je 0x53e79
notl %r15d
addl 0x30(%rsp), %r15d
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x5417f
movq 0x10(%rsp), %r13
testq %r13, %r13
je 0x5417f
leaq 0x40(%rsp), %rsi
leaq 0x2c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x3b7cf
testl %eax, %eax
je 0x54162
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
je 0x53fc9
movl 0x2c(%rsp), %edx
movq %rbx, %rdi
callq 0x3d346
jmp 0x53fd6
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x3d415
cmpl $0x5, %r12d
jne 0x53fec
movq %r13, %rdi
callq 0x50d7b
movq %rbx, %rdi
callq 0x3d03c
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
testl %ebp, %ebp
je 0x54004
callq 0x50fc8
jmp 0x54009
callq 0x50f41
incl %r15d
jne 0x53f79
jmp 0x53e79
movq 0x68(%r13), %rsi
jmp 0x53e36
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rcx
movl %r13d, %r9d
testl %ebp, %ebp
je 0x5408c
movq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x540e7
subq %rax, %r14
movq (%rcx), %r13
movslq 0x18(%rcx), %rax
xorl %ecx, %ecx
testq %rax, %rax
jle 0x540e2
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 0x54085
leaq (%rdx,%r13), %rdi
addq $0x18, %rdi
movl 0x8(%rdi), %edi
addq %rcx, %rdi
cmpq %r14, %rdi
jbe 0x54062
cmpq %r14, %rcx
jne 0x54049
jmp 0x540f1
movq (%rcx), %r13
movq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x540ed
incq %rax
movslq 0x18(%rcx), %rcx
xorl %edx, %edx
testq %rcx, %rcx
jle 0x540e2
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 0x540db
leaq (%rsi,%r13), %r8
addq $0x18, %r8
movl 0x8(%r8), %r8d
addq %rdx, %r8
cmpq %rax, %r8
jbe 0x540b7
cmpq %rax, %rdx
jne 0x540a2
jmp 0x540f1
xorl %r13d, %r13d
jmp 0x540f1
movq 0x8(%rcx), %r13
jmp 0x540f1
movq 0x18(%r13), %r13
testl %r9d, %r9d
je 0x53e79
xorl %eax, %eax
testl %ebp, %ebp
sete %al
leaq 0x10(,%rax,8), %r14
notl %r15d
addl 0x30(%rsp), %r15d
testq %r13, %r13
je 0x54145
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x3d170
cmpl $0x5, %r12d
jne 0x54136
movsd 0x8(%r13), %xmm0
movq %rbx, %rdi
callq 0x3d03c
movq (%r13,%r14), %r13
incl %r15d
jne 0x54111
jmp 0x53e79
leaq 0x6beb8(%rip), %rdx     # 0xc0004
leaq 0x6f583(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq (%rsp), %rsi
movl $0x8e0, %r8d            # imm = 0x8E0
jmp 0x5419a
leaq 0x6f5a4(%rip), %rdx     # 0xc370d
leaq 0x6f566(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq (%rsp), %rsi
movl $0x8bf, %r8d            # imm = 0x8BF
jmp 0x5419a
leaq 0x6f8f0(%rip), %rdx     # 0xc3a76
leaq 0x6f549(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq (%rsp), %rsi
movl $0x8be, %r8d            # imm = 0x8BE
callq 0x627c3
movl $0x1, %edi
callq 0x263c0
leaq 0x6cb16(%rip), %rdi     # 0xc0cc6
leaq 0x6f51f(%rip), %rsi     # 0xc36d6
movl $0x8e8, %edx            # imm = 0x8E8
callq 0x619b4
jmp 0x5419f
leaq 0x6f595(%rip), %rdx     # 0xc375f
leaq 0x6f505(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq (%rsp), %rsi
movl $0x8ba, %r8d            # imm = 0x8BA
jmp 0x5419a