// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0x3ab5e
testl %eax, %eax
je 0x450cc
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 0xb5235(%rip), %rax     # 0xfa310
movq 0x20(%rax), %rdx
movq %rbx, %rdi
callq 0x3af15
testq %rax, %rax
je 0x450bd
movq %rax, %r14
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
jne 0x450bd
movq 0x8(%rsp), %rax
testq %rax, %rax
js 0x45115
pushq $0x1
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
jmp 0x45125
negq %rax
movq %rax, 0x8(%rsp)
pushq $-0x1
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x442b8
movq %rax, %r13
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x44347
testl %eax, %eax
je 0x45186
movq %rbp, %rdi
movq %r15, %rsi
callq 0x44482
testl %eax, %eax
je 0x45135
movq %r13, %rdi
movq %rbp, %rsi
callq 0x444f9
leaq 0xb4743(%rip), %rax     # 0xf98a8
incq 0x720(%rax)
incq %r12
movq 0x8(%rsp), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r12
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0x45135
movq %r13, %rdi
callq 0x44331
testq %r12, %r12
je 0x451c2
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3b125
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x69346(%rip), %rsi     # 0xae500
pushq $0x4
popq %rdi
callq 0x6fb58
movq %r14, %rdi
callq 0x4427e
testq %rax, %rax
jne 0x451fe
movq 0x10(%rbx), %rdi
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3b1df
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x6b222(%rip), %rsi     # 0xb0418
pushq $0x4
popq %rdi
callq 0x6fb58
movq %rbx, %rdi
movq %r12, %rsi
callq 0x370a6
jmp 0x450bd