// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_list.c
// Function: lremCommand
void lremCommand(client *c) {
    robj *subject, *obj;
    obj = c->argv[3];
    long toremove;
    long removed = 0;

    if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != C_OK))
        return;

    subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero);
    if (subject == NULL || checkType(c,subject,OBJ_LIST)) return;

    listTypeIterator *li;
    if (toremove < 0) {
        toremove = -toremove;
        li = listTypeInitIterator(subject,-1,LIST_HEAD);
    } else {
        li = listTypeInitIterator(subject,0,LIST_TAIL);
    }

    listTypeEntry entry;
    while (listTypeNext(li,&entry)) {
        if (listTypeEqual(&entry,obj)) {
            listTypeDelete(li, &entry);
            server.dirty++;
            removed++;
            if (toremove && removed == toremove) break;
        }
    }
    listTypeReleaseIterator(li);

    if (removed) {
        signalModifiedKey(c->db,c->argv[1]);
        notifyKeyspaceEvent(NOTIFY_GENERIC,"lrem",c->argv[1],c->db->id);
    }

    if (listTypeLength(subject) == 0) {
        dbDelete(c->db,c->argv[1]);
        notifyKeyspaceEvent(NOTIFY_GENERIC,"del",c->argv[1],c->db->id);
    }

    addReplyLongLong(c,removed);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x18(%rax), %r15
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
je 0x50b49
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0xb6758(%rip), %rax     # 0x1072b0
movq 0x20(%rax), %rdx
movq %rbx, %rdi
callq 0x44fbb
testq %rax, %rax
je 0x50b3a
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x441ab
testl %eax, %eax
jne 0x50b3a
movq 0x8(%rsp), %rax
testq %rax, %rax
js 0x50b96
movq %r14, %rdi
xorl %esi, %esi
movl $0x1, %edx
jmp 0x50baa
negq %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq $-0x1, %rsi
xorl %edx, %edx
callq 0x4fc5a
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x4fcf2
xorl %r12d, %r12d
testl %eax, %eax
je 0x50c1a
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4fe5a
testl %eax, %eax
je 0x50c0b
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fef6
leaq 0xb5c6c(%rip), %rax     # 0x106858
incq 0x710(%rax)
incq %r12
movq 0x8(%rsp), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r12
sete %al
testb %al, %cl
jne 0x50c1a
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fcf2
testl %eax, %eax
jne 0x50bcb
movq 0x10(%r13), %rdi
callq 0x3b3df
movq %r13, %rdi
callq 0x3b3df
testq %r12, %r12
je 0x50c61
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x45220
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x6e969(%rip), %rsi     # 0xbf5c0
movl $0x4, %edi
callq 0x800c9
movq %r14, %rdi
callq 0x4fc1c
testq %rax, %rax
jne 0x50c9f
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x452f3
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x70821(%rip), %rsi     # 0xc14b6
movl $0x4, %edi
callq 0x800c9
movq %rbx, %rdi
movq %r12, %rsi
callq 0x40606
jmp 0x50b3a