// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/scripting.c
// Function: luaCreateFunction
int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) {
    sds funcdef = sdsempty();

    funcdef = sdscat(funcdef,"function ");
    funcdef = sdscatlen(funcdef,funcname,42);
    funcdef = sdscatlen(funcdef,"() ",3);
    funcdef = sdscatlen(funcdef,body->ptr,sdslen(body->ptr));
    funcdef = sdscatlen(funcdef,"\nend",4);

    if (luaL_loadbuffer(lua,funcdef,sdslen(funcdef),"@user_script")) {
        addReplyErrorFormat(c,"Error compiling script (new function): %s\n",
            lua_tostring(lua,-1));
        lua_pop(lua,1);
        sdsfree(funcdef);
        return C_ERR;
    }
    sdsfree(funcdef);
    if (lua_pcall(lua,0,0,0)) {
        addReplyErrorFormat(c,"Error running script (new function): %s\n",
            lua_tostring(lua,-1));
        lua_pop(lua,1);
        return C_ERR;
    }

    /* We also save a SHA1 -> Original script map in a dictionary
     * so that we can replicate / write in the AOF all the
     * EVALSHA commands as EVAL using the original script. */
    {
        int retval = dictAdd(server.lua_scripts,
                             sdsnewlen(funcname+2,40),body);
        serverAssertWithInfo(c,NULL,retval == DICT_OK);
        incrRefCount(body);
    }
    return C_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
callq 0x384f0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xb962f(%rip), %rsi     # 0x14413b
callq 0x390d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x2a, %edx
callq 0x39040
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xb960f(%rip), %rsi     # 0x144145
movl $0x3, %edx
callq 0x39040
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x895c0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x39040
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0xb95c5(%rip), %rsi     # 0x144149
movl $0x4, %edx
callq 0x39040
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x895c0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rax, %rdx
leaq 0xb9591(%rip), %rcx     # 0x14414e
callq 0xc18f0
cmpl $0x0, %eax
je 0x8ac19
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0xacf60
movq -0x60(%rbp), %rdi
movq %rax, %rdx
leaq 0xb956c(%rip), %rsi     # 0x14415b
movb $0x0, %al
callq 0x42fd0
movq -0x18(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0xac570
movq -0x30(%rbp), %rdi
callq 0x38620
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8acf6
movq -0x30(%rbp), %rdi
callq 0x38620
movq -0x18(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0xae1c0
cmpl $0x0, %eax
je 0x8ac7c
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0xacf60
movq -0x68(%rbp), %rdi
movq %rax, %rdx
leaq 0xb9528(%rip), %rsi     # 0x144186
movb $0x0, %al
callq 0x42fd0
movq -0x18(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0xac570
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8acf6
leaq 0xed555(%rip), %rax     # 0x1781d8
movq 0x9e0(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
addq $0x2, %rdi
movl $0x28, %esi
callq 0x38230
movq -0x70(%rbp), %rdi
movq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x2d8c0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x8acbb
jmp 0x8ace6
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0xb0bc2(%rip), %rdx     # 0x13b88c
leaq 0xb94de(%rip), %rcx     # 0x1441af
movl $0x497, %r8d            # imm = 0x497
callq 0x78360
movl $0x1, %edi
callq 0x263c0
movq -0x28(%rbp), %rdi
callq 0x487b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop