// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/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.*/
        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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
callq 0xc19f0
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x8a245
leaq 0xedfd7(%rip), %rax     # 0x1781d8
movq $0x0, 0x9d0(%rax)
leaq 0xedfc5(%rip), %rax     # 0x1781d8
movq $0x0, 0x9d8(%rax)
leaq 0xedfb3(%rip), %rax     # 0x1781d8
movl $0x0, 0xa0c(%rax)
leaq 0xedfa2(%rip), %rax     # 0x1781d8
movl $0x0, 0xa14(%rax)
callq 0x8a780
movq -0x10(%rbp), %rdi
callq 0x89ce0
movq -0x10(%rbp), %rdi
callq 0x89dd0
leaq 0xecbe2(%rip), %rdi     # 0x176e40
xorl %eax, %eax
movl %eax, %esi
callq 0x2d330
movq %rax, %rcx
leaq 0xedf67(%rip), %rax     # 0x1781d8
movq %rcx, 0x9e0(%rax)
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xad9e0
movq -0x10(%rbp), %rdi
leaq 0xc18dd(%rip), %rsi     # 0x14bb6d
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xb80(%rip), %rsi      # 0x89720
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xc09ef(%rip), %rsi     # 0x14acaf
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xb90(%rip), %rsi      # 0x89740
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb4046(%rip), %rsi     # 0x13e336
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0x7d0(%rip), %rsi      # 0x89b30
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9bcb(%rip), %rsi     # 0x143eeb
callq 0xad410
movq -0x10(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9bab(%rip), %rsi     # 0x143ef5
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xad10d(%rip), %xmm0    # 0x137468
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9b88(%rip), %rsi     # 0x143f01
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xb94c6(%rip), %xmm0    # 0x143850
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9b64(%rip), %rsi     # 0x143f0c
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xb948f(%rip), %xmm0    # 0x143848
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9b41(%rip), %rsi     # 0x143f18
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xc87(%rip), %rsi      # 0x89760
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9b19(%rip), %rsi     # 0x143f20
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xba7(%rip), %rsi      # 0x89870
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9af5(%rip), %rsi     # 0x143f2c
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xba7(%rip), %rsi      # 0x898a0
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9ad2(%rip), %rsi     # 0x143f39
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xba7(%rip), %rsi      # 0x898d0
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9ab5(%rip), %rsi     # 0x143f4c
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xa47(%rip), %rsi      # 0x89a60
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9a8e(%rip), %rsi     # 0x143f55
callq 0xad410
movq -0x10(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9a6e(%rip), %rsi     # 0x143f5f
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xacf66(%rip), %xmm0    # 0x137468
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9a48(%rip), %rsi     # 0x143f68
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xb931f(%rip), %xmm0    # 0x143850
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb9a24(%rip), %rsi     # 0x143f73
callq 0xad410
movq -0x10(%rbp), %rdi
movsd 0xb92e8(%rip), %xmm0    # 0x143848
callq 0xad2f0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb99fe(%rip), %rsi     # 0x143f7c
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xc5e(%rip), %rsi      # 0x89930
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xc3537(%rip), %rsi     # 0x14dae5
callq 0xad410
movq -0x10(%rbp), %rdi
leaq -0xc3e(%rip), %rsi      # 0x89980
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0xada55(%rip), %rdx     # 0x138038
callq 0xadca0
movq -0x10(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0xb96aa(%rip), %rdx     # 0x143ca2
callq 0xad850
movq -0x10(%rbp), %rdi
leaq 0xb3be2(%rip), %rsi     # 0x13e1ea
callq 0xad410
movq -0x10(%rbp), %rdi
leaq 0x1d8(%rip), %rsi       # 0x8a7f0
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
leaq 0xb994f(%rip), %rsi     # 0x143f87
callq 0xad410
movq -0x10(%rbp), %rdi
leaq 0x368(%rip), %rsi       # 0x8a9b0
xorl %edx, %edx
callq 0xad5a0
movq -0x10(%rbp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0xadc40
movq -0x10(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0xb9635(%rip), %rdx     # 0x143ca2
callq 0xadca0
leaq 0xb9919(%rip), %rax     # 0x143f92
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x264f0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rax, %rdx
leaq 0xb9962(%rip), %rcx     # 0x14400a
callq 0xc18f0
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0xae1c0
leaq 0xb9955(%rip), %rax     # 0x144018
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x264f0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq %rax, %rdx
leaq 0xb9a26(%rip), %rcx     # 0x144118
callq 0xc18f0
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0xae1c0
leaq 0xedacb(%rip), %rax     # 0x1781d8
cmpq $0x0, 0x9d0(%rax)
jne 0x8a752
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x41d90
movq %rax, %rcx
leaq 0xedaad(%rip), %rax     # 0x1781d8
movq %rcx, 0x9d0(%rax)
leaq 0xeda9f(%rip), %rax     # 0x1781d8
movq 0x9d0(%rax), %rax
movl 0x98(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x98(%rax)
movq -0x10(%rbp), %rdi
callq 0x89e20
movq -0x10(%rbp), %rcx
leaq 0xeda72(%rip), %rax     # 0x1781d8
movq %rcx, 0x9c8(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)