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

#define CLEANUP zfreeVkPipelineLayoutCreateInfo(L, info, 1)
    if(lua_istable(L, 2))
        {
        allocator = optallocator(L, 3);
        info = zcheckVkPipelineLayoutCreateInfo(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        VkFlags flags = checkflags(L, 2);
        info = znewVkPipelineLayoutCreateInfo(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        info->flags = flags;
        info->pSetLayouts = checkdescriptor_set_layoutlist(L, 3, &info->setLayoutCount, &err, NULL);
        if(err<0) { CLEANUP; return argerror(L, 3); }
        info->pPushConstantRanges = zcheckarrayVkPushConstantRange(L, 4,
                                        &info->pushConstantRangeCount, &err);
        if(err<0) { CLEANUP; return argerror(L, 3); }
        else if(err == ERR_NOTPRESENT) lua_pop(L, 1);
        }
    ec = device_ud->ddt->CreatePipelineLayout(device, info, allocator, &pipeline_layout);
    CLEANUP;
    CheckError(L, ec);
#undef CLEANUP
    TRACE_CREATE(pipeline_layout, "pipeline_layout");
    ud = newuserdata_nondispatchable(L, pipeline_layout, PIPELINE_LAYOUT_MT);
    ud->parent_ud = device_ud;
    ud->device = device;
    ud->instance = device_ud->instance;
    ud->allocator = allocator;
    ud->destructor = freepipeline_layout;
    ud->ddt = device_ud->ddt;
    return 1;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1, %esi
leaq 0x50(%rsp), %rdx
leaq 0x6f73c(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x5f9af
movq 0x68(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x64(%rsp), %rdx
callq 0x1a3b0
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x5f9aa
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x5fc48
jmp 0x5fb38
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x24(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1e, %esi
movl $0x30, %edx
leaq 0x64(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x5fa0e
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x5fc48
movl 0x24(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rdx
addq $0x14, %rdx
movl $0x3, %esi
leaq 0x64(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq 0x7117e(%rip), %r9      # 0xd0bbc
callq 0x191f0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
cmpl $0x0, 0x64(%rsp)
jge 0x5faa2
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movl $0x3, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x5fc48
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rdx
addq $0x20, %rdx
movl $0x4, %esi
leaq 0x64(%rsp), %rcx
callq 0x18d70
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x28(%rax)
cmpl $0x0, 0x64(%rsp)
jge 0x5fb1e
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%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, 0x74(%rsp)
jmp 0x5fc48
cmpl $0x1, 0x64(%rsp)
jne 0x5fb34
movq 0x68(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
jmp 0x5fb36
jmp 0x5fb38
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x198(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq *%rax
movl %eax, 0x4c(%rsp)
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpl $0x0, 0x4c(%rsp)
je 0x5fba0
movq 0x68(%rsp), %rdi
movl 0x4c(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x5fc48
jmp 0x5fba2
jmp 0x5fba4
movq 0x9d3ed(%rip), %rax     # 0xfcf98
cmpl $0x0, (%rax)
je 0x5fbc3
movq 0x40(%rsp), %rsi
leaq 0x831f1(%rip), %rdi     # 0xe2dad
movb $0x0, %al
callq 0x189d0
jmp 0x5fbc5
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x6fd61(%rip), %rdx     # 0xcf937
xorl %ecx, %ecx
callq 0x18350
movq %rax, 0x58(%rsp)
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x30(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x58(%rsp), %rax
leaq 0x76(%rip), %rcx        # 0x5fca0
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x50(%rax)
movl $0x1, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)