// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0xad214(%rip), %r12     # 0x102310
movq 0x50(%r12), %rdx
callq 0x41af9
testq %rax, %rax
je 0x55122
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
je 0x55131
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x51a88
movl (%r15), %ecx
shrl $0x4, %ecx
testb $0x7, %cl
jne 0x552d5
movl %eax, %eax
movq %rax, 0x10(%rsp)
movl (%r13), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x55232
cmpl $0x5, %eax
jne 0x552f1
movq 0x8(%r13), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x3b680
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x5530b
movq %rax, %r14
movl %ebp, 0xc(%rsp)
movq %r12, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x55327
xorl %r13d, %r13d
leaq 0x6e4f7(%rip), %rbp     # 0xc36a8
movq 0x8(%r15), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x551e9
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x551eb
movq -0x11(%rsi), %rdx
jmp 0x551eb
movzwl -0x5(%rsi), %edx
jmp 0x551eb
movl -0x9(%rsi), %edx
jmp 0x551eb
movzbl -0x3(%rsi), %edx
jmp 0x551eb
xorl %edx, %edx
movq %r14, %rdi
callq 0x3b8e6
testl %eax, %eax
jne 0x5527f
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x50f41
movq 0x18(%rsp), %r14
incq %r13
testq %r14, %r14
jne 0x551b1
leaq 0xad0ef(%rip), %rax     # 0x102310
movq 0x50(%rax), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x55122
movq 0x8(%r13), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r15
movq 0x40(%rbx), %rax
movq 0x10(%rax), %r14
movq %r14, %rsi
callq 0x2ebca
testq %rax, %rax
je 0x5529e
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movq %r15, %rdi
movq %r14, %rsi
callq 0x507f6
testq %rax, %rax
je 0x55343
testl %ebp, %ebp
je 0x552b9
movq 0x10(%rsp), %rsi
subq %rax, %rsi
movq %rbx, %rdi
jmp 0x552c2
cmpl $0x0, 0xc(%rsp)
je 0x5528e
notq %r13
addq 0x10(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d23f
jmp 0x55122
movq 0x50(%r12), %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3c854
decq %rax
movq %rbx, %rdi
movq %rax, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3d23f
leaq 0x6e4c0(%rip), %rdx     # 0xc379c
leaq 0x6e3f3(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r15, %rsi
movl $0xb30, %r8d            # imm = 0xB30
jmp 0x5535d
leaq 0x6b9ce(%rip), %rdi     # 0xc0cc6
leaq 0x6e3d7(%rip), %rsi     # 0xc36d6
movl $0xb5f, %edx            # imm = 0xB5F
callq 0x619b4
jmp 0x55362
leaq 0x6e44d(%rip), %rdx     # 0xc375f
leaq 0x6e3bd(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r13, %rsi
movl $0xb37, %r8d            # imm = 0xB37
jmp 0x5535d
leaq 0x6e758(%rip), %rdx     # 0xc3a86
leaq 0x6e3a1(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r13, %rsi
movl $0xb39, %r8d            # imm = 0xB39
jmp 0x5535d
leaq 0x67413(%rip), %rdx     # 0xbc75d
leaq 0x6e385(%rip), %rcx     # 0xc36d6
movq %rbx, %rdi
movq %r14, %rsi
movl $0xb56, %r8d            # imm = 0xB56
callq 0x627c3
movl $0x1, %edi
callq 0x263c0