// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x45204(%rip), %rcx     # 0x8f03b
leaq 0x10(%rsp), %rdx
movl $0x1, %esi
callq 0x1a520
movq %rax, %r14
movq %rbx, %rdi
movl $0x2, %esi
callq 0x1a130
movq %rbx, %rdi
cmpl $0x5, %eax
jne 0x49ec2
movl $0x3, %esi
callq 0x191c0
movq %rax, %r12
leaq 0x4(%rsp), %r13
movq %rbx, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x1a290
movq %rax, %r15
cmpl $0x0, (%r13)
je 0x49fc2
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x19170
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x18690
movq %rbx, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0x18420
jmp 0x4a071
movl $0x2, %esi
callq 0x18f70
movq %rax, %r12
leaq 0x4(%rsp), %r13
movl $0x30, %edx
movq %rbx, %rdi
movl $0x1e, %esi
movq %r13, %rcx
callq 0x19de0
movq %rax, %r15
cmpl $0x0, (%r13)
je 0x49f13
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x19170
movq %rbx, %rdi
callq 0x199e0
xorl %r12d, %r12d
jmp 0x49fb6
movl %r12d, 0x10(%r15)
leaq 0x14(%r15), %rdx
leaq 0x46ce2(%rip), %r9      # 0x90c04
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movl $0x3, %esi
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x19150
movq %rax, 0x18(%r15)
cmpl $0x0, (%r12)
js 0x49f84
movq %r15, %rdx
addq $0x20, %rdx
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movl $0x4, %esi
movq %r12, %rcx
callq 0x18cf0
movq %rax, 0x28(%r15)
movl (%r12), %eax
testl %eax, %eax
js 0x49f84
movb $0x1, %r12b
cmpl $0x1, %eax
jne 0x49f82
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18150
jmp 0x49fb6
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x19170
xorl %r12d, %r12d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x18690
movq %rbx, %rdi
movl $0x3, %esi
movq %rax, %rdx
callq 0x18420
testb %r12b, %r12b
je 0x4a071
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x198(%rax)
movl %eax, %ebp
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x19170
testl %ebp, %ebp
je 0x4a00b
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18990
movq %rbx, %rdi
callq 0x199e0
jmp 0x4a071
movq 0x78fb6(%rip), %rax     # 0xc2fc8
cmpl $0x0, (%rax)
je 0x4a02a
movq 0x8(%rsp), %rsi
leaq 0x58db8(%rip), %rdi     # 0xa2ddb
xorl %eax, %eax
callq 0x18970
movq 0x8(%rsp), %rsi
leaq 0x45901(%rip), %rdx     # 0x8f937
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x18330
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %r14, 0x20(%rax)
movq 0x18(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq %r12, 0x40(%rax)
leaq 0x4f(%rip), %rdx        # 0x4a0af
movq %rdx, 0x8(%rax)
movq 0x50(%rcx), %rcx
movq %rcx, 0x50(%rax)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq