// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
callq 0x3114c
leaq 0x56f99(%rip), %rsi     # 0xbb04b
movq %rax, %rdi
callq 0x317b7
pushq $0x2a
popq %rdx
movq %rax, %rdi
movq %r12, %rsi
callq 0x31758
leaq 0x56f86(%rip), %rsi     # 0xbb055
pushq $0x3
popq %rdx
movq %rax, %rdi
callq 0x31758
movq %rax, %r13
movq 0x8(%r15), %rbp
movq %rbp, %rdi
callq 0x63370
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x31758
leaq 0x56f5b(%rip), %rsi     # 0xbb059
pushq $0x4
popq %rdx
movq %rax, %rdi
callq 0x31758
movq %rax, %r13
movq %rax, %rdi
callq 0x63370
leaq 0x56f43(%rip), %rcx     # 0xbb05e
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x83534
testl %eax, %eax
je 0x64168
pushq $-0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x788e1
leaq 0x56f28(%rip), %rsi     # 0xbb06b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x36b96
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x78478
movq %r13, %rdi
callq 0x311c8
jmp 0x641eb
movq %r13, %rdi
callq 0x311c8
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x79168
testl %eax, %eax
je 0x641b2
pushq $-0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x788e1
leaq 0x56efe(%rip), %rsi     # 0xbb096
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x36b96
pushq $-0x2
popq %rsi
movq %r14, %rdi
callq 0x78478
jmp 0x641eb
leaq 0x956ef(%rip), %rax     # 0xf98a8
movq 0x9e0(%rax), %r14
addq $0x2, %r12
pushq $0x28
popq %rsi
movq %r12, %rdi
callq 0x31018
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x2a3ed
testl %eax, %eax
jne 0x641fc
movq %r15, %rdi
callq 0x39e74
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e529(%rip), %rdx     # 0xb272c
leaq 0x56eb5(%rip), %rcx     # 0xbb0bf
movq %rbx, %rdi
xorl %esi, %esi
movl $0x497, %r8d            # imm = 0x497
callq 0x588a4
pushq $0x1
popq %rdi
callq 0x263c0