// File: /workspace/github_c_makefile_star2_O3/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
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
movq $0x0, 0x30(%rsp)
movq $-0x1, 0x40(%rsp)
xorl %ecx, %ecx
testl %esi, %esi
sete %cl
movq 0x10(%rax,%rcx,8), %rsi
xorl $0x3, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x8(%rsp), %rdx
callq 0x52c43
testl %eax, %eax
je 0x54bfc
leaq 0x6ed64(%rip), %rsi     # 0xc394a
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
movl %ebp, 0x4(%rsp)
movl 0x38(%rbx), %ebp
cmpl $0x5, %ebp
jge 0x54c57
leaq 0xad701(%rip), %r15     # 0x102310
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41af9
testq %rax, %rax
je 0x54c3e
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
je 0x54cfb
movq 0x8(%rsp), %rdi
callq 0x40c8f
movq 0x10(%rsp), %rdi
callq 0x40c8f
jmp 0x54edb
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x6f3eb(%rip), %r15     # 0xc404f
cmpl $0x3, %ebp
jl 0x54ccc
movq 0x40(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x262f0
testl %eax, %eax
jne 0x54ccc
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x54edb
movq 0x40(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x54edb
addq $0x18, %r13
addl $-0x3, %ebp
jne 0x54c64
jmp 0x54c08
movq 0x8(%rsp), %rdi
callq 0x40c8f
movq 0x10(%rsp), %rdi
callq 0x40c8f
leaq 0xad629(%rip), %rax     # 0x102310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x54edb
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x54d2f
cmpl $0x5, %eax
movl 0x4(%rsp), %ebp
jne 0x54fcf
movq 0x8(%r12), %r13
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
testl %ebp, %ebp
je 0x54da3
callq 0x514a2
jmp 0x54da8
movq 0x8(%r12), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %rsi
testl %ebp, %ebp
je 0x54d4c
callq 0x50c5e
jmp 0x54d51
callq 0x50b55
movq %rax, %r12
testq %rax, %rax
je 0x54eea
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq %rbx, %rdi
callq 0x3cee9
movq %rax, %rbp
movq 0x30(%rsp), %rax
leaq 0x10(,%r14,8), %rcx
subq $0x1, %rax
jb 0x54efb
movq (%r12,%rcx), %r12
testq %r12, %r12
jne 0x54d7e
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %r13
xorl %r15d, %r15d
jmp 0x54ebb
callq 0x513f4
movq %rax, %r14
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x54eea
movq %r13, %rdi
movq %r14, %rsi
callq 0x3b745
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
callq 0x3cee9
movq %rax, 0x20(%rsp)
subq $0x1, 0x30(%rsp)
jb 0x54e14
xorl %r15d, %r15d
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x54df9
callq 0x50fc8
jmp 0x54dfe
callq 0x50f41
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x54eb1
subq $0x1, 0x30(%rsp)
jae 0x54de1
xorl %r15d, %r15d
subq $0x1, 0x40(%rsp)
jb 0x54eb1
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
testl %ebp, %ebp
je 0x54e36
callq 0x5137c
jmp 0x54e3b
callq 0x513b6
testl %eax, %eax
je 0x54eb1
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x3b7cf
testl %eax, %eax
je 0x54fa6
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x54e76
movl 0x4c(%rsp), %edx
movq %rbx, %rdi
callq 0x3d346
jmp 0x54e83
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x3d415
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x54e9b
callq 0x50fc8
jmp 0x54ea0
callq 0x50f41
movq 0x28(%rsp), %r14
incq %r15
testq %r14, %r14
jne 0x54e17
movq 0x8(%rsp), %r13
movq 0x20(%rsp), %rbp
movq %r13, %rdi
callq 0x40c8f
movq 0x10(%rsp), %rdi
callq 0x40c8f
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x3cf25
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x54c3e
movq %rbp, 0x20(%rsp)
movq $-0x1, 0x30(%rsp)
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
cmpl $0x1, 0x18(%rsp)
movl $0x0, %ebp
sbbl %ebp, %ebp
movl 0x1c(%rsp), %eax
movl %eax, 0x48(%rsp)
subq $0x1, 0x40(%rsp)
jb 0x54eb6
movq (%r12), %rdi
cmpl $0x0, 0x4(%rsp)
je 0x54f5d
movq %r13, %rsi
callq 0x50a6f
movl $0x10, %r14d
cmpl %ebp, %eax
jg 0x54f89
jmp 0x54eb6
movq 0x50(%rsp), %rsi
callq 0x50a6f
movl %eax, %ecx
shrl $0x1f, %ecx
xorl %edx, %edx
testl %eax, %eax
setle %dl
cmpl $0x0, 0x48(%rsp)
cmovnel %ecx, %edx
movl $0x18, %r14d
testl %edx, %edx
je 0x54eb6
incq %r15
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x3d170
movq (%r12,%r14), %r12
testq %r12, %r12
jne 0x54f2f
jmp 0x54eb6
leaq 0x6e760(%rip), %rdx     # 0xc370d
leaq 0x6e722(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r12, %rsi
movl $0xab8, %r8d            # imm = 0xAB8
callq 0x627c3
movl $0x1, %edi
callq 0x263c0
leaq 0x6bcf0(%rip), %rdi     # 0xc0cc6
leaq 0x6e6f9(%rip), %rsi     # 0xc36d6
movl $0xafd, %edx            # imm = 0xAFD
callq 0x619b4
jmp 0x54fc5