// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: lsetCommand
void lsetCommand(redisClient *c) {

    // 取出列表对象
    robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);

    if (o == NULL || checkType(c,o,REDIS_LIST)) return;
    long index;

    // 取出值对象 value
    robj *value = (c->argv[3] = tryObjectEncoding(c->argv[3]));

    // 取出整数值对象 index
    if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK))
        return;

    // 查看保存 value 值是否需要转换列表的底层编码
    listTypeTryConversion(o,value);

    // 设置到 ziplist
    if (o->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *p, *zl = o->ptr;
        // 查找索引
        p = ziplistIndex(zl,index);
        if (p == NULL) {
            addReply(c,shared.outofrangeerr);
        } else {
            // 删除现有的值
            o->ptr = ziplistDelete(o->ptr,&p);
            // 插入新值到指定索引
            value = getDecodedObject(value);
            o->ptr = ziplistInsert(o->ptr,p,value->ptr,sdslen(value->ptr));
            decrRefCount(value);

            addReply(c,shared.ok);
            signalModifiedKey(c->db,c->argv[1]);
            notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"lset",c->argv[1],c->db->id);
            server.dirty++;
        }

    // 设置到双端链表
    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {

        listNode *ln = listIndex(o->ptr,index);

        if (ln == NULL) {
            addReply(c,shared.outofrangeerr);
        } else {
            // 删除旧值对象
            decrRefCount((robj*)listNodeValue(ln));
            // 指向新对象
            listNodeValue(ln) = value;
            incrRefCount(value);

            addReply(c,shared.ok);
            signalModifiedKey(c->db,c->argv[1]);
            notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"lset",c->argv[1],c->db->id);
            server.dirty++;
        }
    } else {
        redisPanic("Unknown list encoding");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0xcae9d(%rip), %rax     # 0x114150
movq 0x78(%rax), %rdx
callq 0x3c110
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x492de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x492e3
jmp 0x49590
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, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x4932b
jmp 0x49590
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x47cc0
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x49486
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %esi
callq 0x32e50
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4938f
movq -0x8(%rbp), %rdi
leaq 0xcadd2(%rip), %rax     # 0x114150
movq 0x90(%rax), %rsi
callq 0x35a70
jmp 0x49481
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x33700
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x3aef0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x47c80
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl %eax, %ecx
callq 0x336c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x3aaa0
movq -0x8(%rbp), %rdi
leaq 0xcad39(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
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 0x94f0f(%rip), %rsi     # 0xde36b
callq 0x814a0
leaq 0xca490(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xca47e(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
jmp 0x49590
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4956c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x20530
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x494d3
movq -0x8(%rbp), %rdi
leaq 0xcac8e(%rip), %rax     # 0x114150
movq 0x90(%rax), %rsi
callq 0x35a70
jmp 0x4956a
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3aaa0
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rdi
callq 0x3a3f0
movq -0x8(%rbp), %rdi
leaq 0xcac50(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
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 0x94e26(%rip), %rsi     # 0xde36b
callq 0x814a0
leaq 0xca3a7(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xca395(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
jmp 0x4958e
leaq 0x995d9(%rip), %rdi     # 0xe2b4c
leaq 0x99ab7(%rip), %rsi     # 0xe3031
movl $0x2f9, %edx            # imm = 0x2F9
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x49590
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)