// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: pushxGenericCommand
void pushxGenericCommand(redisClient *c, robj *refval, robj *val, int where) {
    robj *subject;
    listTypeIterator *iter;
    listTypeEntry entry;
    int inserted = 0;

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

    // 执行的是 LINSERT 命令
    if (refval != NULL) {
        /* We're not sure if this value can be inserted yet, but we cannot
         * convert the list inside the iterator. We don't want to loop over
         * the list twice (once to see if the value can be inserted and once
         * to do the actual insert), so we assume this value can be inserted
         * and convert the ziplist to a regular list if necessary. */
        // 看保存值 value 是否需要将列表编码转换为双端链表
        listTypeTryConversion(subject,val);

        /* Seek refval from head to tail */
        // 在列表中查找 refval 对象
        iter = listTypeInitIterator(subject,0,REDIS_TAIL);
        while (listTypeNext(iter,&entry)) {
            if (listTypeEqual(&entry,refval)) {
                // 找到了，将值插入到节点的前面或后面
                listTypeInsert(&entry,val,where);
                inserted = 1;
                break;
            }
        }
        listTypeReleaseIterator(iter);

        if (inserted) {
            /* Check if the length exceeds the ziplist length threshold. */
            // 查看插入之后是否需要将编码转换为双端链表
            if (subject->encoding == REDIS_ENCODING_ZIPLIST &&
                ziplistLen(subject->ptr) > server.list_max_ziplist_entries)
                    listTypeConvert(subject,REDIS_ENCODING_LINKEDLIST);

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

            notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"linsert",
                                c->argv[1],c->db->id);
            server.dirty++;
        } else {
            /* Notify client of a failed insert */
            // refval 不存在，插入失败
            addReply(c,shared.cnegone);
            return;
        }

    // 执行的是 LPUSHX 或 RPUSHX 命令
    } else {
        char *event = (where == REDIS_HEAD) ? "lpush" : "rpush";

        listTypePush(subject,val,where);

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

        notifyKeyspaceEvent(REDIS_NOTIFY_LIST,event,c->argv[1],c->db->id);

        server.dirty++;
    }

    addReplyLongLong(c,listTypeLength(subject));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x90889(%rip), %rax     # 0xca800
movq 0x20(%rax), %rdx
callq 0x31475
testq %rax, %rax
je 0x39f9c
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x308e7
testl %eax, %eax
je 0x39fab
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
je 0x3a053
movl %ebp, 0xc(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x395f4
movq %r14, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x39935
movq %rax, %r13
leaq 0x10(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x399ca
testl %eax, %eax
je 0x3a0d0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x39c29
testl %eax, %eax
je 0x39fda
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
callq 0x39b51
movq %r13, %rdi
callq 0x2984b
movl $0xf0, %eax
andl (%r14), %eax
leaq 0x5a29d(%rip), %r12     # 0x942c1
cmpl $0x50, %eax
jne 0x3a074
movq 0x8(%r14), %rdi
callq 0x2c9a8
movl %eax, %eax
leaq 0x8ff6d(%rip), %rcx     # 0xc9fa8
cmpq %rax, 0x768(%rcx)
jae 0x3a074
movq %r14, %rdi
movl $0x4, %esi
callq 0x3962c
jmp 0x3a074
testl %ebp, %ebp
leaq 0x5a27b(%rip), %rax     # 0x942d7
leaq 0x5a24a(%rip), %r12     # 0x942ad
cmoveq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x39719
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x316b7
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
movl $0x10, %edi
movq %r12, %rsi
callq 0x608b5
leaq 0x8ff00(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
movq %r14, %rdi
callq 0x398e9
movq %rbx, %rdi
movq %rax, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dea3
movq %r13, %rdi
callq 0x2984b
leaq 0x90721(%rip), %rax     # 0xca800
movq 0x30(%rax), %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d6f0