// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_string.c
// Function: getrangeCommand
void getrangeCommand(redisClient *c) {
    robj *o;
    long start, end;
    char *str, llbuf[32];
    size_t strlen;

    // 取出 start 参数
    if (getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK)
        return;

    // 取出 end 参数
    if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK)
        return;

    // 从数据库中查找键 c->argv[1] 
    if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL ||
        checkType(c,o,REDIS_STRING)) return;

    // 根据编码，对对象的值进行处理
    if (o->encoding == REDIS_ENCODING_INT) {
        str = llbuf;
        strlen = ll2string(llbuf,sizeof(llbuf),(long)o->ptr);
    } else {
        str = o->ptr;
        strlen = sdslen(str);
    }

    /* Convert negative indexes */
    // 将负数索引转换为整数索引
    if (start < 0) start = strlen+start;
    if (end < 0) end = strlen+end;
    if (start < 0) start = 0;
    if (end < 0) end = 0;
    if ((unsigned)end >= strlen) end = strlen-1;

    /* Precondition: end >= 0 && end < strlen, so the only condition where
     * nothing can be returned is: start > end. */
    if (start > end) {
        // 处理索引范围为空的情况
        addReply(c,shared.emptybulk);
    } else {
        // 向客户端返回给定范围内的字符串内容
        addReplyBulkCBuffer(c,(char*)str+start,end-start+1);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%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 0x47133
jmp 0x47286
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x4715a
jmp 0x47286
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0xccfdf(%rip), %rax     # 0x114150
movq 0x18(%rax), %rdx
callq 0x3c0c0
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x47198
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x4719d
jmp 0x47286
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x471d4
leaq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x20, %esi
callq 0x39660
cltq
movq %rax, -0x58(%rbp)
jmp 0x471ed
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x46650
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x18(%rbp)
jge 0x47200
movq -0x58(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x47213
movq -0x58(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jge 0x47222
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x47231
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %eax
cmpq -0x58(%rbp), %rax
jb 0x47249
movq -0x58(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x47269
movq -0x8(%rbp), %rdi
leaq 0xccef2(%rip), %rax     # 0x114150
movq 0x18(%rax), %rsi
callq 0x35a70
jmp 0x47286
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
subq -0x18(%rbp), %rdx
addq $0x1, %rdx
callq 0x36670
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)