// File: /workspace/github_c_makefile_star2_O3/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
movl %esi, %ebp
movq %rdi, %rbx
movq 0x38(%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 0x3fa0d
testl %eax, %eax
je 0x418bb
leaq 0x57b60(%rip), %rsi     # 0x99405
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dc63
movl %ebp, 0x4(%rsp)
movl 0x30(%rbx), %ebp
cmpl $0x5, %ebp
jge 0x41916
leaq 0x88f32(%rip), %r15     # 0xca800
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31745
testq %rax, %rax
je 0x418fd
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x30bbf
testl %eax, %eax
je 0x419ba
movq 0x8(%rsp), %rdi
callq 0x30b0c
movq 0x10(%rsp), %rdi
callq 0x30b0c
jmp 0x41b9a
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x58061(%rip), %r15     # 0x99984
cmpl $0x3, %ebp
jl 0x4198b
movq 0x38(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x1f2e0
testl %eax, %eax
jne 0x4198b
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x313b2
testl %eax, %eax
jne 0x41b9a
movq 0x38(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x313b2
testl %eax, %eax
jne 0x41b9a
addq $0x18, %r13
addl $-0x3, %ebp
jne 0x41923
jmp 0x418c7
movq 0x8(%rsp), %rdi
callq 0x30b0c
movq 0x10(%rsp), %rdi
callq 0x30b0c
leaq 0x88e5a(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
jmp 0x41b9a
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x419ee
cmpl $0x5, %eax
movl 0x4(%rsp), %ebp
jne 0x41c8e
movq 0x8(%r12), %r13
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
testl %ebp, %ebp
je 0x41a62
callq 0x3e600
jmp 0x41a67
movq 0x8(%r12), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %rsi
testl %ebp, %ebp
je 0x41a0b
callq 0x3ddbc
jmp 0x41a10
callq 0x3dcb3
movq %rax, %r12
testq %rax, %rax
je 0x41ba9
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq %rbx, %rdi
callq 0x2de9a
movq %rax, %rbp
movq 0x30(%rsp), %rax
leaq 0x10(,%r14,8), %rcx
subq $0x1, %rax
jb 0x41bba
movq (%r12,%rcx), %r12
testq %r12, %r12
jne 0x41a3d
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %r13
xorl %r15d, %r15d
jmp 0x41b7a
callq 0x3e552
movq %rax, %r14
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x41ba9
movq %r13, %rdi
movq %r14, %rsi
callq 0x2c558
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
callq 0x2de9a
movq %rax, 0x20(%rsp)
subq $0x1, 0x30(%rsp)
jb 0x41ad3
xorl %r15d, %r15d
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x41ab8
callq 0x3e126
jmp 0x41abd
callq 0x3e09f
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x41b70
subq $0x1, 0x30(%rsp)
jae 0x41aa0
xorl %r15d, %r15d
subq $0x1, 0x40(%rsp)
jb 0x41b70
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
testl %ebp, %ebp
je 0x41af5
callq 0x3e4da
jmp 0x41afa
callq 0x3e514
testl %eax, %eax
je 0x41b70
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x2c5f6
testl %eax, %eax
je 0x41c65
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x41b35
movl 0x4c(%rsp), %edx
movq %rbx, %rdi
callq 0x2e237
jmp 0x41b42
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x2e277
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x41b5a
callq 0x3e126
jmp 0x41b5f
callq 0x3e09f
movq 0x28(%rsp), %r14
incq %r15
testq %r14, %r14
jne 0x41ad6
movq 0x8(%rsp), %r13
movq 0x20(%rsp), %rbp
movq %r13, %rdi
callq 0x30b0c
movq 0x10(%rsp), %rdi
callq 0x30b0c
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2ded6
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x2d97c
jmp 0x418fd
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 0x41b75
movq (%r12), %rdi
cmpl $0x0, 0x4(%rsp)
je 0x41c1c
movq %r13, %rsi
callq 0x3dbcd
movl $0x10, %r14d
cmpl %ebp, %eax
jg 0x41c48
jmp 0x41b75
movq 0x50(%rsp), %rsi
callq 0x3dbcd
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 0x41b75
incq %r15
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x2e204
movq (%r12,%r14), %r12
testq %r12, %r12
jne 0x41bee
jmp 0x41b75
leaq 0x575ca(%rip), %rdx     # 0x99236
leaq 0x5758c(%rip), %rcx     # 0x991ff
movq %rbx, %rdi
movq %r12, %rsi
movl $0xdfd, %r8d            # imm = 0xDFD
callq 0x4d277
movl $0x1, %edi
callq 0x1f3b0
leaq 0x5571e(%rip), %rdi     # 0x973b3
leaq 0x57563(%rip), %rsi     # 0x991ff
movl $0xe42, %edx            # imm = 0xE42
callq 0x4cae0
jmp 0x41c84