// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zrankGenericCommand
void zrankGenericCommand(client *c, int reverse) {
    robj *key = c->argv[1];
    robj *ele = c->argv[2];
    robj *zobj;
    unsigned long llen;
    unsigned long rank;

    if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL ||
        checkType(c,zobj,OBJ_ZSET)) return;
    llen = zsetLength(zobj);

    serverAssertWithInfo(c,ele,sdsEncodedObject(ele));

    if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
        unsigned char *zl = zobj->ptr;
        unsigned char *eptr, *sptr;

        eptr = ziplistIndex(zl,0);
        serverAssertWithInfo(c,zobj,eptr != NULL);
        sptr = ziplistNext(zl,eptr);
        serverAssertWithInfo(c,zobj,sptr != NULL);

        rank = 1;
        while(eptr != NULL) {
            if (ziplistCompare(eptr,ele->ptr,sdslen(ele->ptr)))
                break;
            rank++;
            zzlNext(zl,&eptr,&sptr);
        }

        if (eptr != NULL) {
            if (reverse)
                addReplyLongLong(c,llen-rank);
            else
                addReplyLongLong(c,rank-1);
        } else {
            addReply(c,shared.nullbulk);
        }
    } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
        zset *zs = zobj->ptr;
        zskiplist *zsl = zs->zsl;
        dictEntry *de;
        double score;

        ele = c->argv[2];
        de = dictFind(zs->dict,ele);
        if (de != NULL) {
            score = *(double*)dictGetVal(de);
            rank = zslGetRank(zsl,score,ele);
            serverAssertWithInfo(c,ele,rank); /* Existing elements always have a rank. */
            if (reverse)
                addReplyLongLong(c,llen-rank);
            else
                addReplyLongLong(c,rank-1);
        } else {
            addReply(c,shared.nullbulk);
        }
    } else {
        serverPanic("Unknown sorted set encoding");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %r15
leaq 0xae84c(%rip), %r12     # 0x1072b0
movq 0x50(%r12), %rdx
callq 0x44f89
testq %rax, %rax
je 0x58c0b
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
jne 0x58c0b
movq %r14, %rdi
callq 0x551a5
movl (%r15), %ecx
shrl $0x4, %ecx
testb $0x7, %cl
jne 0x58c52
movl %eax, %r13d
movl (%r14), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x58b8c
cmpl $0x5, %eax
jne 0x58c6e
movq 0x8(%r14), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x3ea40
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x58c88
movq %r13, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
movq %r12, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x58ca4
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
sete %bpl
je 0x58bf8
xorl %r13d, %r13d
leaq 0x6db07(%rip), %r14     # 0xc6628
movq 0x8(%r15), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x58b58
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x58b5a
movq -0x11(%rsi), %rdx
jmp 0x58b5a
movzwl -0x5(%rsi), %edx
jmp 0x58b5a
movl -0x9(%rsi), %edx
jmp 0x58b5a
movzbl -0x3(%rsi), %edx
jmp 0x58b5a
xorl %edx, %edx
callq 0x3ec4f
testl %eax, %eax
jne 0x58bf2
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x545d7
movq 0x8(%rsp), %rdi
incq %r13
testq %rdi, %rdi
sete %bpl
jne 0x58b21
jmp 0x58bf8
movq 0x8(%r14), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r15
movq 0x40(%rbx), %rax
movq 0x10(%rax), %r14
movq %r14, %rsi
callq 0x31cca
testq %rax, %rax
je 0x58bd7
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movq %r15, %rdi
movq %r14, %rsi
callq 0x53f2f
testq %rax, %rax
je 0x58cc0
testl %ebp, %ebp
je 0x58c1a
subq %rax, %r13
movq %rbx, %rdi
movq %r13, %rsi
jmp 0x58c23
movq 0x50(%r12), %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fc19
testb $0x1, %bpl
je 0x58c36
leaq 0xae6b1(%rip), %rax     # 0x1072b0
movq 0x50(%rax), %rsi
movq %rbx, %rdi
callq 0x3fc19
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rax
movq %rbx, %rdi
movq %rax, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40606
cmpl $0x0, 0x14(%rsp)
je 0x58c45
notq %r13
addq 0x18(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x40606
jmp 0x58c0b
leaq 0x6dac3(%rip), %rdx     # 0xc671c
leaq 0x6d9f6(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r15, %rsi
movl $0xb30, %r8d            # imm = 0xB30
jmp 0x58cda
leaq 0x6b001(%rip), %rdi     # 0xc3c76
leaq 0x6d9da(%rip), %rsi     # 0xc6656
movl $0xb5f, %edx            # imm = 0xB5F
callq 0x6558d
jmp 0x58cdf
leaq 0x6da50(%rip), %rdx     # 0xc66df
leaq 0x6d9c0(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0xb37, %r8d            # imm = 0xB37
jmp 0x58cda
leaq 0x6dd5b(%rip), %rdx     # 0xc6a06
leaq 0x6d9a4(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0xb39, %r8d            # imm = 0xB39
jmp 0x58cda
leaq 0x66a46(%rip), %rdx     # 0xbf70d
leaq 0x6d988(%rip), %rcx     # 0xc6656
movq %rbx, %rdi
movq %r14, %rsi
movl $0xb56, %r8d            # imm = 0xB56
callq 0x66380
movl $0x1, %edi
callq 0x263d0