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

    robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);

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

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

    // 根据索引，遍历 ziplist ，直到指定位置
    if (o->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *p;
        unsigned char *vstr;
        unsigned int vlen;
        long long vlong;

        p = ziplistIndex(o->ptr,index);

        if (ziplistGet(p,&vstr,&vlen,&vlong)) {
            if (vstr) {
                value = createStringObject((char*)vstr,vlen);
            } else {
                value = createStringObjectFromLongLong(vlong);
            }
            addReplyBulk(c,value);
            decrRefCount(value);
        } else {
            addReply(c,shared.nullbulk);
        }

    // 根据索引，遍历双端链表，直到指定位置
    } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {

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

        if (ln != NULL) {
            value = listNodeValue(ln);
            addReplyBulk(c,value);
        } else {
            addReply(c,shared.nullbulk);
        }
    } 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 0xcb04d(%rip), %rax     # 0x114150
movq 0x50(%rax), %rdx
callq 0x3c0c0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x4912e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x49133
jmp 0x49283
movq $0x0, -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 0x49162
jmp 0x49283
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x49201
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movl %eax, %esi
callq 0x32e50
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x34(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x33490
cmpl $0x0, %eax
je 0x491e8
cmpq $0x0, -0x30(%rbp)
je 0x491c3
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0x3a2e0
movq %rax, -0x20(%rbp)
jmp 0x491d0
movq -0x40(%rbp), %rdi
callq 0x3a330
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x36620
movq -0x20(%rbp), %rdi
callq 0x3aaa0
jmp 0x491fc
movq -0x8(%rbp), %rdi
leaq 0xcaf5d(%rip), %rax     # 0x114150
movq 0x50(%rax), %rsi
callq 0x35a70
jmp 0x49283
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4925f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x20530
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x49249
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x36620
jmp 0x4925d
movq -0x8(%rbp), %rdi
leaq 0xcaefc(%rip), %rax     # 0x114150
movq 0x50(%rax), %rsi
callq 0x35a70
jmp 0x49281
leaq 0x998e6(%rip), %rdi     # 0xe2b4c
leaq 0x99dc4(%rip), %rsi     # 0xe3031
movl $0x2ba, %edx            # imm = 0x2BA
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x49283
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)