// File: /workspace/github_cpp_makefile_star2_O2/stetre[P]moonvulkan/src/command_buffer.c
// Function: Create
static int Create(lua_State *L)
    {
    int err;
    ud_t *ud, *command_pool_ud;
    VkResult ec;
    uint32_t i, count;
    VkCommandBuffer *command_buffer;
    VkCommandBufferAllocateInfo* info;
    VkCommandPool command_pool = checkcommand_pool(L, 1, &command_pool_ud);

#define CLEANUP zfreeVkCommandBufferAllocateInfo(L, info, 1)
    if(lua_istable(L, 2))
        {
        info = zcheckVkCommandBufferAllocateInfo(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        VkCommandBufferLevel level = checkcommandbufferlevel(L, 2);
        uint32_t commandBufferCount = luaL_checkinteger(L, 3);
        info = znewVkCommandBufferAllocateInfo(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        info->level = level;
        info->commandBufferCount = commandBufferCount;
        }

    info->commandPool = command_pool;
    count = info->commandBufferCount;
    if(count == 0) { CLEANUP; return luaL_error(L, "invalid count"); }

    command_buffer = (VkCommandBuffer*)MallocNoErr(L, sizeof(VkCommandBuffer)*count);
    if(!command_buffer) { CLEANUP; return errmemory(L); }

    ec = command_pool_ud->ddt->AllocateCommandBuffers(command_pool_ud->device, info, command_buffer);
    CLEANUP;
#undef CLEANUP
    if(ec) { Free(L, command_buffer); CheckError(L, ec); return 0; }

    lua_newtable(L);
    for(i=0; i<count; i++)
        {
        TRACE_CREATE(command_buffer[i], "command_buffer");
        ud = newuserdata_dispatchable(L, command_buffer[i], COMMAND_BUFFER_MT);
        ud->parent_ud = command_pool_ud;
        ud->device = command_pool_ud->device;
        ud->instance = command_pool_ud->instance;
        ud->destructor = freecommand_buffer;
        ud->ddt = command_pool_ud->ddt;
        lua_rawseti(L, -2, i+1);
        }
    return 1;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x5e191(%rip), %rcx     # 0x7e2f8
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %rdx
callq 0x1a500
movq %rax, %r14
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x1a110
cmpl $0x5, %eax
jne 0x201d2
pushq $0x2
popq %rsi
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x19db0
movq %rax, %r15
cmpl $0x0, (%r12)
je 0x20220
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19150
pushq $-0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x18680
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x18420
jmp 0x202e2
pushq $0x1f
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x19c00
movl %eax, %ebp
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x190d0
movq %rax, %r12
pushq $0x28
popq %rsi
pushq $0x20
popq %rdx
leaq 0xc(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rcx
callq 0x19dc0
movq %rax, %r15
cmpl $0x0, (%r13)
je 0x20226
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19150
jmp 0x2029b
movl 0x1c(%r15), %r12d
jmp 0x2022e
movl %ebp, 0x18(%r15)
movl %r12d, 0x1c(%r15)
movq %r14, 0x10(%r15)
testl %r12d, %r12d
je 0x202a5
movl %r12d, %r12d
leaq (,%r12,8), %rsi
movq %rbx, %rdi
callq 0x18050
testq %rax, %rax
je 0x202bf
movq %rax, %r14
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x50(%rax), %rax
movq %r15, %rsi
movq %r14, %rdx
callq *0x238(%rax)
movl %eax, %r13d
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x19150
movq %rbx, %rdi
testl %r13d, %r13d
je 0x202f5
movq %r14, %rsi
callq 0x182e0
movq %rbx, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199c0
jmp 0x202e2
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19150
leaq 0x5e056(%rip), %rsi     # 0x7e310
movq %rbx, %rdi
jmp 0x202db
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19150
pushq $-0x6
popq %rdi
callq 0x19950
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x19bc0
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
negq %r12
pushq $0x1
popq %r15
pushq $-0x2
popq %r13
leaq (%r12,%r15), %rax
cmpq $0x1, %rax
je 0x202e4
movq 0x9ac7e(%rip), %rax     # 0xbaf98
cmpl $0x0, (%rax)
je 0x20332
movq -0x8(%r14,%r15,8), %rsi
leaq 0x5dff3(%rip), %rdi     # 0x7e31e
xorl %eax, %eax
callq 0x18960
movq -0x8(%r14,%r15,8), %rsi
movq %rbx, %rdi
leaq 0x5d5c8(%rip), %rdx     # 0x7d909
movl %ebp, %ecx
callq 0x18330
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movups 0x18(%rcx), %xmm0
movups %xmm0, 0x18(%rax)
leaq 0x30f(%rip), %rdx       # 0x2066f
movq %rdx, 0x8(%rax)
movq 0x50(%rcx), %rcx
movq %rcx, 0x50(%rax)
movq %rbx, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x19120
incq %r15
jmp 0x20309