// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 $0x78, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%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 0x5646e
testl %eax, %eax
je 0x58523
leaq 0x6e3bd(%rip), %rsi     # 0xc68ca
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ffcb
movl %ebp, 0xc(%rsp)
movl 0x38(%rbx), %ebp
cmpl $0x5, %ebp
jge 0x5857e
leaq 0xaed7a(%rip), %r15     # 0x1072b0
movq 0x68(%r15), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x44f89
testq %rax, %rax
je 0x58565
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
je 0x58622
movq 0x20(%rsp), %rdi
callq 0x440f3
movq 0x28(%rsp), %rdi
callq 0x440f3
jmp 0x588fd
addl $-0x4, %ebp
xorl %r13d, %r13d
leaq 0x6ea58(%rip), %r15     # 0xc6fe3
cmpl $0x3, %ebp
jl 0x585f3
movq 0x40(%rbx), %r12
movq 0x20(%r12,%r13), %rax
movq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x26300
testl %eax, %eax
jne 0x585f3
movq 0x28(%r12,%r13), %rsi
movq %rbx, %rdi
leaq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x588fd
movq 0x40(%rbx), %rax
movq 0x30(%rax,%r13), %rsi
movq %rbx, %rdi
leaq 0x48(%rsp), %rdx
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x588fd
addq $0x18, %r13
addl $-0x3, %ebp
jne 0x5858b
jmp 0x5852f
movq 0x20(%rsp), %rdi
callq 0x440f3
movq 0x28(%rsp), %rdi
callq 0x440f3
leaq 0xaeca2(%rip), %rax     # 0x1072b0
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x3fc19
jmp 0x588fd
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x5865b
cmpl $0x5, %eax
movl 0xc(%rsp), %ebp
jne 0x58937
movq 0x8(%r14), %r12
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
testl %ebp, %ebp
je 0x586ed
callq 0x54b3b
jmp 0x586f2
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
movl 0xc(%rsp), %ebp
leaq 0x20(%rsp), %rsi
testl %ebp, %ebp
je 0x58677
callq 0x54345
jmp 0x5867c
callq 0x5426f
movq %rax, %r14
testq %rax, %rax
je 0x586c2
xorl %r15d, %r15d
testl %ebp, %ebp
sete %r15b
movq %rbx, %rdi
callq 0x402b0
movq %rax, (%rsp)
movq 0x38(%rsp), %rax
leaq 0x10(,%r15,8), %rcx
movq %r14, %r13
subq $0x1, %rax
jb 0x5886f
movq (%r13,%rcx), %r13
testq %r13, %r13
jne 0x586a9
jmp 0x58876
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x3fc19
movq 0x20(%rsp), %rdi
callq 0x440f3
movq 0x28(%rsp), %rdi
callq 0x440f3
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x588d6
callq 0x54a5d
movq %rax, %r13
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5883f
movq %r14, 0x58(%rsp)
movq %r12, %rdi
movq %r13, 0x18(%rsp)
movq %r13, %rsi
callq 0x3ead6
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x402b0
movq %rax, (%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x58764
leaq 0x10(%rsp), %r15
leaq 0x40(%rsp), %r13
subq $0x1, 0x38(%rsp)
jb 0x58764
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
testl %ebp, %ebp
je 0x58757
callq 0x5465e
jmp 0x5875c
callq 0x545d7
cmpq $0x0, 0x10(%rsp)
jne 0x5873b
movq 0x10(%rsp), %r13
xorl %r15d, %r15d
testq %r13, %r13
je 0x58834
movq %r12, 0x60(%rsp)
subq $0x1, 0x48(%rsp)
jb 0x58834
movq %r13, %rdi
callq 0x544b6
movq %rax, %r14
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
testl %ebp, %ebp
je 0x587a4
callq 0x53e0a
jmp 0x587a9
callq 0x53e28
movl %eax, %r12d
movq %r14, %rdi
callq 0x440f3
testl %r12d, %r12d
je 0x58834
movq %r13, %rdi
leaq 0x70(%rsp), %rsi
leaq 0x54(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x3eb60
testl %eax, %eax
movq 0x60(%rsp), %r12
je 0x5890c
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
movl 0xc(%rsp), %ebp
je 0x587f9
movl 0x54(%rsp), %edx
movq %rbx, %rdi
callq 0x4070f
jmp 0x58806
movq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x407de
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x40(%rsp), %rdx
testl %ebp, %ebp
je 0x5881e
callq 0x5465e
jmp 0x58823
callq 0x545d7
movq 0x10(%rsp), %r13
incq %r15
testq %r13, %r13
jne 0x5877a
movq (%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0x58865
movq 0x68(%r15), %rsi
movq %rbx, %rdi
callq 0x3fc19
movq 0x20(%rsp), %rdi
callq 0x440f3
movq 0x28(%rsp), %rdi
callq 0x440f3
xorl %r12d, %r12d
xorl %r15d, %r15d
testq %r13, %r13
jne 0x588db
jmp 0x588fd
movq $-0x1, %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
testq %r13, %r13
je 0x588d2
leaq 0x20(%rsp), %r12
subq $0x1, 0x48(%rsp)
jb 0x588d2
movq (%r13), %rdi
movq %r12, %rsi
testl %ebp, %ebp
je 0x588a7
callq 0x53e0a
movl $0x10, %ebp
jmp 0x588b1
callq 0x53e28
movl $0x18, %ebp
testl %eax, %eax
je 0x588d2
incq %r15
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x40537
movq (%r13,%rbp), %r13
testq %r13, %r13
movl 0xc(%rsp), %ebp
jne 0x58888
movq (%rsp), %r12
testq %r14, %r14
je 0x588fd
movq 0x20(%rsp), %rdi
callq 0x440f3
movq 0x28(%rsp), %rdi
callq 0x440f3
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x402ec
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6dd7a(%rip), %rdx     # 0xc668d
leaq 0x6dd3c(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
movl $0xab8, %r8d            # imm = 0xAB8
callq 0x66380
movl $0x1, %edi
callq 0x263d0
leaq 0x6b338(%rip), %rdi     # 0xc3c76
leaq 0x6dd11(%rip), %rsi     # 0xc6656
movl $0xafd, %edx            # imm = 0xAFD
callq 0x6558d
jmp 0x5892d