// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movl $0x38, %edi
callq 0x65a0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
jne 0x122ae
movq 0x28(%rsp), %rdi
leaq 0x53c7(%rip), %rsi      # 0x17660
movb $0x0, %al
callq 0x67b0
movq $0x0, 0x30(%rsp)
jmp 0x123ea
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x6300
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x6430
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x12311
movq 0x8(%rsp), %rdi
callq 0x60a0
movq 0x28(%rsp), %rdi
leaq 0x537b(%rip), %rsi      # 0x17677
movb $0x0, %al
callq 0x67b0
movq $0x0, 0x30(%rsp)
jmp 0x123ea
cmpq $0x0, 0x18(%rsp)
je 0x12324
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
jmp 0x12331
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 0x12400
cmpq $0x0, %rax
je 0x1237f
movq 0x8(%rsp), %rdi
callq 0x60a0
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rdx
leaq 0x5320(%rip), %rsi      # 0x1768d
movb $0x0, %al
callq 0x67b0
movq $0x0, 0x30(%rsp)
jmp 0x123ea
movq 0x28(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x63d0
movq 0x28(%rsp), %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6240
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x8(%rsp), %rdi
callq 0x12430
cmpq $0x0, 0x10(%rsp)
je 0x123dc
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rdx
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x6970
movq 0x28(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x6450
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)