// File: stetre[P]moonvulkan/src/descriptor_set_layout.c
// Function: Create
static int Create(lua_State *L)
    {
    ud_t *ud;
    int err;
    VkResult ec;
    VkDescriptorSetLayout descriptor_set_layout;
    VkDescriptorSetLayoutCreateInfo *info;
    VkDevice device = checkdevice(L, 1, NULL);
    const VkAllocationCallbacks *allocator = NULL;

#define CLEANUP zfreeVkDescriptorSetLayoutCreateInfo(L, info, 1)
    if(lua_istable(L, 2))
        {
        allocator = optallocator(L, 3);
        info = zcheckVkDescriptorSetLayoutCreateInfo(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        info = znewVkDescriptorSetLayoutCreateInfo(L, &err);
        info->flags = optflags(L, 2, 0);
        info->pBindings = zcheckarrayVkDescriptorSetLayoutBinding(L, 3, &info->bindingCount, &err);
        if(err < 0) { CLEANUP; return argerror(L, 3); }
        if(err == ERR_NOTPRESENT) lua_pop(L, 1);
        }

    ec = UD(device)->ddt->CreateDescriptorSetLayout(device, info, allocator, &descriptor_set_layout);
    CLEANUP;
#undef CLEANUP
    CheckError(L, ec);
    TRACE_CREATE(descriptor_set_layout, "descriptor_set_layout");
    ud = newuserdata_nondispatchable(L, descriptor_set_layout, DESCRIPTOR_SET_LAYOUT_MT);
    ud->parent_ud = UD(device);
    ud->device = device;
    ud->instance = UD(device)->instance;
    ud->allocator = allocator;
    ud->destructor = freedescriptor_set_layout;
    ud->ddt = UD(device)->ddt;
    return 1;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xa6b3d(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x285ae
movq 0x48(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
leaq 0x3c(%rsp), %rdx
callq 0x198c0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x3c(%rsp)
je 0x285a9
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x54(%rsp)
jmp 0x287a4
jmp 0x2867d
movq 0x48(%rsp), %rdi
movl $0x20, %esi
movl $0x20, %edx
leaq 0x3c(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x19370
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rdx
addq $0x14, %rdx
movl $0x3, %esi
leaq 0x3c(%rsp), %rcx
callq 0x1a130
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rax)
cmpl $0x0, 0x3c(%rsp)
jge 0x28665
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x3, %esi
callq 0x18460
movl %eax, 0x54(%rsp)
jmp 0x287a4
cmpl $0x1, 0x3c(%rsp)
jne 0x2867b
movq 0x48(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
jmp 0x2867d
movq 0x20(%rsp), %rdi
callq 0x19fd0
movq 0x50(%rax), %rax
movq 0x1b8(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq *%rax
movl %eax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpl $0x0, 0x38(%rsp)
je 0x286ea
movq 0x48(%rsp), %rdi
movl 0x38(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x287a4
jmp 0x286ec
jmp 0x286ee
movq 0xd48a3(%rip), %rax     # 0xfcf98
cmpl $0x0, (%rax)
je 0x2870d
movq 0x30(%rsp), %rsi
leaq 0xa8574(%rip), %rdi     # 0xd0c7a
movb $0x0, %al
callq 0x189d0
jmp 0x2870f
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0xa849c(%rip), %rdx     # 0xd0bbc
xorl %ecx, %ecx
callq 0x18350
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rdi
callq 0x19fd0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x20(%rsp), %rdi
callq 0x19fd0
movq 0x18(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x40(%rsp), %rax
leaq 0x21f(%rip), %rcx       # 0x289a0
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rdi
callq 0x19fd0
movq 0x50(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rax)
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax)