// File: stetre[P]moonvulkan/src/command_pool.c
// Function: Create
static int Create(lua_State *L)
    {
    int err;
    ud_t *ud, *device_ud;
    VkResult ec;
    VkCommandPool command_pool;
    VkCommandPoolCreateInfo* info;
    const VkAllocationCallbacks *allocator = NULL;

    VkDevice device = checkdevice(L, 1, &device_ud);

#define CLEANUP zfreeVkCommandPoolCreateInfo(L, info, 1)
    if(lua_istable(L, 2))
        {
        allocator = optallocator(L, 3);
        info = zcheckVkCommandPoolCreateInfo(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        VkFlags flags = checkflags(L, 2);
        uint32_t queueFamilyIndex = luaL_checkinteger(L, 3);
        info = znewVkCommandPoolCreateInfo(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        info->flags = flags;
        info->queueFamilyIndex = queueFamilyIndex;
        }

    ec = device_ud->ddt->CreateCommandPool(device, info, allocator, &command_pool);
    CLEANUP;
    CheckError(L, ec);
#undef CLEANUP
    TRACE_CREATE(command_pool, "command_pool");
    ud = newuserdata_nondispatchable(L, command_pool, COMMAND_POOL_MT);
    ud->parent_ud = device_ud;
    ud->device = device;
    ud->instance = device_ud->instance;
    ud->allocator = allocator;
    ud->destructor = freecommand_pool;
    ud->ddt = device_ud->ddt;
    return 1;
    }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
leaq 0x40(%rsp), %rdx
leaq 0xabb23(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x235bf
movq 0x58(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movl $0x2, %esi
leaq 0x54(%rsp), %rdx
callq 0x194d0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x235ba
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x64(%rsp)
jmp 0x23759
jmp 0x23649
movq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x14(%rsp)
movq 0x58(%rsp), %rdi
movl $0x3, %esi
callq 0x19190
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movl $0x27, %esi
movl $0x18, %edx
leaq 0x54(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x23631
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x58(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x64(%rsp)
jmp 0x23759
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movl 0x10(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x14(%rax)
movq 0x40(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x220(%rax), %rax
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq *%rax
movl %eax, 0x3c(%rsp)
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpl $0x0, 0x3c(%rsp)
je 0x236b1
movq 0x58(%rsp), %rdi
movl 0x3c(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x58(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x64(%rsp)
jmp 0x23759
jmp 0x236b3
jmp 0x236b5
movq 0xd98dc(%rip), %rax     # 0xfcf98
cmpl $0x0, (%rax)
je 0x236d4
movq 0x30(%rsp), %rsi
leaq 0xaccdf(%rip), %rdi     # 0xd03ac
movb $0x0, %al
callq 0x189d0
jmp 0x236d6
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0xacc11(%rip), %rdx     # 0xd02f8
xorl %ecx, %ecx
callq 0x18350
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x48(%rsp), %rax
leaq 0x1d5(%rip), %rcx       # 0x23910
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rax
movq 0x50(%rax), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x50(%rax)
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)