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

    // SCRIPT FLUSH 命令
    if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"flush")) {
        scriptingReset();
        addReply(c,shared.ok);
        replicationScriptCacheFlush();
        server.dirty++; /* Propagating this command is a good idea. */

    // SCRIPT EXISTS 命令
    } else if (c->argc >= 2 && !strcasecmp(c->argv[1]->ptr,"exists")) {
        int j;

        addReplyMultiBulkLen(c, c->argc-2);
        for (j = 2; j < c->argc; j++) {
            if (dictFind(server.lua_scripts,c->argv[j]->ptr))
                addReply(c,shared.cone);
            else
                addReply(c,shared.czero);
        }

    // SCRIPT LOAD 命令
    } else if (c->argc == 3 && !strcasecmp(c->argv[1]->ptr,"load")) {
        char funcname[43];
        sds sha;

        // 函数名前缀
        funcname[0] = 'f';
        funcname[1] = '_';

        // 计算脚本的 SHA1 值
        sha1hex(funcname+2,c->argv[2]->ptr,sdslen(c->argv[2]->ptr));
        sha = sdsnewlen(funcname+2,40);

        // 根据 SHA1 值，在字典中查找脚本
        // 如果脚本未定义，在 Lua 中创建新函数
        if (dictFind(server.lua_scripts,sha) == NULL) {
            if (luaCreateFunction(c,server.lua,funcname,c->argv[2])
                    == REDIS_ERR) {
                sdsfree(sha);
                return;
            }
        }

        // 返回脚本的 SHA1 值
        addReplyBulkCBuffer(c,funcname+2,40);

        sdsfree(sha);

        forceCommandPropagation(c,REDIS_PROPAGATE_REPL|REDIS_PROPAGATE_AOF);

    // SCRIPT KILL 命令
    } else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"kill")) {
        if (server.lua_caller == NULL) {
            addReplySds(c,sdsnew("-NOTBUSY No scripts in execution right now.\r\n"));
        } else if (server.lua_write_dirty) {
            addReplySds(c,sdsnew("-UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.\r\n"));
        } else {
            server.lua_kill = 1;
            addReply(c,shared.ok);
        }

    } else {
        addReplyError(c, "Unknown SCRIPT subcommand or wrong # of args.");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x7552a
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x729d0(%rip), %rsi     # 0xe7ead
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x7552a
callq 0x74810
movq -0x8(%rbp), %rdi
leaq 0x9ec59(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
callq 0x40020
leaq 0x9e3ec(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0x9e3da(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
jmp 0x757e7
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jl 0x755ef
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x6e9db(%rip), %rsi     # 0xe3f2a
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x755ef
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x2, %eax
movslq %eax, %rsi
callq 0x364f0
movl $0x2, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x755ea
leaq 0x9e36b(%rip), %rax     # 0x1138f8
movq 0x7f8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rsi
callq 0x23aa0
cmpq $0x0, %rax
je 0x755c9
movq -0x8(%rbp), %rdi
leaq 0x9eb92(%rip), %rax     # 0x114150
movq 0x28(%rax), %rsi
callq 0x35a70
jmp 0x755dd
movq -0x8(%rbp), %rdi
leaq 0x9eb7c(%rip), %rax     # 0x114150
movq 0x20(%rax), %rsi
callq 0x35a70
jmp 0x755df
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7557a
jmp 0x757e5
movq -0x8(%rbp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x75710
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x6fbdc(%rip), %rsi     # 0xe51f0
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x75710
movb $0x66, -0x40(%rbp)
movb $0x5f, -0x3f(%rbp)
leaq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x72b70
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x73930
leaq -0x40(%rbp), %rdi
addq $0x2, %rdi
movl $0x28, %esi
callq 0x2c000
movq %rax, -0x48(%rbp)
leaq 0x9e26c(%rip), %rax     # 0x1138f8
movq 0x7f8(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x23aa0
cmpq $0x0, %rax
jne 0x756de
movq -0x8(%rbp), %rdi
leaq 0x9e24b(%rip), %rax     # 0x1138f8
movq 0x7e0(%rax), %rsi
leaq -0x40(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rcx
callq 0x74c30
cmpl $-0x1, %eax
jne 0x756dc
movq -0x48(%rbp), %rdi
callq 0x2c160
jmp 0x757e7
jmp 0x756de
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
addq $0x2, %rsi
movl $0x28, %edx
callq 0x36670
movq -0x48(%rbp), %rdi
callq 0x2c160
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x28850
jmp 0x757e3
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x757d1
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x6bab8(%rip), %rsi     # 0xe11ed
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x757d1
leaq 0x9e1ae(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x7f0(%rax)
jne 0x75776
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x72750(%rip), %rdi     # 0xe7eb3
callq 0x2c0e0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x35c00
jmp 0x757cf
leaq 0x9e17b(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x810(%rax)
je 0x757a8
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq 0x7274c(%rip), %rdi     # 0xe7ee1
callq 0x2c0e0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x35c00
jmp 0x757cd
leaq 0x9e149(%rip), %rax     # 0x1138f8
movl $0x1, 0x81c(%rax)
movq -0x8(%rbp), %rdi
leaq 0x9e98c(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
jmp 0x757cf
jmp 0x757e1
movq -0x8(%rbp), %rdi
leaq 0x727c8(%rip), %rsi     # 0xe7fa4
callq 0x35d40
jmp 0x757e3
jmp 0x757e5
jmp 0x757e7
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)