// File: /workspace/github_c_makefile_star2_O0/stetre[P]moonnuklear/src/udata.c
// Function: moonnuklear_udata_new
void *udata_new(lua_State *L, size_t size, uint64_t id_, const char *mt)
/* Creates a new Lua userdata, optionally sets its metatable to mt (if != NULL),
 * associates the userdata with the passed id and pushes the userdata on the stack.
 *
 * The userdata can be subsquently pushed on the Lua stack with udata_push(L, id).
 * (This is useful to bind C/C++ objects to Lua userdata).
 *
 * If id=0, the pointer to the memory area allocated by Lua is used as identifier
 * (this function returnes it).
 */
    {
    udata_t *udata;
    if((udata = (udata_t*)Malloc(L, sizeof(udata_t))) == NULL) 
        { luaL_error(L, "cannot allocate memory"); return NULL; }
    memset(udata, 0, sizeof(udata_t));
    udata->mem = lua_newuserdata(L, size);
    if(!udata->mem)
        {
        Free(L, udata);
        luaL_error(L, "lua_newuserdata error"); 
        return NULL;
        }
    udata->id = id_ != 0 ? id_ : (uint64_t)(uintptr_t)(udata->mem);
    if(udata_search(udata->id))
        { 
        Free(L, udata);
        luaL_error(L, "duplicated object %I", id_); 
        return NULL; 
        }
    /* create a reference for later push's */
    lua_pushvalue(L, -1); /* the newly created userdata */
    udata->ref = luaL_ref(L, LUA_REGISTRYINDEX);
    udata_insert(udata);
    if(mt)
        {
        udata->mt = mt;
        luaL_getmetatable(L, mt);
        lua_setmetatable(L, -2);
        }
    return udata->mem;
    }

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movl $0x40, %esi
callq 0x14c40
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
jne 0x9ef53
movq 0x28(%rsp), %rdi
leaq 0x162e0(%rip), %rsi     # 0xb521e
movb $0x0, %al
callq 0x14bf0
movq $0x0, 0x30(%rsp)
jmp 0x9f0a7
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x13c40
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x14040
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x9efbb
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x14230
movq 0x28(%rsp), %rdi
leaq 0x1628f(%rip), %rsi     # 0xb5235
movb $0x0, %al
callq 0x14bf0
movq $0x0, 0x30(%rsp)
jmp 0x9f0a7
cmpq $0x0, 0x18(%rsp)
je 0x9efce
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
jmp 0x9efdb
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, (%rsp)
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x9f0c0
cmpq $0x0, %rax
je 0x9f02e
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x14230
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rdx
leaq 0x1622f(%rip), %rsi     # 0xb524b
movb $0x0, %al
callq 0x14bf0
movq $0x0, 0x30(%rsp)
jmp 0x9f0a7
movq 0x28(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x13eb0
movq 0x28(%rsp), %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x13840
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x8(%rsp), %rdi
callq 0x9f0f0
cmpq $0x0, 0x10(%rsp)
je 0x9f099
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rdx
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x15310
movq 0x28(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x14080
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)