// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/t_zset.c
// Function: genericZrangebylexCommand
void genericZrangebylexCommand(client *c, int reverse) {
    zlexrangespec range;
    robj *key = c->argv[1];
    robj *zobj;
    long offset = 0, limit = -1;
    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 (zslParseLexRange(c->argv[minidx],c->argv[maxidx],&range) != C_OK) {
        addReplyError(c,"min or max not valid string range item");
        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 >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
                if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
                    (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return;
                pos += 3; remaining -= 3;
            } else {
                zslFreeLexRange(&range);
                addReply(c,shared.syntaxerr);
                return;
            }
        }
    }

    /* Ok, lookup the key and get the range */
    if ((zobj = lookupKeyReadOrReply(c,key,shared.emptymultibulk)) == NULL ||
        checkType(c,zobj,OBJ_ZSET))
    {
        zslFreeLexRange(&range);
        return;
    }

    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 reversed, get the last node in range as starting point. */
        if (reverse) {
            eptr = zzlLastInLexRange(zl,&range);
        } else {
            eptr = zzlFirstInLexRange(zl,&range);
        }

        /* No "first" element in the specified interval. */
        if (eptr == NULL) {
            addReply(c, shared.emptymultibulk);
            zslFreeLexRange(&range);
            return;
        }

        /* Get score pointer for the first element. */
        serverAssertWithInfo(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. */
        while (eptr && offset--) {
            if (reverse) {
                zzlPrev(zl,&eptr,&sptr);
            } else {
                zzlNext(zl,&eptr,&sptr);
            }
        }

        while (eptr && limit--) {
            /* Abort when the node is no longer in range. */
            if (reverse) {
                if (!zzlLexValueGteMin(eptr,&range)) break;
            } else {
                if (!zzlLexValueLteMax(eptr,&range)) break;
            }

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

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

            /* Move to next node */
            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;

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

        /* No "first" element in the specified interval. */
        if (ln == NULL) {
            addReply(c, shared.emptymultibulk);
            zslFreeLexRange(&range);
            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. */
        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 (!zslLexValueGteMin(ln->obj,&range)) break;
            } else {
                if (!zslLexValueLteMax(ln->obj,&range)) break;
            }

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

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

    zslFreeLexRange(&range);
    setDeferredMultiBulkLength(c, replylen, rangelen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
andq $0x0, 0x20(%rsp)
orq $-0x1, 0x40(%rsp)
movl %esi, %ebp
xorl %ecx, %ecx
testl %esi, %esi
sete %cl
movq 0x10(%rax,%rcx,8), %rsi
xorl $0x3, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x28(%rsp), %rdx
callq 0x4a19e
testl %eax, %eax
je 0x4be91
leaq 0x68f4b(%rip), %rsi     # 0xb4dc6
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36b6f
movl %ebp, 0xc(%rsp)
movl 0x38(%rbx), %ebp
cmpl $0x5, %ebp
jl 0x4bf19
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x69559(%rip), %r15     # 0xb5403
testl %ebp, %ebp
je 0x4bf19
cmpl $0x3, %ebp
jl 0x4bf59
movq 0x40(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x262f0
testl %eax, %eax
jne 0x4bf59
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4c1ad
movq 0x40(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4c1ad
addl $-0x3, %ebp
addq $0x18, %r13
jmp 0x4beaa
leaq 0xae3f0(%rip), %r12     # 0xfa310
movq 0x68(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3aee5
testq %rax, %rax
je 0x4bf4a
movq %rax, %r15
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x4bf7e
leaq 0x28(%rsp), %rdi
callq 0x4832a
jmp 0x4c1ad
leaq 0x28(%rsp), %rdi
callq 0x4832a
leaq 0xae3a6(%rip), %rax     # 0xfa310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4c1ad
movl (%r15), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4bfb7
cmpl $0x5, %eax
movl 0xc(%rsp), %ebp
jne 0x4c1e3
movq 0x8(%r15), %r13
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
testl %ebp, %ebp
je 0x4c07d
callq 0x48c14
jmp 0x4c082
movq 0x8(%r15), %rax
movq 0x8(%rax), %rdi
movl 0xc(%rsp), %ebp
leaq 0x28(%rsp), %rsi
testl %ebp, %ebp
je 0x4bfd3
callq 0x48499
jmp 0x4bfd8
callq 0x483f9
movq %rax, %r15
testq %rax, %rax
je 0x4c0e3
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq %rbx, %rdi
callq 0x36dad
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rax
leaq 0x10(,%r14,8), %rcx
decq %rax
testq %r15, %r15
je 0x4c020
movq %rax, 0x20(%rsp)
cmpq $-0x1, %rax
je 0x4c020
movq (%r15,%rcx), %r15
jmp 0x4c007
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
pushq $0x10
popq %r13
testq %r15, %r15
je 0x4c193
subq $0x1, 0x40(%rsp)
jb 0x4c193
movq (%r15), %rdi
movq %r14, %rsi
testl %ebp, %ebp
je 0x4c055
callq 0x48073
movq %r13, %rbp
jmp 0x4c05d
callq 0x48091
pushq $0x18
popq %rbp
testl %eax, %eax
je 0x4c193
incq %r12
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x36fd9
movq (%r15,%rbp), %r15
movl 0xc(%rsp), %ebp
jmp 0x4c02c
callq 0x48b73
movq %rax, %r14
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x4c0e3
movq %r13, %rdi
movq %r14, %rsi
callq 0x35b60
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x36dad
movq %rax, 0x50(%rsp)
leaq 0x10(%rsp), %r12
testq %r14, %r14
je 0x4c0f5
subq $0x1, 0x20(%rsp)
jb 0x4c0f5
movq %r13, %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
testl %ebp, %ebp
je 0x4c0d7
callq 0x48778
jmp 0x4c0dc
callq 0x486f3
movq 0x10(%rsp), %r14
jmp 0x4c0b4
movq 0x68(%r12), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4bf4a
xorl %r12d, %r12d
testq %r14, %r14
je 0x4c193
subq $0x1, 0x40(%rsp)
jb 0x4c193
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
testl %ebp, %ebp
je 0x4c120
callq 0x48b17
jmp 0x4c125
callq 0x48b45
testl %eax, %eax
je 0x4c193
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x35be8
testl %eax, %eax
je 0x4c1bc
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x4c15c
movl 0x4c(%rsp), %edx
movq %rbx, %rdi
callq 0x3716c
jmp 0x4c169
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x37206
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %rdx
testl %ebp, %ebp
je 0x4c181
callq 0x48778
jmp 0x4c186
callq 0x486f3
movq 0x10(%rsp), %r14
incq %r12
jmp 0x4c0f8
leaq 0x28(%rsp), %rdi
callq 0x4832a
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x36de9
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x689c6(%rip), %rdx     # 0xb4b89
leaq 0x68988(%rip), %rcx     # 0xb4b52
movq %rbx, %rdi
movq %r15, %rsi
movl $0xab8, %r8d            # imm = 0xAB8
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0
leaq 0x663b4(%rip), %rdi     # 0xb259e
leaq 0x68961(%rip), %rsi     # 0xb4b52
movl $0xafd, %edx            # imm = 0xAFD
callq 0x57b45
jmp 0x4c1db