// File: /workspace/github_c_makefile_star2_O0/stetre[P]moonsndfile/src/structs.c
// Function: moonsndfile_checkchunk
chunknode_t *checkchunk(lua_State *L, int arg)
    {
    const char *id;
    const char *data;
    size_t id_size, datalen;
    chunknode_t *p;
    if(lua_isnoneornil(L, arg))
        { luaL_argerror(L, arg, errstring(ERR_NOTPRESENT)); return NULL; }
    if(lua_type(L, arg) != LUA_TTABLE)
        { luaL_argerror(L, arg, errstring(ERR_TABLE)); return NULL; }

    lua_getfield(L, arg, "id");
    id = luaL_checklstring(L, -1, &id_size);
    if(!id || id_size == 0 || id_size > 64)
        { lua_pop(L, 1); luaL_argerror(L, arg, "missing or invalid 'id' field"); return NULL; }
    lua_pop(L, 1);
    
    lua_getfield(L, arg, "data");
    data = luaL_optlstring(L, -1, NULL, &datalen);
    lua_pop(L, 1);
    
    p = (chunknode_t*)Malloc(L, sizeof(chunknode_t));
    if(id) memcpy(p->chunk.id, id, id_size);
    if(data && datalen > 0)
        {
        p->chunk.data = MallocNoErr(L, datalen);
        if(!p->chunk.data)
            { 
            freechunk(L, p);
            luaL_argerror(L, arg, errstring(ERR_MEMORY)); 
            return NULL;
            }
        memcpy(p->chunk.data, data, datalen);
        }
    return p;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movl %esi, 0x64(%rsp)
movq 0x68(%rsp), %rdi
movl 0x64(%rsp), %esi
callq 0x4730
cmpl $0x0, %eax
jg 0xf0fb
movq 0x68(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x34(%rsp)
movl $0x1, %edi
callq 0x4660
movq 0x28(%rsp), %rdi
movl 0x34(%rsp), %esi
movq %rax, %rdx
callq 0x4100
movq $0x0, 0x70(%rsp)
jmp 0xf2ed
movq 0x68(%rsp), %rdi
movl 0x64(%rsp), %esi
callq 0x4730
cmpl $0x5, %eax
je 0xf149
movq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x24(%rsp)
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0x4660
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %esi
movq %rax, %rdx
callq 0x4100
movq $0x0, 0x70(%rsp)
jmp 0xf2ed
movq 0x68(%rsp), %rdi
movl 0x64(%rsp), %esi
leaq 0x384b(%rip), %rdx      # 0x129a4
callq 0x47e0
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rdx
callq 0x4380
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0xf18f
cmpq $0x0, 0x48(%rsp)
je 0xf18f
cmpq $0x40, 0x48(%rsp)
jbe 0xf1c1
movq 0x68(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq 0x68(%rsp), %rdi
movl 0x64(%rsp), %esi
leaq 0x44f2(%rip), %rdx      # 0x136a0
callq 0x4100
movq $0x0, 0x70(%rsp)
jmp 0xf2ed
movq 0x68(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq 0x68(%rsp), %rdi
movl 0x64(%rsp), %esi
leaq 0x412d(%rip), %rdx      # 0x1330d
callq 0x47e0
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
leaq 0x40(%rsp), %rcx
callq 0x4270
movq %rax, 0x50(%rsp)
movq 0x68(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq 0x68(%rsp), %rdi
movl $0x58, %esi
callq 0x41d0
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0xf245
movq 0x38(%rsp), %rdi
addq $0x8, %rdi
movq 0x58(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x44b0
cmpq $0x0, 0x50(%rsp)
je 0xf2e3
cmpq $0x0, 0x40(%rsp)
jbe 0xf2e3
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x4390
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x50(%rax)
movq 0x38(%rsp), %rax
cmpq $0x0, 0x50(%rax)
jne 0xf2cb
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x4240
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x14(%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x4660
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %esi
movq %rax, %rdx
callq 0x4100
movq $0x0, 0x70(%rsp)
jmp 0xf2ed
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x50(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x44b0
movq 0x38(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
addq $0x78, %rsp
retq
nopw (%rax,%rax)