// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r14
movq $0x0, 0x38(%rsp)
movq $-0x1, 0x48(%rsp)
xorl %ecx, %ecx
testl %esi, %esi
sete %cl
movq 0x10(%rax,%rcx,8), %rsi
xorl $0x3, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3f9d9
testl %eax, %eax
je 0x41963
leaq 0x57a6f(%rip), %rsi     # 0x993bc
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d9d7
movl %ebp, 0xc(%rsp)
movl 0x30(%rbx), %ebp
cmpl $0x5, %ebp
jge 0x419be
leaq 0x88e8a(%rip), %r15     # 0xca800
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31475
testq %rax, %rax
je 0x419a5
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x308e7
testl %eax, %eax
je 0x41a62
movq 0x20(%rsp), %rdi
callq 0x30834
movq 0x28(%rsp), %rdi
callq 0x30834
jmp 0x41d3d
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x57f71(%rip), %r15     # 0x9993c
cmpl $0x3, %ebp
jl 0x41a33
movq 0x38(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x1f2e0
testl %eax, %eax
jne 0x41a33
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x310df
testl %eax, %eax
jne 0x41d3d
movq 0x38(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x48(%rsp), %rdx
xorl %ecx, %ecx
callq 0x310df
testl %eax, %eax
jne 0x41d3d
addq $0x18, %r13
addl $-0x3, %ebp
jne 0x419cb
jmp 0x4196f
movq 0x20(%rsp), %rdi
callq 0x30834
movq 0x28(%rsp), %rdi
callq 0x30834
leaq 0x88db2(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
jmp 0x41d3d
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x41a9b
cmpl $0x5, %eax
movl 0xc(%rsp), %ebp
jne 0x41d77
movq 0x8(%r14), %r12
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
testl %ebp, %ebp
je 0x41b2d
callq 0x3e4e1
jmp 0x41b32
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
movl 0xc(%rsp), %ebp
leaq 0x20(%rsp), %rsi
testl %ebp, %ebp
je 0x41ab7
callq 0x3dceb
jmp 0x41abc
callq 0x3dc15
movq %rax, %r14
testq %rax, %rax
je 0x41b02
xorl %r15d, %r15d
testl %ebp, %ebp
sete %r15b
movq %rbx, %rdi
callq 0x2dc0a
movq %rax, (%rsp)
movq 0x38(%rsp), %rax
leaq 0x10(,%r15,8), %rcx
movq %r14, %r13
subq $0x1, %rax
jb 0x41caf
movq (%r13,%rcx), %r13
testq %r13, %r13
jne 0x41ae9
jmp 0x41cb6
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x2d6f0
movq 0x20(%rsp), %rdi
callq 0x30834
movq 0x28(%rsp), %rdi
callq 0x30834
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x41d16
callq 0x3e403
movq %rax, %r13
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x41c7f
movq %r14, 0x58(%rsp)
movq %r12, %rdi
movq %r13, 0x18(%rsp)
movq %r13, %rsi
callq 0x2c2b3
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x2dc0a
movq %rax, (%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x41ba4
leaq 0x10(%rsp), %r15
leaq 0x40(%rsp), %r13
subq $0x1, 0x38(%rsp)
jb 0x41ba4
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
testl %ebp, %ebp
je 0x41b97
callq 0x3e004
jmp 0x41b9c
callq 0x3df7d
cmpq $0x0, 0x10(%rsp)
jne 0x41b7b
movq 0x10(%rsp), %r13
xorl %r15d, %r15d
testq %r13, %r13
je 0x41c74
movq %r12, 0x60(%rsp)
subq $0x1, 0x48(%rsp)
jb 0x41c74
movq %r13, %rdi
callq 0x3de5c
movq %rax, %r14
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
testl %ebp, %ebp
je 0x41be4
callq 0x3d868
jmp 0x41be9
callq 0x3d886
movl %eax, %r12d
movq %r14, %rdi
callq 0x30834
testl %r12d, %r12d
je 0x41c74
movq %r13, %rdi
leaq 0x70(%rsp), %rsi
leaq 0x54(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x2c351
testl %eax, %eax
movq 0x60(%rsp), %r12
je 0x41d4c
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
movl 0xc(%rsp), %ebp
je 0x41c39
movl 0x54(%rsp), %edx
movq %rbx, %rdi
callq 0x2dfa7
jmp 0x41c46
movq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x2dfe7
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
testl %ebp, %ebp
je 0x41c5e
callq 0x3e004
jmp 0x41c63
callq 0x3df7d
movq 0x10(%rsp), %r13
incq %r15
testq %r13, %r13
jne 0x41bba
movq (%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0x41ca5
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x2d6f0
movq 0x20(%rsp), %rdi
callq 0x30834
movq 0x28(%rsp), %rdi
callq 0x30834
xorl %r12d, %r12d
xorl %r15d, %r15d
testq %r13, %r13
jne 0x41d1b
jmp 0x41d3d
movq $-0x1, %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
testq %r13, %r13
je 0x41d12
leaq 0x20(%rsp), %r12
subq $0x1, 0x48(%rsp)
jb 0x41d12
movq (%r13), %rdi
movq %r12, %rsi
testl %ebp, %ebp
je 0x41ce7
callq 0x3d868
movl $0x10, %ebp
jmp 0x41cf1
callq 0x3d886
movl $0x18, %ebp
testl %eax, %eax
je 0x41d12
incq %r15
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x2df74
movq (%r13,%rbp), %r13
testq %r13, %r13
movl 0xc(%rsp), %ebp
jne 0x41cc8
movq (%rsp), %r12
testq %r14, %r14
je 0x41d3d
movq 0x20(%rsp), %rdi
callq 0x30834
movq 0x28(%rsp), %rdi
callq 0x30834
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2dc46
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5749a(%rip), %rdx     # 0x991ed
leaq 0x5745c(%rip), %rcx     # 0x991b6
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
movl $0xdfd, %r8d            # imm = 0xDFD
callq 0x4d872
movl $0x1, %edi
callq 0x1f3b0
leaq 0x555d5(%rip), %rdi     # 0x97353
leaq 0x57431(%rip), %rsi     # 0x991b6
movl $0xe42, %edx            # imm = 0xE42
callq 0x4d0e5
jmp 0x41d6d