// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x3acc0
movq -0x8(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq %rax, 0x18(%rcx)
movq %rax, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x49d4c
jmp 0x49eda
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0xca3ed(%rip), %rax     # 0x114150
movq 0x20(%rax), %rdx
callq 0x3c110
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x49d8e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x49d93
jmp 0x49eda
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x49db1
movq -0x18(%rbp), %rdi
callq 0x3aef0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x49dda
xorl %eax, %eax
subq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq $-0x1, %rsi
xorl %edx, %edx
callq 0x48180
movq %rax, -0x48(%rbp)
jmp 0x49df0
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x48180
movq %rax, -0x48(%rbp)
jmp 0x49df2
movq -0x48(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x48280
cmpl $0x0, %eax
je 0x49e62
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x48730
cmpl $0x0, %eax
je 0x49e60
leaq -0x40(%rbp), %rdi
callq 0x48840
leaq 0xc9ad2(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xc9ac0(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x49e5e
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x49e5e
jmp 0x49e62
jmp 0x49e60
jmp 0x49df2
movq -0x48(%rbp), %rdi
callq 0x48260
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x49e85
movq -0x18(%rbp), %rdi
callq 0x3aaa0
movq -0x10(%rbp), %rdi
callq 0x480f0
cmpq $0x0, %rax
jne 0x49ead
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3c4f0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36480
cmpq $0x0, -0x28(%rbp)
je 0x49eda
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3c3d0
addq $0x50, %rsp
popq %rbp
retq