// File: /workspace/github_c_makefile_star2_O3/stetre[P]moonassimp/src/udata.c
// Function: moonassimp_udata_new
void *udata_new(lua_State *L, size_t size, const void *ptr, const char *mt)
/* 
 * Creates a new Lua userdata, optionally sets its metatable to mt (if != NULL),
 * associates the userdata with the passed ptr and pushes the userdata on the stack.
 *
 * The userdata can be subsquently pushed on the Lua stack with udata_push(L, ptr).
 * (This is useful to bind C/C++ objects to Lua userdata).
 *
 * If ptr=NULL, the pointer to the memory area allocated by Lua is used as ptr
 * (this function returnes it).
 */
    {
    udata_t *udata;
//  printf("new object %p\n", ptr);
    if((udata = (udata_t*)malloc(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(udata);
        luaL_error(L, "lua_newuserdata error"); 
        return NULL;
        }
    udata->id = ptr!=NULL ? (uintptr_t)ptr : (uintptr_t)(udata->mem);
    if(udata_search(udata->id))
        { 
        free(udata);
        luaL_error(L, "duplicated object %p", ptr); 
        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)
        {
        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 $0x1, %edi
movl $0x38, %esi
callq 0x6400
testq %rax, %rax
je 0xe1bc
movq %rax, %r14
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6430
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0xe3fc
testq %r12, %r12
cmovneq %r12, %rax
movq %rax, 0x20(%r14)
movq 0xa36e(%rip), %rcx      # 0x18510
testq %rcx, %rcx
je 0xe1c8
cmpq %rax, 0x20(%rcx)
ja 0xe1b7
jae 0xe46a
addq $0x8, %rcx
movq (%rcx), %rcx
jmp 0xe1a2
leaq 0x349d(%rip), %rsi      # 0x11660
jmp 0xe40b
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x63c0
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6240
movl %eax, 0x28(%r14)
movq 0xa323(%rip), %rsi      # 0x18510
testq %rsi, %rsi
je 0xe41a
movq 0x20(%r14), %rcx
movq %rsi, %rax
movq 0x20(%rsi), %rdx
cmpq %rdx, %rcx
jb 0xe210
jbe 0xe442
leaq 0x8(%rax), %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
jne 0xe1fa
xorl %esi, %esi
cmpq %rdx, %rcx
setae %sil
movq %rax, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl $0x1, 0x18(%r14)
movq %r14, (%rax,%rsi,8)
leaq 0xa2d1(%rip), %rcx      # 0x18510
xorl %edx, %edx
movq %r14, %rdi
cmpl $0x1, 0x18(%rax)
jne 0xe3f3
movq 0x10(%rax), %rsi
movq (%rsi), %r8
cmpq %r8, %rax
je 0xe27f
testq %r8, %r8
je 0xe26c
cmpl $0x1, 0x18(%r8)
jne 0xe26c
movl %edx, 0x18(%r8)
jmp 0xe293
movq (%rax), %r8
cmpq %rdi, %r8
je 0xe2b9
movq %rax, %r8
movq %rdi, %rax
jmp 0xe328
movq 0x8(%rsi), %r9
testq %r9, %r9
je 0xe2a5
cmpl $0x1, 0x18(%r9)
jne 0xe2a5
movl %edx, 0x18(%r9)
movl %edx, 0x18(%rax)
movl $0x1, 0x18(%rsi)
movq %rsi, %rax
jmp 0xe3e3
movq 0x8(%rax), %r9
cmpq %rdi, %r9
je 0xe2db
movq %rax, %r9
movq %rdi, %rax
jmp 0xe39b
movq 0x8(%r8), %r9
movq %r9, (%rax)
testq %r9, %r9
je 0xe304
movq %rax, 0x10(%r9)
movq 0x10(%rax), %r9
movq %r9, 0x10(%r8)
movq %rcx, %r10
testq %r9, %r9
jne 0xe30c
jmp 0xe31a
movq (%r9), %r8
movq %r8, 0x8(%rax)
testq %r8, %r8
je 0xe375
movq %rax, 0x10(%r8)
movq 0x10(%rax), %r8
movq %r8, 0x10(%r9)
movq %rcx, %r10
testq %r8, %r8
jne 0xe37d
jmp 0xe38b
movq %rsi, 0x10(%r8)
movq 0x10(%rax), %r9
xorl %r10d, %r10d
cmpq (%r9), %rax
setne %r10b
leaq (%r9,%r10,8), %r10
movq %r8, (%r10)
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 0xe34b
movq %rsi, 0x10(%r8)
movq 0x10(%rsi), %r8
movq %r8, 0x10(%rdi)
movq %rcx, %r9
testq %r8, %r8
je 0xe369
xorl %r9d, %r9d
cmpq (%r8), %rsi
setne %r9b
leaq (%r8,%r9,8), %r9
movq %rdi, (%r9)
movq %rsi, (%rdi)
movq %rdi, 0x10(%rsi)
jmp 0xe3e3
movq %rsi, 0x10(%r9)
movq 0x10(%rax), %r8
xorl %r10d, %r10d
cmpq (%r8), %rax
setne %r10b
leaq (%r8,%r10,8), %r10
movq %r9, (%r10)
movq %rax, (%r9)
movq %r9, 0x10(%rax)
movq (%rsi), %r8
movq %rdi, %r9
movl $0x0, 0x18(%r9)
movl $0x1, 0x18(%rsi)
movq 0x8(%r8), %rdi
movq %rdi, (%rsi)
testq %rdi, %rdi
je 0xe3ba
movq %rsi, 0x10(%rdi)
movq 0x10(%rsi), %rdi
movq %rdi, 0x10(%r8)
movq %rcx, %r9
testq %rdi, %rdi
je 0xe3d8
xorl %r9d, %r9d
cmpq (%rdi), %rsi
setne %r9b
leaq (%rdi,%r9,8), %r9
movq %r8, (%r9)
movq %rsi, 0x8(%r8)
movq %r8, 0x10(%rsi)
movq %rax, %rdi
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0xe244
movq 0xa116(%rip), %rax      # 0x18510
jmp 0xe43b
movq %r14, %rdi
callq 0x60a0
leaq 0x326c(%rip), %rsi      # 0x11677
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x67a0
jmp 0xe489
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movl $0x1, 0x18(%r14)
movq %r14, 0xa0d8(%rip)      # 0x18510
movq %r14, %rax
movl $0x0, 0x18(%rax)
testq %r15, %r15
je 0xe464
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
movq %r15, %rdx
callq 0x6960
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6450
movq 0x30(%r14), %r14
jmp 0xe489
movq %r14, %rdi
callq 0x60a0
leaq 0x3214(%rip), %rsi      # 0x1168d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x67a0
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq