// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/slowlog.c
// Function: slowlogCommand
void slowlogCommand(redisClient *c) {

    // 重置
    if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"reset")) {
        slowlogReset();
        addReply(c,shared.ok);

    // 返回长度
    } else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"len")) {
        addReplyLongLong(c,listLength(server.slowlog));

    // 获取某条或者全部日志
    } else if ((c->argc == 2 || c->argc == 3) &&
               !strcasecmp(c->argv[1]->ptr,"get"))
    {
        long count = 10, sent = 0;
        listIter li;
        void *totentries;
        listNode *ln;
        slowlogEntry *se;

        if (c->argc == 3 &&
            getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != REDIS_OK)
            return;

        // 遍历日志，取出指定数量的日志
        listRewind(server.slowlog,&li);
        totentries = addDeferredMultiBulkLength(c);
        while(count-- && (ln = listNext(&li))) {
            int j;

            se = ln->value;
            addReplyMultiBulkLen(c,4);
            addReplyLongLong(c,se->id);
            addReplyLongLong(c,se->time);
            addReplyLongLong(c,se->duration);
            addReplyMultiBulkLen(c,se->argc);
            for (j = 0; j < se->argc; j++)
                addReplyBulk(c,se->argv[j]);
            sent++;
        }
        setDeferredMultiBulkLength(c,totentries,sent);
    } else {
        addReplyError(c,
            "Unknown SLOWLOG subcommand or wrong # of args. Try GET, RESET, LEN.");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x30(%rdi), %ebp
cmpl $0x2, %ebp
jne 0x56957
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x4662a(%rip), %rsi     # 0x9cf53
callq 0x1f2e0
testl %eax, %eax
je 0x5699a
cmpl $0x2, %ebp
jne 0x56957
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x435ab(%rip), %rsi     # 0x99ef5
callq 0x1f2e0
testl %eax, %eax
je 0x56a18
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x5697d
movq 0x38(%rbx), %r14
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
leaq 0x3daf3(%rip), %rsi     # 0x94467
callq 0x1f2e0
testl %eax, %eax
je 0x569c0
leaq 0x46be9(%rip), %rsi     # 0x9d56d
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d9d7
callq 0x568da
leaq 0x73e5a(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d6f0
movq $0xa, (%rsp)
cmpl $0x3, %ebp
jne 0x569e6
movq 0x10(%r14), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x310df
testl %eax, %eax
jne 0x56ad3
leaq 0x735bb(%rip), %rax     # 0xc9fa8
movq 0x3a8(%rax), %rdi
leaq 0x8(%rsp), %rsi
callq 0x205d2
movq %rbx, %rdi
callq 0x2dc0a
movq %rax, %r14
subq $0x1, (%rsp)
jae 0x56a40
xorl %r15d, %r15d
jmp 0x56ac5
leaq 0x73589(%rip), %rax     # 0xc9fa8
movq 0x3a8(%rax), %rax
movq 0x28(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dea3
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x205ef
testq %rax, %rax
je 0x56ac5
movq 0x10(%rax), %r13
movl $0x4, %esi
movq %rbx, %rdi
callq 0x2ded8
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0x2dea3
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x2dea3
movq 0x18(%r13), %rsi
movq %rbx, %rdi
callq 0x2dea3
movslq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0x2ded8
cmpl $0x0, 0x8(%r13)
jle 0x56abb
xorl %ebp, %ebp
movq (%r13), %rax
movq (%rax,%rbp,8), %rsi
movq %rbx, %rdi
callq 0x2df74
incq %rbp
movslq 0x8(%r13), %rax
cmpq %rax, %rbp
jl 0x56a9f
incq %r15
subq $0x1, (%rsp)
jae 0x56a48
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2dc46
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop