// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/scripting.c
// Function: scriptingInit
void scriptingInit(int setup) {
    lua_State *lua = lua_open();

    if (setup) {
        server.lua_client = NULL;
        server.lua_caller = NULL;
        server.lua_timedout = 0;
        server.lua_always_replicate_commands = 0; /* Only DEBUG can change it.*/
        server.lua_time_limit = LUA_SCRIPT_TIME_LIMIT;
        ldbInit();
    }

    luaLoadLibraries(lua);
    luaRemoveUnsupportedFunctions(lua);

    /* Initialize a dictionary we use to map SHAs to scripts.
     * This is useful for replication, as we need to replicate EVALSHA
     * as EVAL, so we need to remember the associated script. */
    server.lua_scripts = dictCreate(&shaScriptObjectDictType,NULL);

    /* Register the redis commands table and fields */
    lua_newtable(lua);

    /* redis.call */
    lua_pushstring(lua,"call");
    lua_pushcfunction(lua,luaRedisCallCommand);
    lua_settable(lua,-3);

    /* redis.pcall */
    lua_pushstring(lua,"pcall");
    lua_pushcfunction(lua,luaRedisPCallCommand);
    lua_settable(lua,-3);

    /* redis.log and log levels. */
    lua_pushstring(lua,"log");
    lua_pushcfunction(lua,luaLogCommand);
    lua_settable(lua,-3);

    lua_pushstring(lua,"LOG_DEBUG");
    lua_pushnumber(lua,LL_DEBUG);
    lua_settable(lua,-3);

    lua_pushstring(lua,"LOG_VERBOSE");
    lua_pushnumber(lua,LL_VERBOSE);
    lua_settable(lua,-3);

    lua_pushstring(lua,"LOG_NOTICE");
    lua_pushnumber(lua,LL_NOTICE);
    lua_settable(lua,-3);

    lua_pushstring(lua,"LOG_WARNING");
    lua_pushnumber(lua,LL_WARNING);
    lua_settable(lua,-3);

    /* redis.sha1hex */
    lua_pushstring(lua, "sha1hex");
    lua_pushcfunction(lua, luaRedisSha1hexCommand);
    lua_settable(lua, -3);

    /* redis.error_reply and redis.status_reply */
    lua_pushstring(lua, "error_reply");
    lua_pushcfunction(lua, luaRedisErrorReplyCommand);
    lua_settable(lua, -3);
    lua_pushstring(lua, "status_reply");
    lua_pushcfunction(lua, luaRedisStatusReplyCommand);
    lua_settable(lua, -3);

    /* redis.replicate_commands */
    lua_pushstring(lua, "replicate_commands");
    lua_pushcfunction(lua, luaRedisReplicateCommandsCommand);
    lua_settable(lua, -3);

    /* redis.set_repl and associated flags. */
    lua_pushstring(lua,"set_repl");
    lua_pushcfunction(lua,luaRedisSetReplCommand);
    lua_settable(lua,-3);

    lua_pushstring(lua,"REPL_NONE");
    lua_pushnumber(lua,PROPAGATE_NONE);
    lua_settable(lua,-3);

    lua_pushstring(lua,"REPL_AOF");
    lua_pushnumber(lua,PROPAGATE_AOF);
    lua_settable(lua,-3);

    lua_pushstring(lua,"REPL_SLAVE");
    lua_pushnumber(lua,PROPAGATE_REPL);
    lua_settable(lua,-3);

    lua_pushstring(lua,"REPL_ALL");
    lua_pushnumber(lua,PROPAGATE_AOF|PROPAGATE_REPL);
    lua_settable(lua,-3);

    /* redis.breakpoint */
    lua_pushstring(lua,"breakpoint");
    lua_pushcfunction(lua,luaRedisBreakpointCommand);
    lua_settable(lua,-3);

    /* redis.debug */
    lua_pushstring(lua,"debug");
    lua_pushcfunction(lua,luaRedisDebugCommand);
    lua_settable(lua,-3);

    /* Finally set the table as 'redis' global var. */
    lua_setglobal(lua,"redis");

    /* Replace math.random and math.randomseed with our implementations. */
    lua_getglobal(lua,"math");

    lua_pushstring(lua,"random");
    lua_pushcfunction(lua,redis_math_random);
    lua_settable(lua,-3);

    lua_pushstring(lua,"randomseed");
    lua_pushcfunction(lua,redis_math_randomseed);
    lua_settable(lua,-3);

    lua_setglobal(lua,"math");

    /* Add a helper function that we use to sort the multi bulk output of non
     * deterministic commands, when containing 'false' elements. */
    {
        char *compare_func =    "function __redis__compare_helper(a,b)\n"
                                "  if a == false then a = '' end\n"
                                "  if b == false then b = '' end\n"
                                "  return a<b\n"
                                "end\n";
        luaL_loadbuffer(lua,compare_func,strlen(compare_func),"@cmp_func_def");
        lua_pcall(lua,0,0,0);
    }

    /* Add a helper function we use for pcall error reporting.
     * Note that when the error is in the C function we want to report the
     * information about the caller, that's what makes sense from the point
     * of view of the user debugging a script. */
    {
        char *errh_func =       "local dbg = debug\n"
                                "function __redis__err__handler(err)\n"
                                "  local i = dbg.getinfo(2,'nSl')\n"
                                "  if i and i.what == 'C' then\n"
                                "    i = dbg.getinfo(3,'nSl')\n"
                                "  end\n"
                                "  if i then\n"
                                "    return i.source .. ':' .. i.currentline .. ': ' .. err\n"
                                "  else\n"
                                "    return err\n"
                                "  end\n"
                                "end\n";
        luaL_loadbuffer(lua,errh_func,strlen(errh_func),"@err_handler_def");
        lua_pcall(lua,0,0,0);
    }

    /* Create the (non connected) client that we use to execute Redis commands
     * inside the Lua interpreter.
     * Note: there is no need to create it again when this function is called
     * by scriptingReset(). */
    if (server.lua_client == NULL) {
        server.lua_client = createClient(-1);
        server.lua_client->flags |= CLIENT_LUA;
    }

    /* Lua beginners often don't use "local", this is likely to introduce
     * subtle bugs in their code. To prevent problems we protect accesses
     * to global variables. */
    scriptingEnableGlobalsProtection(lua);

    server.lua = lua;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebp
callq 0x95606
movq %rax, %rbx
testl %ebp, %ebp
je 0x7283e
leaq 0x94042(%rip), %rax     # 0x106858
xorl %ecx, %ecx
movl %ecx, 0x9fc(%rax)
movl %ecx, 0xa04(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x9c0(%rax)
movq $0x1388, 0x9d8(%rax) # imm = 0x1388
callq 0x72cb1
movq %rbx, %rdi
callq 0x7254b
movq %rbx, %rdi
callq 0x72613
leaq 0x9354b(%rip), %rdi     # 0x105da0
xorl %esi, %esi
callq 0x31774
leaq 0x93ff5(%rip), %r15     # 0x106858
movq %rax, 0x9d0(%r15)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8a31b
leaq 0x6226d(%rip), %rsi     # 0xd4aea
movq %rbx, %rdi
callq 0x8a02b
leaq -0x708(%rip), %rsi      # 0x72184
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x614f5(%rip), %rsi     # 0xd3d9f
movq %rbx, %rdi
callq 0x8a02b
leaq -0x72b(%rip), %rsi      # 0x7218e
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x54547(%rip), %rsi     # 0xc6e1e
movq %rbx, %rdi
callq 0x8a02b
leaq -0x4db(%rip), %rsi      # 0x7240b
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a62f(%rip), %rsi     # 0xccf33
movq %rbx, %rdi
callq 0x8a02b
xorps %xmm0, %xmm0
movq %rbx, %rdi
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a612(%rip), %rsi     # 0xccf3d
movq %rbx, %rdi
callq 0x8a02b
movsd 0x5109d(%rip), %xmm0    # 0xc39d8
movq %rbx, %rdi
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a5f2(%rip), %rsi     # 0xccf49
movq %rbx, %rdi
callq 0x8a02b
movsd 0x59f29(%rip), %xmm0    # 0xcc890
movq %rbx, %rdi
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a5d1(%rip), %rsi     # 0xccf54
movq %rbx, %rdi
callq 0x8a02b
movsd 0x59f05(%rip), %xmm0    # 0xcc898
movq %rbx, %rdi
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a5b1(%rip), %rsi     # 0xccf60
movq %rbx, %rdi
callq 0x8a02b
leaq -0x829(%rip), %rsi      # 0x72195
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a58c(%rip), %rsi     # 0xccf68
movq %rbx, %rdi
callq 0x8a02b
leaq -0x76f(%rip), %rsi      # 0x7227c
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a56b(%rip), %rsi     # 0xccf74
movq %rbx, %rdi
callq 0x8a02b
leaq -0x788(%rip), %rsi      # 0x72290
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a54b(%rip), %rsi     # 0xccf81
movq %rbx, %rdi
callq 0x8a02b
leaq -0x7a1(%rip), %rsi      # 0x722a4
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a531(%rip), %rsi     # 0xccf94
movq %rbx, %rdi
callq 0x8a02b
leaq -0x6e0(%rip), %rsi      # 0x72392
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a50d(%rip), %rsi     # 0xccf9d
movq %rbx, %rdi
callq 0x8a02b
xorps %xmm0, %xmm0
movq %rbx, %rdi
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a4f0(%rip), %rsi     # 0xccfa7
movq %rbx, %rdi
callq 0x8a02b
movq %rbx, %rdi
movsd 0x50f0e(%rip), %xmm0    # 0xc39d8
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a4cd(%rip), %rsi     # 0xccfb0
movq %rbx, %rdi
callq 0x8a02b
movq %rbx, %rdi
movsd 0x59d9a(%rip), %xmm0    # 0xcc890
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a4ac(%rip), %rsi     # 0xccfbb
movq %rbx, %rdi
callq 0x8a02b
movq %rbx, %rdi
movsd 0x59d76(%rip), %xmm0    # 0xcc898
callq 0x89fa5
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a489(%rip), %rsi     # 0xccfc4
movq %rbx, %rdi
callq 0x8a02b
leaq -0x866(%rip), %rsi      # 0x722e4
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x64870(%rip), %rsi     # 0xd73d8
movq %rbx, %rdi
callq 0x8a02b
leaq -0x86a(%rip), %rsi      # 0x7230d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x4d4c1(%rip), %rdx     # 0xc0056
movq %rbx, %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
callq 0x8a43e
leaq 0x5a141(%rip), %r14     # 0xcccea
movq %rbx, %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
movq %r14, %rdx
callq 0x8a262
leaq 0x54112(%rip), %rsi     # 0xc6cd2
movq %rbx, %rdi
callq 0x8a02b
leaq 0x135(%rip), %rsi       # 0x72d04
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
leaq 0x5a3e2(%rip), %rsi     # 0xccfcf
movq %rbx, %rdi
callq 0x8a02b
leaq 0x249(%rip), %rsi       # 0x72e45
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8a159
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x8a417
movq %rbx, %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
movq %r14, %rdx
callq 0x8a43e
leaq 0x5a3b0(%rip), %rsi     # 0xccfda
leaq 0x5a421(%rip), %rcx     # 0xcd052
movl $0x77, %edx
movq %rbx, %rdi
callq 0x9558c
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8a6ac
leaq 0x5a40d(%rip), %rsi     # 0xcd060
leaq 0x5a506(%rip), %rcx     # 0xcd160
movl $0xff, %edx
movq %rbx, %rdi
callq 0x9558c
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8a6ac
cmpq $0x0, 0x9c0(%r15)
jne 0x72c97
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3f180
movq %rax, 0x9c0(%r15)
orb $0x1, 0x99(%rax)
movq %rbx, %rdi
callq 0x7264d
movq %rbx, 0x9b8(%r15)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq