// File: stetre[P]moonvulkan/src/pipeline.c
// Function: CreateGraphics
static int CreateGraphics(lua_State *L)
    {
    int err;
    uint32_t count, i;
    VkResult ec;
    VkPipeline *pipeline;

    VkDevice device = checkdevice(L, 1, NULL);
    VkPipelineCache cache = testpipeline_cache(L, 2, NULL);
    const VkAllocationCallbacks *allocator = optallocator(L, 4);
#define CLEANUP zfreearrayVkGraphicsPipelineCreateInfo(L, info, count, 1)
    VkGraphicsPipelineCreateInfo *info = zcheckarrayVkGraphicsPipelineCreateInfo(L, 3, &count, &err);
    if(err) { CLEANUP; return argerror(L, 3); }

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

    ec = UD(device)->ddt->CreateGraphicsPipelines(device, cache, count, info, allocator, pipeline);
    CLEANUP;
#undef CLEANUP
    if(ec)
        {
        Free(L, pipeline);
        CheckError(L, ec);
        }
    lua_newtable(L);
    for(i = 0; i < count; i++)
        {
        newpipeline(L, pipeline[i], device, allocator);
        lua_rawseti(L, -2, i+1);
        }
    Free(L, pipeline);
    return 1;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0x7139d(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0x73277(%rip), %rcx     # 0xd0f34
callq 0x1a5f0
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rdi
movl $0x4, %esi
callq 0x19260
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x3, %esi
leaq 0x40(%rsp), %rdx
leaq 0x44(%rsp), %rcx
callq 0x19150
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x5dd56
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x90, %edx
movl $0x1, %r8d
callq 0x198d0
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 0x5ded8
movq 0x48(%rsp), %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x18050
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x5ddbf
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x90, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19a60
movq (%rsp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x54(%rsp)
jmp 0x5ded8
movq 0x28(%rsp), %rdi
callq 0x19fd0
movq 0x50(%rax), %rax
movq 0x180(%rax), %rax
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x40(%rsp), %edx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x30(%rsp), %r9
callq *%rax
movl %eax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x40(%rsp), %ecx
movl $0x90, %edx
movl $0x1, %r8d
callq 0x198d0
cmpl $0x0, 0x38(%rsp)
je 0x5de59
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
cmpl $0x0, 0x38(%rsp)
je 0x5de55
movq 0x48(%rsp), %rdi
movl 0x38(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5ded8
jmp 0x5de57
jmp 0x5de59
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0x5dec1
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rax
movl 0x3c(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movq 0x28(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x5ecc0
movq 0x48(%rsp), %rdi
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x5de6f
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x18300
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)