// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: lremCommand
void lremCommand(redisClient *c) {
    robj *subject, *obj;

    // 编码目标对象 elem
    obj = c->argv[3] = tryObjectEncoding(c->argv[3]);
    long toremove;
    long removed = 0;
    listTypeEntry entry;

    // 取出指定删除模式的 count 参数
    if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != REDIS_OK))
        return;

    // 取出列表对象
    subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero);
    if (subject == NULL || checkType(c,subject,REDIS_LIST)) return;

    /* Make sure obj is raw when we're dealing with a ziplist */
    if (subject->encoding == REDIS_ENCODING_ZIPLIST)
        obj = getDecodedObject(obj);

    listTypeIterator *li;

    // 根据 toremove 参数，决定是从表头还是表尾开始进行删除
    if (toremove < 0) {
        toremove = -toremove;
        li = listTypeInitIterator(subject,-1,REDIS_HEAD);
    } else {
        li = listTypeInitIterator(subject,0,REDIS_TAIL);
    }

    // 查找，比对对象，并进行删除
    while (listTypeNext(li,&entry)) {
        if (listTypeEqual(&entry,obj)) {
            listTypeDelete(&entry);
            server.dirty++;
            removed++;
            // 已经满足删除数量，停止
            if (toremove && removed == toremove) break;
        }
    }
    listTypeReleaseIterator(li);

    /* Clean up raw encoded object */
    if (subject->encoding == REDIS_ENCODING_ZIPLIST)
        decrRefCount(obj);

    // 删除空列表
    if (listTypeLength(subject) == 0) dbDelete(c->db,c->argv[1]);

    addReplyLongLong(c,removed);

    if (removed) signalModifiedKey(c->db,c->argv[1]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x18(%rax), %rdi
callq 0x30c49
movq %rax, %r14
movq 0x38(%rbx), %rax
movq %r14, 0x18(%rax)
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x313b2
testl %eax, %eax
je 0x3ab51
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0x8fca0(%rip), %rax     # 0xca800
movq 0x20(%rax), %rdx
movq %rbx, %rdi
callq 0x317a6
testq %rax, %rax
je 0x3ab42
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x30bbf
testl %eax, %eax
jne 0x3ab42
movl $0xf0, %eax
andl (%r15), %eax
cmpl $0x50, %eax
jne 0x3aba0
movq %r14, %rdi
callq 0x30d93
movq %rax, %r14
movq 0x8(%rsp), %rax
testq %rax, %rax
js 0x3abb6
movq %r15, %rdi
xorl %esi, %esi
movl $0x1, %edx
jmp 0x3abca
negq %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq $-0x1, %rsi
xorl %edx, %edx
callq 0x399c5
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x39a5a
xorl %r12d, %r12d
testl %eax, %eax
je 0x3ac37
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x39cb9
testl %eax, %eax
je 0x3ac28
movq %rbp, %rdi
callq 0x39d38
leaq 0x8f39f(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
incq %r12
movq 0x8(%rsp), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r12
sete %al
testb %al, %cl
jne 0x3ac37
movq %r13, %rdi
movq %rbp, %rsi
callq 0x39a5a
testl %eax, %eax
jne 0x3abeb
movq %r13, %rdi
callq 0x29af7
movl $0xf0, %eax
andl (%r15), %eax
cmpl $0x50, %eax
jne 0x3ac54
movq %r14, %rdi
callq 0x30b0c
movq %r15, %rdi
callq 0x39979
testq %rax, %rax
jne 0x3ac72
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x31a36
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2e133
testq %r12, %r12
je 0x3ab42
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x319b8
jmp 0x3ab42