// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: zremCommand
void zremCommand(redisClient *c) {
    robj *key = c->argv[1];
    robj *zobj;
    int deleted = 0, keyremoved = 0, j;

    // 取出有序集合对象
    if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
        checkType(c,zobj,REDIS_ZSET)) return;

    // 从 ziplist 中删除
    if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *eptr;

        // 遍历所有输入元素
        for (j = 2; j < c->argc; j++) {
            // 如果元素在 ziplist 中存在的话
            if ((eptr = zzlFind(zobj->ptr,c->argv[j],NULL)) != NULL) {
                // 元素存在时，删除计算器才增一
                deleted++;
                // 那么删除它们
                zobj->ptr = zzlDelete(zobj->ptr,eptr);
                
                // ziplist 已清空，将有序集合从数据库中删除
                if (zzlLength(zobj->ptr) == 0) {
                    dbDelete(c->db,key);
                    break;
                }
            }
        }

    // 从跳跃表和字典中删除
    } else if (zobj->encoding == REDIS_ENCODING_SKIPLIST) {
        zset *zs = zobj->ptr;
        dictEntry *de;
        double score;

        // 遍历所有输入元素
        for (j = 2; j < c->argc; j++) {

            // 查找元素
            de = dictFind(zs->dict,c->argv[j]);

            if (de != NULL) {
                // 元素存在时，删除计算器才增一
                deleted++;

                /* Delete from the skiplist */
                // 将元素从跳跃表中删除
                score = *(double*)dictGetVal(de);
                redisAssertWithInfo(c,c->argv[j],zslDelete(zs->zsl,score,c->argv[j]));

                /* Delete from the hash table */
                // 将元素从字典中删除
                dictDelete(zs->dict,c->argv[j]);

                // 检查是否需要缩小字典
                if (htNeedsResize(zs->dict)) dictResize(zs->dict);

                // 字典已被清空，有序集合已经被清空，将它从数据库中删除
                if (dictSize(zs->dict) == 0) {
                    dbDelete(c->db,key);
                    break;
                }
            }
        }
    } else {
        redisPanic("Unknown sorted set encoding");
    }

    // 如果有至少一个元素被删除的话，那么执行以下代码
    if (deleted) {

        notifyKeyspaceEvent(REDIS_NOTIFY_ZSET,"zrem",key,c->db->id);

        if (keyremoved)
            notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"del",key,c->db->id);

        signalModifiedKey(c->db,key);

        server.dirty += deleted;
    }

    // 回复被删除元素的数量
    addReplyLongLong(c,deleted);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0xc35a7(%rip), %rax     # 0x114150
movq 0x20(%rax), %rdx
callq 0x3c110
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x50bd3
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x3, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x50bd8
jmp 0x50e97
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x50c90
movl $0x2, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x50c8b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x4f990
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x50c7b
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x4fab0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4f0e0
cmpl $0x0, %eax
jne 0x50c79
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x3c4f0
jmp 0x50c8b
jmp 0x50c7b
jmp 0x50c7d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x50bf4
jmp 0x50e0d
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x50de9
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x2, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x50de7
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x23aa0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x50dd7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movsd -0x48(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4d8b0
cmpl $0x0, %eax
je 0x50d36
jmp 0x50d6d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x92705(%rip), %rdx     # 0xe3456
leaq 0x92536(%rip), %rcx     # 0xe328e
movl $0x7ab, %r8d            # imm = 0x7AB
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x23c30
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x25700
cmpl $0x0, %eax
je 0x50da6
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x23250
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
addq 0x48(%rcx), %rax
cmpq $0x0, %rax
jne 0x50dd5
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x3c4f0
jmp 0x50de7
jmp 0x50dd7
jmp 0x50dd9
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x50cb8
jmp 0x50e0b
leaq 0x906ab(%rip), %rdi     # 0xe149b
leaq 0x92497(%rip), %rsi     # 0xe328e
movl $0x7bc, %edx            # imm = 0x7BC
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x50e0d
cmpl $0x0, -0x1c(%rbp)
je 0x50e8a
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x80, %edi
leaq 0x8d5d9(%rip), %rsi     # 0xde407
callq 0x814a0
cmpl $0x0, -0x20(%rbp)
je 0x50e59
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x4, %edi
leaq 0x8d6b1(%rip), %rsi     # 0xde505
callq 0x814a0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x3c3d0
movslq -0x1c(%rbp), %rcx
leaq 0xc2a83(%rip), %rax     # 0x1138f8
addq 0x560(%rax), %rcx
leaq 0xc2a75(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x36480
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)