// File: stetre[P]moonvulkan/src/cmd.c
// Function: CmdCopyImageToBuffer
static int CmdCopyImageToBuffer(lua_State *L)
    {
    int err;
    uint32_t count;
    ud_t *ud;
    VkCommandBuffer cb = checkcommand_buffer(L, 1, &ud);
    if(ud->ddt->CmdCopyImageToBuffer2KHR && lua_type(L, 2)==LUA_TTABLE)
        {
        VkCopyImageToBufferInfo2KHR *info = zcheckVkCopyImageToBufferInfo2KHR(L, 2, &err);
#define CLEANUP zfreeVkCopyImageToBufferInfo2KHR(L, info, 1)
        if(err) { CLEANUP; return argerror(L, 2); }
        ud->ddt->CmdCopyImageToBuffer2KHR(cb, info);
        CLEANUP;
#undef CLEANUP
        }
    else
        {
        VkImage srcImage = checkimage(L, 2, NULL);
        VkImageLayout srcImageLayout = checkimagelayout(L, 3);
        VkBuffer dstBuffer = checkbuffer(L, 4, NULL);
#define CLEANUP zfreearrayVkBufferImageCopy(L, regions, count, 1)
        VkBufferImageCopy* regions = zcheckarrayVkBufferImageCopy(L, 5, &count, &err);
        if(err) { CLEANUP; return argerror(L, 5); }
        ud->ddt->CmdCopyImageToBuffer(cb, srcImage, srcImageLayout, dstBuffer, count, regions);
        CLEANUP;
#undef CLEANUP
        }
    return 0;
    }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
leaq 0x48(%rsp), %rdx
leaq 0xb27fa(%rip), %rcx     # 0xcf909
callq 0x1a640
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x6b8(%rax)
je 0x1d1e9
movq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x1d1e9
movq 0x58(%rsp), %rdi
movl $0x2, %esi
leaq 0x54(%rsp), %rdx
callq 0x18130
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x1d1b4
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%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, 0x64(%rsp)
jmp 0x1d316
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x6b8(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq *%rax
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
jmp 0x1d30e
movq 0x58(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb279c(%rip), %rcx     # 0xcf99a
callq 0x1a640
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
movl $0xa, %esi
movl $0x3, %edx
callq 0x19d20
movl %eax, 0x2c(%rsp)
movq 0x58(%rsp), %rdi
movl $0x4, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb1dcb(%rip), %rcx     # 0xcf000
callq 0x1a640
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movl $0x5, %esi
leaq 0x50(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x19160
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x1d2bc
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x5, %esi
callq 0x18460
movl %eax, 0x64(%rsp)
jmp 0x1d316
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x388(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq 0x20(%rsp), %rcx
movl 0x50(%rsp), %r8d
movq 0x18(%rsp), %r9
callq *%rax
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nop