// File: stetre[P]moonvulkan/src/cmd.c
// Function: CmdWaitEvents1
static int CmdWaitEvents1(lua_State *L)
    {
    int err;
    ud_t *ud;
    uint32_t eventCount, mCount=0, bCount=0, iCount=0;
    VkEvent* pEvents = NULL;
    VkMemoryBarrier* pMemoryBarriers = NULL;
    VkBufferMemoryBarrier* pBufferMemoryBarriers = NULL;
    VkImageMemoryBarrier* pImageMemoryBarriers = NULL;
    VkCommandBuffer cb = checkcommand_buffer(L, 1, &ud);
    VkPipelineStageFlags srcStageMask = checkflags(L, 2);
    VkPipelineStageFlags dstStageMask = checkflags(L, 3);
#define CLEANUP do {                                                        \
    Free(L, pEvents);                                                       \
    zfreearrayVkMemoryBarrier(L, pMemoryBarriers, mCount, 1);               \
    zfreearrayVkBufferMemoryBarrier(L, pBufferMemoryBarriers, bCount, 1);   \
    zfreearrayVkImageMemoryBarrier(L, pImageMemoryBarriers, iCount, 1);     \
} while(0)
    pEvents = checkeventlist(L, 4, &eventCount, &err, NULL);
    if(err) { CLEANUP; return argerrorc(L, 4, err); }

    pMemoryBarriers = zcheckarrayVkMemoryBarrier(L, 5, &mCount, &err);
    if(err < 0) { CLEANUP; return argerror(L, 5); }
    if(err) lua_pop(L, 1);

    pBufferMemoryBarriers = zcheckarrayVkBufferMemoryBarrier(L, 6, &bCount, &err);
    if(err < 0) { CLEANUP; return argerror(L, 6); }
    if(err) lua_pop(L, 1);

    pImageMemoryBarriers = zcheckarrayVkImageMemoryBarrier(L, 7, &iCount, &err);
    if(err < 0) { CLEANUP; return argerror(L, 7); }
    if(err) lua_pop(L, 1);

    ud->ddt->CmdWaitEvents(cb, eventCount, pEvents, srcStageMask, dstStageMask, 
            mCount, pMemoryBarriers, bCount, pBufferMemoryBarriers, 
            iCount, pImageMemoryBarriers);
    CLEANUP;
#undef CLEANUP
    return 0;
    }

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq %rdi, 0xa0(%rsp)
movl $0x0, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movl $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq 0xa0(%rsp), %rdi
movl $0x1, %esi
leaq 0x90(%rsp), %rdx
leaq 0xaddb5(%rip), %rcx     # 0xcf909
callq 0x1a640
movq %rax, 0x58(%rsp)
movq 0xa0(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x54(%rsp)
movq 0xa0(%rsp), %rdi
movl $0x3, %esi
callq 0x19010
movl %eax, 0x50(%rsp)
movq 0xa0(%rsp), %rdi
movl $0x4, %esi
leaq 0x8c(%rsp), %rdx
leaq 0x9c(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq 0xaddf8(%rip), %r9      # 0xcf9ab
callq 0x191f0
movq %rax, 0x78(%rsp)
cmpl $0x0, 0x9c(%rsp)
je 0x21c82
jmp 0x21bcd
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x18300
movq 0xa0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x84(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x80(%rsp), %ecx
movl $0x48, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x9c(%rsp), %edi
callq 0x19a60
movq 0x48(%rsp), %rdi
movq %rax, %rdx
movl $0x4, %esi
callq 0x18460
movl %eax, 0xac(%rsp)
jmp 0x220ad
movq 0xa0(%rsp), %rdi
movl $0x5, %esi
leaq 0x88(%rsp), %rdx
leaq 0x9c(%rsp), %rcx
callq 0x1a4b0
movq %rax, 0x70(%rsp)
cmpl $0x0, 0x9c(%rsp)
jge 0x21d78
jmp 0x21cb9
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x18300
movq 0xa0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x84(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x80(%rsp), %ecx
movl $0x48, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xa0(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x40(%rsp), %rdi
movq %rax, %rdx
movl $0x5, %esi
callq 0x18460
movl %eax, 0xac(%rsp)
jmp 0x220ad
cmpl $0x0, 0x9c(%rsp)
je 0x21d94
movq 0xa0(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
movq 0xa0(%rsp), %rdi
movl $0x6, %esi
leaq 0x84(%rsp), %rdx
leaq 0x9c(%rsp), %rcx
callq 0x18ed0
movq %rax, 0x68(%rsp)
cmpl $0x0, 0x9c(%rsp)
jge 0x21e8a
jmp 0x21dcb
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x18300
movq 0xa0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x84(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x80(%rsp), %ecx
movl $0x48, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x38(%rsp), %rdi
movq %rax, %rdx
movl $0x6, %esi
callq 0x18460
movl %eax, 0xac(%rsp)
jmp 0x220ad
cmpl $0x0, 0x9c(%rsp)
je 0x21ea6
movq 0xa0(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
movq 0xa0(%rsp), %rdi
movl $0x7, %esi
leaq 0x80(%rsp), %rdx
leaq 0x9c(%rsp), %rcx
callq 0x19300
movq %rax, 0x60(%rsp)
cmpl $0x0, 0x9c(%rsp)
jge 0x21f9c
jmp 0x21edd
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x18300
movq 0xa0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x84(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x80(%rsp), %ecx
movl $0x48, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xa0(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x30(%rsp), %rdi
movq %rax, %rdx
movl $0x7, %esi
callq 0x18460
movl %eax, 0xac(%rsp)
jmp 0x220ad
cmpl $0x0, 0x9c(%rsp)
je 0x21fb8
movq 0xa0(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x18170
movq 0x90(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x3d0(%rax), %rax
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
movq 0x78(%rsp), %rdx
movl 0x54(%rsp), %ecx
movl 0x50(%rsp), %r8d
movl 0x88(%rsp), %r9d
movq 0x70(%rsp), %r14
movl 0x84(%rsp), %ebp
movq 0x68(%rsp), %rbx
movl 0x80(%rsp), %r11d
movq 0x60(%rsp), %r10
movq %r14, (%rsp)
movl %ebp, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movq %r10, 0x20(%rsp)
callq *%rax
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x18300
movq 0xa0(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x88(%rsp), %ecx
movl $0x18, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x84(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0xa0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x80(%rsp), %ecx
movl $0x48, %edx
movl $0x1, %r8d
callq 0x198d0
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq