// File: stetre[P]moonvulkan/src/utils.c
// Function: moonvulkan_checkdevicesizelist
VkDeviceSize* checkdevicesizelist(lua_State *L, int arg, uint32_t *count, int *err)
    {
    const char *s;
    VkDeviceSize* list;
    uint32_t i;

    *count = 0;
    *err = 0;
    if(lua_isnoneornil(L, arg))
        { *err = ERR_NOTPRESENT; return NULL; }
    if(lua_type(L, arg) != LUA_TTABLE)
        { *err = ERR_TABLE; return NULL; }

    *count = luaL_len(L, arg);
    if(*count == 0)
        { *err = ERR_EMPTY; return NULL; }

    list = (VkDeviceSize*)MallocNoErr(L, sizeof(VkDeviceSize) * (*count));
    if(!list)
        { *count = 0; *err = ERR_MEMORY; return NULL; }

    for(i=0; i<*count; i++)
        {
        lua_rawgeti(L, arg, i+1);
        if(lua_type(L, -1) == LUA_TSTRING)
            {
            s = lua_tostring(L, -1);
            if(strcmp(s, "whole size") == 0)
                list[i] = VK_WHOLE_SIZE;
            else *err = ERR_VALUE;
            }
        else if(lua_isinteger(L, -1))
            list[i] = lua_tointeger(L, -1);
        else
            *err = ERR_TYPE;
        lua_pop(L, 1);
        if(*err)
            { Free(L, list); *count = 0; return NULL; }
        }
    return list;
    }

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movl %esi, 0x34(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
movq 0x20(%rsp), %rax
movl $0x0, (%rax)
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x1a240
cmpl $0x0, %eax
jg 0x69299
movq 0x20(%rsp), %rax
movl $0x1, (%rax)
movq $0x0, 0x40(%rsp)
jmp 0x6947b
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x1a240
cmpl $0x5, %eax
je 0x692c5
movq 0x20(%rsp), %rax
movl $0xfffffffc, (%rax)     # imm = 0xFFFFFFFC
movq $0x0, 0x40(%rsp)
jmp 0x6947b
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x1a270
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x692ff
movq 0x20(%rsp), %rax
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
movq $0x0, 0x40(%rsp)
jmp 0x6947b
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x18050
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x69347
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
movq 0x20(%rsp), %rax
movl $0xfffffffa, (%rax)     # imm = 0xFFFFFFFA
movq $0x0, 0x40(%rsp)
jmp 0x6947b
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x69471
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x189e0
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1a240
cmpl $0x4, %eax
jne 0x693db
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x7a7a5(%rip), %rsi     # 0xe3b56
callq 0x190a0
cmpl $0x0, %eax
jne 0x693ce
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
movq $-0x1, (%rax,%rcx,8)
jmp 0x693d9
movq 0x20(%rsp), %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
jmp 0x69421
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1a720
cmpl $0x0, %eax
je 0x69414
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x18690
movq %rax, %rdx
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x6941f
movq 0x20(%rsp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
jmp 0x69421
movq 0x38(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
movq 0x20(%rsp), %rax
cmpl $0x0, (%rax)
je 0x6945f
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x18300
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
movq $0x0, 0x40(%rsp)
jmp 0x6947b
jmp 0x69461
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x6934f
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)