// File: /workspace/github_c_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
pushq $0x40
popq %rsi
callq 0x13c00
testq %rax, %rax
je 0x5b6b3
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x13030
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x5b6bc
testq %r12, %r12
cmovneq %r12, %rax
movq %rax, 0x20(%r14)
movq %rax, %rdi
callq 0x5b952
testq %rax, %rax
je 0x5b6e8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13220
leaq 0x10ef2(%rip), %rsi     # 0x6c593
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x13bb0
jmp 0x5b6db
leaq 0x10eac(%rip), %rsi     # 0x6c566
jmp 0x5b6ce
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13220
leaq 0x10eaf(%rip), %rsi     # 0x6c57d
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x13bb0
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x12e90
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x12800
movl %eax, 0x28(%r14)
leaq 0x2ab85(%rip), %rdx     # 0x86290
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rdx), %rsi
testq %rsi, %rsi
je 0x5b739
movq 0x20(%rsi), %rcx
movq %rsi, %rdx
movq %rsi, %rax
cmpq %rcx, 0x20(%r14)
setb %cl
jb 0x5b70f
jbe 0x5b925
leaq 0x8(%rsi), %rdx
movq %rsi, %rax
jmp 0x5b70f
movq %rax, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x1, 0x18(%r14)
notb %cl
movzbl %cl, %ecx
andl $0x1, %ecx
testq %rax, %rax
leaq (%rax,%rcx,8), %rdx
leaq 0x2ab2e(%rip), %rcx     # 0x86290
cmoveq %rcx, %rdx
movq %r14, (%rdx)
movq %r14, %rsi
testq %rax, %rax
je 0x5b91a
cmpl $0x1, 0x18(%rax)
jne 0x5b91a
movq 0x10(%rax), %rdx
movq (%rdx), %rdi
cmpq %rdi, %rax
je 0x5b7af
testq %rdi, %rdi
je 0x5b79c
cmpl $0x1, 0x18(%rdi)
jne 0x5b79c
andl $0x0, 0x18(%rdi)
jmp 0x5b7c4
movq (%rax), %rdi
cmpq %rsi, %rdi
je 0x5b7eb
movq %rax, %rdi
movq %rsi, %rax
jmp 0x5b85a
movq 0x8(%rdx), %r8
testq %r8, %r8
je 0x5b7d7
cmpl $0x1, 0x18(%r8)
jne 0x5b7d7
andl $0x0, 0x18(%r8)
andl $0x0, 0x18(%rax)
movl $0x1, 0x18(%rdx)
movq %rdx, %rax
jmp 0x5b90e
movq 0x8(%rax), %r8
cmpq %rsi, %r8
je 0x5b80d
movq %rax, %r8
movq %rsi, %rax
jmp 0x5b8c9
movq 0x8(%rdi), %r8
movq %r8, (%rax)
testq %r8, %r8
je 0x5b836
movq %rax, 0x10(%r8)
movq 0x10(%rax), %r8
movq %r8, 0x10(%rdi)
movq %rcx, %r9
testq %r8, %r8
jne 0x5b83e
jmp 0x5b84c
movq (%r8), %rdi
movq %rdi, 0x8(%rax)
testq %rdi, %rdi
je 0x5b8a3
movq %rax, 0x10(%rdi)
movq 0x10(%rax), %rdi
movq %rdi, 0x10(%r8)
movq %rcx, %r9
testq %rdi, %rdi
jne 0x5b8ab
jmp 0x5b8b9
movq %rdx, 0x10(%rdi)
movq 0x10(%rax), %r8
xorl %r9d, %r9d
cmpq (%r8), %rax
setne %r9b
leaq (%r8,%r9,8), %r9
movq %rdi, (%r9)
movq %rax, 0x8(%rdi)
movq %rdi, 0x10(%rax)
movq %rsi, %rdi
andl $0x0, 0x18(%rdi)
movl $0x1, 0x18(%rdx)
movq 0x8(%rdx), %rsi
movq (%rsi), %rdi
movq %rdi, 0x8(%rdx)
testq %rdi, %rdi
je 0x5b879
movq %rdx, 0x10(%rdi)
movq 0x10(%rdx), %rdi
movq %rdi, 0x10(%rsi)
movq %rcx, %r8
testq %rdi, %rdi
je 0x5b897
xorl %r8d, %r8d
cmpq (%rdi), %rdx
setne %r8b
leaq (%rdi,%r8,8), %r8
movq %rsi, (%r8)
movq %rdx, (%rsi)
movq %rsi, 0x10(%rdx)
jmp 0x5b90e
movq %rdx, 0x10(%r8)
movq 0x10(%rax), %rdi
xorl %r9d, %r9d
cmpq (%rdi), %rax
setne %r9b
leaq (%rdi,%r9,8), %r9
movq %r8, (%r9)
movq %rax, (%r8)
movq %r8, 0x10(%rax)
movq (%rdx), %rdi
movq %rsi, %r8
andl $0x0, 0x18(%r8)
movl $0x1, 0x18(%rdx)
movq 0x8(%rdi), %rsi
movq %rsi, (%rdx)
testq %rsi, %rsi
je 0x5b8e5
movq %rdx, 0x10(%rsi)
movq 0x10(%rdx), %rsi
movq %rsi, 0x10(%rdi)
movq %rcx, %r8
testq %rsi, %rsi
je 0x5b903
xorl %r8d, %r8d
cmpq (%rsi), %rdx
setne %r8b
leaq (%rsi,%r8,8), %r8
movq %rdi, (%r8)
movq %rdx, 0x8(%rdi)
movq %rdi, 0x10(%rdx)
movq %rax, %rsi
movq 0x10(%rax), %rax
jmp 0x5b76c
movq 0x2a96f(%rip), %rax     # 0x86290
andl $0x0, 0x18(%rax)
testq %r15, %r15
je 0x5b949
movq %r15, 0x38(%r14)
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
movq %r15, %rdx
callq 0x142b0
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0x13070
movq 0x30(%r14), %r14
jmp 0x5b6db