// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: genericZrangebylexCommand
void genericZrangebylexCommand(redisClient *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) != REDIS_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) != REDIS_OK) ||
                    (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_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,REDIS_ZSET))
    {
        zslFreeLexRange(&range);
        return;
    }

    if (zobj->encoding == REDIS_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. */
        redisAssertWithInfo(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. */
            redisAssertWithInfo(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 == REDIS_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 {
        redisPanic("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 0x38(%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 0x3cae5
testl %eax, %eax
je 0x3e7e4
leaq 0x50bfb(%rip), %rsi     # 0x8f3c9
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c2da
movl %ebp, 0xc(%rsp)
movl 0x30(%rbx), %ebp
cmpl $0x5, %ebp
jl 0x3e86c
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x5114b(%rip), %r15     # 0x8f948
testl %ebp, %ebp
je 0x3e86c
cmpl $0x3, %ebp
jl 0x3e8ac
movq 0x38(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x1f2e0
testl %eax, %eax
jne 0x3e8ac
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2f672
testl %eax, %eax
jne 0x3eb00
movq 0x38(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2f672
testl %eax, %eax
jne 0x3eb00
addl $-0x3, %ebp
addq $0x18, %r13
jmp 0x3e7fd
leaq 0x88f8d(%rip), %r12     # 0xc7800
movq 0x68(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2f9a9
testq %rax, %rax
je 0x3e89d
movq %rax, %r15
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2eec6
testl %eax, %eax
je 0x3e8d1
leaq 0x28(%rsp), %rdi
callq 0x3ae93
jmp 0x3eb00
leaq 0x28(%rsp), %rdi
callq 0x3ae93
leaq 0x88f43(%rip), %rax     # 0xc7800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x3eb00
movl (%r15), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x3e90a
cmpl $0x5, %eax
movl 0xc(%rsp), %ebp
jne 0x3eb36
movq 0x8(%r15), %r13
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
testl %ebp, %ebp
je 0x3e9d0
callq 0x3b77d
jmp 0x3e9d5
movq 0x8(%r15), %rax
movq 0x8(%rax), %rdi
movl 0xc(%rsp), %ebp
leaq 0x28(%rsp), %rsi
testl %ebp, %ebp
je 0x3e926
callq 0x3b002
jmp 0x3e92b
callq 0x3af62
movq %rax, %r15
testq %rax, %rax
je 0x3ea36
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq %rbx, %rdi
callq 0x2c506
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rax
leaq 0x10(,%r14,8), %rcx
decq %rax
testq %r15, %r15
je 0x3e973
movq %rax, 0x20(%rsp)
cmpq $-0x1, %rax
je 0x3e973
movq (%r15,%rcx), %r15
jmp 0x3e95a
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
pushq $0x10
popq %r13
testq %r15, %r15
je 0x3eae6
subq $0x1, 0x40(%rsp)
jb 0x3eae6
movq (%r15), %rdi
movq %r14, %rsi
testl %ebp, %ebp
je 0x3e9a8
callq 0x3ac23
movq %r13, %rbp
jmp 0x3e9b0
callq 0x3ac41
pushq $0x18
popq %rbp
testl %eax, %eax
je 0x3eae6
incq %r12
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x2c84a
movq (%r15,%rbp), %r15
movl 0xc(%rsp), %ebp
jmp 0x3e97f
callq 0x3b6dc
movq %rax, %r14
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x3ea36
movq %r13, %rdi
movq %r14, %rsi
callq 0x2ae0d
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x2c506
movq %rax, 0x50(%rsp)
leaq 0x10(%rsp), %r12
testq %r14, %r14
je 0x3ea48
subq $0x1, 0x20(%rsp)
jb 0x3ea48
movq %r13, %rdi
movq %r12, %rsi
leaq 0x18(%rsp), %rdx
testl %ebp, %ebp
je 0x3ea2a
callq 0x3b2e1
jmp 0x3ea2f
callq 0x3b25c
movq 0x10(%rsp), %r14
jmp 0x3ea07
movq 0x68(%r12), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x3e89d
xorl %r12d, %r12d
testq %r14, %r14
je 0x3eae6
subq $0x1, 0x40(%rsp)
jb 0x3eae6
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
testl %ebp, %ebp
je 0x3ea73
callq 0x3b680
jmp 0x3ea78
callq 0x3b6ae
testl %eax, %eax
je 0x3eae6
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x2aea9
testl %eax, %eax
je 0x3eb0f
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x3eaaf
movl 0x4c(%rsp), %edx
movq %rbx, %rdi
callq 0x2c87d
jmp 0x3eabc
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x2c8bb
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %rdx
testl %ebp, %ebp
je 0x3ead4
callq 0x3b2e1
jmp 0x3ead9
callq 0x3b25c
movq 0x10(%rsp), %r14
incq %r12
jmp 0x3ea4b
leaq 0x28(%rsp), %rdi
callq 0x3ae93
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x2c542
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x506e4(%rip), %rdx     # 0x8f1fa
leaq 0x506a6(%rip), %rcx     # 0x8f1c3
movq %rbx, %rdi
movq %r15, %rsi
movl $0xdfd, %r8d            # imm = 0xDFD
callq 0x4980c
pushq $0x1
popq %rdi
callq 0x1f3b0
leaq 0x4e86a(%rip), %rdi     # 0x8d3a7
leaq 0x5067f(%rip), %rsi     # 0x8f1c3
movl $0xe42, %edx            # imm = 0xE42
callq 0x490e8
jmp 0x3eb2e