// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0xcb48b(%rip), %rax     # 0x114150
movq 0x20(%rax), %rdx
callq 0x3c0c0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x48cef
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x48cf4
jmp 0x48eda
cmpq $0x0, -0x10(%rbp)
je 0x48e33
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x47cc0
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x48180
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x48280
cmpl $0x0, %eax
je 0x48d61
movq -0x10(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x48730
cmpl $0x0, %eax
je 0x48d5f
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x48(%rbp), %rdi
callq 0x48540
movl $0x1, -0x4c(%rbp)
jmp 0x48d61
jmp 0x48d22
movq -0x30(%rbp), %rdi
callq 0x48260
cmpl $0x0, -0x4c(%rbp)
je 0x48e15
movq -0x28(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x48db2
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33f70
movl %eax, %eax
leaq 0xcab5d(%rip), %rcx     # 0x1138f8
cmpq 0x768(%rcx), %rax
jbe 0x48db2
movq -0x28(%rbp), %rdi
movl $0x4, %esi
callq 0x47d40
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3c3d0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x10, %edi
leaq 0x9554b(%rip), %rsi     # 0xde339
callq 0x814a0
leaq 0xcaafe(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xcaaec(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
jmp 0x48e2e
movq -0x8(%rbp), %rdi
leaq 0xcb330(%rip), %rax     # 0x114150
movq 0x30(%rax), %rsi
callq 0x35a70
jmp 0x48eda
jmp 0x48ebd
movl -0x1c(%rbp), %edx
leaq 0x954e8(%rip), %rax     # 0xde325
leaq 0x9550b(%rip), %rcx     # 0xde34f
cmpl $0x0, %edx
cmoveq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x47e50
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3c3d0
movq -0x58(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x10, %edi
callq 0x814a0
leaq 0xcaa54(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xcaa42(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rdi
callq 0x480f0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x36480
addq $0x60, %rsp
popq %rbp
retq