// File: /workspace/github_c_makefile_star2_O1/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
movl $0x40, %esi
callq 0x13a00
testq %rax, %rax
je 0x6259d
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 0x12f00
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x625ff
testq %r12, %r12
cmovneq %r12, %rax
movq %rax, 0x20(%r14)
movq 0x26bc5(%rip), %rcx     # 0x89148
testq %rcx, %rcx
je 0x625a6
cmpq %rax, 0x20(%rcx)
ja 0x62598
jae 0x62837
addq $0x8, %rcx
movq (%rcx), %rcx
jmp 0x62583
leaq 0x12082(%rip), %rsi     # 0x74626
jmp 0x62611
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x12d70
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x12780
movl %eax, 0x28(%r14)
movq 0x26b7d(%rip), %rcx     # 0x89148
testq %rcx, %rcx
je 0x62623
movq 0x20(%r14), %rdx
movq %rcx, %rax
movq 0x20(%rcx), %rsi
cmpq %rsi, %rdx
jb 0x625ea
jbe 0x6280b
leaq 0x8(%rax), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x625d4
xorl %ecx, %ecx
cmpq %rsi, %rdx
setae %cl
shll $0x3, %ecx
jmp 0x6262a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x130d0
leaq 0x1202c(%rip), %rsi     # 0x7463d
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x139b0
jmp 0x62859
movl $0x8, %ecx
xorl %eax, %eax
movq %rax, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x1, 0x18(%r14)
testq %rax, %rax
je 0x627f6
movq %r14, (%rax,%rcx)
leaq 0x26af7(%rip), %rcx     # 0x89148
xorl %edx, %edx
movq %r14, %rdi
cmpl $0x1, 0x18(%rax)
jne 0x627fd
movq 0x10(%rax), %rsi
movq (%rsi), %r8
cmpq %r8, %rax
je 0x62688
testq %r8, %r8
je 0x62678
cmpl $0x1, 0x18(%r8)
je 0x62698
movq (%rax), %r8
cmpq %rdi, %r8
je 0x626c6
movq %rax, %r8
movq %rdi, %rax
jmp 0x62706
movq 0x8(%rsi), %r8
testq %r8, %r8
je 0x626ae
cmpl $0x1, 0x18(%r8)
jne 0x626ae
movl %edx, 0x18(%r8)
movl %edx, 0x18(%rax)
movl $0x1, 0x18(%rsi)
movq %rsi, %rax
jmp 0x627e4
movq 0x8(%rax), %r8
cmpq %rdi, %r8
je 0x62756
movq %rax, %r8
movq %rdi, %rax
jmp 0x62795
movq 0x8(%r8), %r9
movq %r9, (%rax)
testq %r9, %r9
je 0x626d6
movq %rax, 0x10(%r9)
movq 0x10(%rax), %r10
movq %r10, 0x10(%r8)
movq %rcx, %r9
testq %r10, %r10
je 0x626f8
movq 0x10(%rax), %r9
xorl %r10d, %r10d
cmpq (%r9), %rax
setne %r10b
leaq (%r9,%r10,8), %r9
movq %r8, (%r9)
movq %rax, 0x8(%r8)
movq %r8, 0x10(%rax)
movq %rdi, %r8
movl $0x0, 0x18(%r8)
movl $0x1, 0x18(%rsi)
movq 0x8(%rsi), %rdi
movq (%rdi), %r8
movq %r8, 0x8(%rsi)
testq %r8, %r8
je 0x62729
movq %rsi, 0x10(%r8)
movq 0x10(%rsi), %r9
movq %r9, 0x10(%rdi)
movq %rcx, %r8
testq %r9, %r9
je 0x6274b
movq 0x10(%rsi), %r8
xorl %r9d, %r9d
cmpq (%r8), %rsi
setne %r9b
leaq (%r8,%r9,8), %r8
movq %rdi, (%r8)
movq %rsi, (%rdi)
jmp 0x627e0
movq (%r8), %r9
movq %r9, 0x8(%rax)
testq %r9, %r9
je 0x62766
movq %rax, 0x10(%r9)
movq 0x10(%rax), %r10
movq %r10, 0x10(%r8)
movq %rcx, %r9
testq %r10, %r10
je 0x62788
movq 0x10(%rax), %r9
xorl %r10d, %r10d
cmpq (%r9), %rax
setne %r10b
leaq (%r9,%r10,8), %r9
movq %r8, (%r9)
movq %rax, (%r8)
movq %r8, 0x10(%rax)
movq %rdi, %r8
movl $0x0, 0x18(%r8)
movl $0x1, 0x18(%rsi)
movq (%rsi), %rdi
movq 0x8(%rdi), %r8
movq %r8, (%rsi)
testq %r8, %r8
je 0x627b7
movq %rsi, 0x10(%r8)
movq 0x10(%rsi), %r9
movq %r9, 0x10(%rdi)
movq %rcx, %r8
testq %r9, %r9
je 0x627d9
movq 0x10(%rsi), %r8
xorl %r9d, %r9d
cmpq (%r8), %rsi
setne %r9b
leaq (%r8,%r9,8), %r8
movq %rdi, (%r8)
movq %rsi, 0x8(%rdi)
movq %rdi, 0x10(%rsi)
movq %rax, %rdi
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x62656
jmp 0x627fd
movq %r14, 0x2694b(%rip)     # 0x89148
movq 0x26944(%rip), %rax     # 0x89148
movl $0x0, 0x18(%rax)
testq %r15, %r15
je 0x62831
movq %r15, 0x38(%r14)
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
movq %r15, %rdx
callq 0x14050
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x12f40
movq 0x30(%r14), %r14
jmp 0x62859
movq %rbx, %rdi
movq %r14, %rsi
callq 0x130d0
leaq 0x11e0a(%rip), %rsi     # 0x74653
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x139b0
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq